howtoinsertdateintosybasefromjavaprog
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.
Web Development
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.
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.
Sort by Trending