Discussion Locked

howtoinsertdateintosybasefromjavaprog

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i'm accepting date values as strings.i want to
convert the string to date and insert into sybase
table.i accept the string in mm-dd-yy format which
is acceptable by sybase.

1 reply

by geert pante

The most portable answer is to use a preparedStatement and bind a java.sql.Date to it instead of just pasting the date as a string into the insert statement.

SimpleDateFormat df=new SimpleDateFormat("MM-dd-yy");
java.util.Date utilDate=df.parse(inputString);
java.sql.Date sqlDate=new java.sql.Date(utilDate.getTime());
PreparedStatement stmt=conn.prepareStatement("insert into table (date) values (?)");
stmt.setDate(1, sqlDate);
stmt.executeUpdate();

This discussion is closed to new replies.