java - Error while storing jXDatePicker1 Date value in database -


i using swingxlabs' component jxdatepicker1 pick date in graphical format , trying store in database made in derby. code this:

date date=jxdatepicker1.getdate();   preparedstatement statement = connect       .preparestatement("insert billing (date, dhrnumber) values('"+date+"', "+dhrnumber+")"); 

the error getting is:

java.sql.sqldataexception: syntax of string representation of datetime value incorrect. 

am doing right? or there can other way solve this.

thanks

derby's built-in date datatype supports short list of string formats: http://db.apache.org/derby/docs/10.9/ref/rrefsqlj18730.html

since using preparedstatement, best thing prepare statement

insert billing (date, dhrnumber) values(?,?) 

and substitute actual values using setdate() , setint() methods from: http://docs.oracle.com/javase/6/docs/api/java/sql/preparedstatement.html


Comments