Am trying to read a date that i have stored in a database table and then parse it to a date object of the Date class using a servlet, but it returns null for the converted date.Where am i going wrong?Some advice on how to sort that out would be helpful. The servlet code is below:
Connection con;
Statement st;
ResultSet rs;
Date d3 = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:lab","admin","");
st = con.createStatement();
String Qry = ("SELECT * FROM Rodents;");
rs = st.executeQuery(Qry);
while(rs.next())
{
String ResID = rs.getString(1);
String ProdID = rs.getString(2);
String PName = rs.getString(3);
String Price = rs.getString(4);
//***********************************************
//Chaning the date from String to an object of Date
//***********************************************
String ds = rs.getString(5);
DateFormat df = DateFormat.getDateInstance();
try
{
d3 = df.parse(ds);
}
catch(ParseException e)
{
System.out.println("Unable to parse");
}
//**********************************************
//Printing out the data in the table
//**********************************************
out.print(ResID+" ");
out.print(ProdID+" ");
out.print(PName+" ");
out.print(Price+" ");
out.print(ds);
}
rs.close();
st.close();
con.close();
}
catch(Exception e)
{
System.out.print("Unable to find DB");
}
finally {
out.close();
}
}