• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem in getting date from JSP Form

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am implenting a project on Library Management System(Web application).
I have a form as New User Registration Form in which user enters his/her information.There is one field as DateOfBirth which takes input as string(i.e date of birth of the user).Now I am extracting this inputs in Servlet.
My aim is to insert these inputs in a user table.I am using SQL Server 2000.
I am using Prepared Statement for Insert query.I convert the date of birth which is in string to java.sql.Date object using the following code:-

java.util.Date d=null;
java.sql.Date dateofbirth=null;

try {
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
dateofbirth = new java.sql.Date(formatter.parse(dob).getTime());

} catch(Exception e) {
e.printStackTrace();}

Now the problem arises when i am doing this:-

query="Insert into USERDETAILS values(?,?,?,?,?,?,?,?,?,?,?)";

pstmt=con.prepareStatement(query);
pstmt.setString(1, userid);
pstmt.setString(2, name);
******* pstmt.setDate(3, dateofbirth);
pstmt.setString(4, gender);
pstmt.setString(5, address);
pstmt.setString(6, city);
pstmt.setString(7, state);
pstmt.setString(8, country);
pstmt.setString(9, phone);
pstmt.setString(10, email);
pstmt.setString(11, occupation);
i=pstmt.executeUpdate();

I am getting error in "pstmt.setDate(3, dateofbirth);".
It gives error like "java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented"

This is the error i m getting.Please help me in this matter.I will be very thankful to you.

Regards,
Mohsin
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JDBC/ODBC driver does not provide a complete set of JDBC 2.0 features so this example must result in a call that is not supported in the driver. You could try using the Microsoft JDBC driver or the JDTS driver. They should provide better performance as well.

cheers
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a suggestion -
Try it out with DATETIME in SQL Server and java.sql.Timestamp in Java once.
 
mohsin sheikh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thankyou for your replies.Now the problem is solved.Now i am using different Driver i.e sql driver(Type4).Now again some problems comes out.When the user enter Date in String form ,i convert that date in java.sql.date using the following function:

private java.sql.Date dateConverter(String date) {

java.sql.Date sqlDate=null;
try
{
SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy");
sqlDate = new java.sql.Date(formatter.parse(date).getTime());
return sqlDate;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}

The problem now is that when the user enters some date,then that date gets changed e.g
when the user enters 25/07/1983.it gets stored in database as 1/25/1983.
Please help me on this matter.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mohsin,
25/07/1983 is not in the format mm/dd/yyyy. In particular, 25 is not a valid month. Java is guessing at what you mean.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic