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>

[10275 byte] By [venkateshpa] at [2007-10-2 16:26:44]
# 1
document.forms[0].year.value;That's not right, year is a select box. It should be this:document.forms[0].year.options[document.forms[0].year.selectedIndex].value;
gimbal2a at 2007-7-13 17:26:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
But am not able to insert the date into the database.
venkateshpa at 2007-7-13 17:26:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Add a print statement here:

String query = "insert into Holiday(HolidayDate, Description) VALUES (?, ?)";

out.println(date);

PREPstmt1=con.prepareStatement(query);

PREPstmt1.setString(1,date);

Have a look at the output and check whether the value is in the correct format for your database.

angrycata at 2007-7-13 17:26:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...