This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Syntax error converting datetime from character string. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Syntax error converting datetime from character string." Watch "Syntax error converting datetime from character string." New topic
Author

Syntax error converting datetime from character string.

S bitz
Ranch Hand

Joined: Jan 20, 2006
Posts: 80
Hi,
I am trying to insert some values in a database.I'm using prepared statements and this is my query


startDate and returnDate are of the format "YYYYMMDD"

This throws this error : Syntax error converting datetime from character string.

but when i change the query to

pstmt.setString(4,"20060905") this works fine.

I'm using SQL Server 2000.
Can anyone tell me how this can be fixed?

Thanks
Bitz
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

  • Convert Your String date to java.util.Date or Java.sql.Date
  • Set them as date in preparedStaement, NOT as String






  • Shailesh


    Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
     
     
    subject: Syntax error converting datetime from character string.
     
    Similar Threads
    DataTime conversion
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    msyql jdbc problem.
    howto modify database structure ?
    Convert DateTime Error