year getting null?
In this code, the year value is getting null.. why is it so? Am not able to insert the date, as the year value is getting null?
where should i change the year value, to get the user selected year?
please help?
<%@ page import="java.util.List"%>
<%@page import="java.sql.*, java.util.*, java.text.*" %>
<%@page import="java.sql.Connection, java.sql.DriverManager,java.sql.ResultSet,java.sql.SQLException" %>
<html>
<head>
<title>Print a month page.</title>
<meta name="version">
<script>
var lastId ="";
var curId ="";
function selectDate(f)
{
if(document.forms[0].lastDateId !=null)
{
lastId = document.forms[0].lastDateId.value;
}
if(lastId != document.forms[0].todayId.value)
{
if(document.getElementById(lastId).title =="")
{
document.getElementById(lastId).style.backgroundColor='white';
}
}
if(f.id != document.forms[0].todayId.value)
{
document.getElementById(f.id).style.backgroundColor='blue';
}
document.forms[0].lastDateId.value=f.id;
curId = f.id;
document.getElementById("descr").style.visibility='visible';
document.forms[0].descText.value = f.title;
}
function setTitle()
{
document.getElementById(curId).title=document.forms[0].descText.value;
if(document.forms[0].descText.value =="" && curId != document.forms[0].todayId.value)
{
document.getElementById(curId).style.backgroundColor='white';
}
else
{
if(document.forms[0].list.value =="" )
{
document.forms[0].list.value = curId+":"+document.getElementById(curId).title;
}
else
{
list = replaceList(document.forms[0].list.value,curId);
list = list+","+curId+":"+document.getElementById(curId).title;
document.forms[0].list.value = list;
}
}
document.getElementById("descr").style.visibility='hidden';
}
function replaceList(list,id)
{
arr = list.split(",");
newlist ="";
for(i in arr)
{
if(arr[i].match(id) ==null)
{
if(newlist =="")
{
newlist = arr[i];
}
else
{
newlist +=","+arr[i]+",";
}
}
}
return newlist
}
function showCalendar()
{
location.href="CalendarPage.jsp?year="+document.forms[0].year.value;
}
</script>
</head>
<body bgcolor="#c6d9e4">
<%
Connection con =null;
response.setContentType("text/html");
try
{
String driverName ="com.mysql.jdbc.Driver";
Class.forName(driverName);
String serverName ="192.168.10.5";
String mydatabase ="Trainees";
String url ="jdbc:mysql://" + serverName +"/" + mydatabase;
String username ="venkat";
String password ="venkat";
con = DriverManager.getConnection(url, username, password);
Statement stmt =null;
ResultSet rset =null;
PreparedStatement PREPstmt1;
stmt = con.createStatement();
String year = request.getParameter("year");
out.println("year value is : "+year);
String date="",descr="";
String list = request.getParameter("list");
if(list !=null)
{
String dateDescrList[] = list.split(",");
for(int i=0;i<dateDescrList.length;i++)
{
String listObj = dateDescrList[i];
if(!listObj.equals("") || !listObj.trim().equals(""))
{
date= year+"-"+listObj.substring(0,listObj.indexOf(":"));
descr = listObj.substring(listObj.indexOf(":")+1);
out.println("date is : "+date);
out.println("description is : "+descr);
}
String query ="insert into Holiday(HolidayDate, Description) VALUES (?, ?)";
PREPstmt1=con.prepareStatement(query);
PREPstmt1.setString(1,date);
PREPstmt1.setString(2,descr);
PREPstmt1.executeUpdate();
}
}
}
catch(Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
finally
{
try
{
if(con !=null)
con.close();
}
catch(SQLException e)
{
}
}
%>
<%
Calendar c = Calendar.getInstance( );
boolean yyok =false;
int yy = 0, mm = 0;
String yyString = String.valueOf(c.get(Calendar.YEAR));//setting calendar with current year
String STyear = request.getParameter("year");//to get selected year
if(STyear !=null)//If an year is selected, then set that year. Else Current Year
{
yyString=STyear;
}
if (yyString !=null && yyString.length() > 0)
{
try
{
yy = Integer.parseInt(yyString);
yyok =true;
}
catch (NumberFormatException e)
{
out.println("Year " + yyString +" invalid");
}
}
if (!yyok)yy = c.get(Calendar.YEAR);
mm = c.get(Calendar.MONTH);
String todayId ="";
%>
<form method=get action="CalendarPage.jsp">
Enter Year : <select name="year">
<%
for(int i=2000;i<=2015;i++)
{
if(i==Integer.parseInt(yyString))
{
%>
<OPTION SELECTED= <%=i%> > <%=i%> </option>
<%
}
else
{
%>
<OPTION VALUE= <%=i%> > <%=i%> </option>
%>
<%
}
}
%>
</select>

