mysql - A datetime equivalent in java.sql ? (is there a java.sql.datetime ?) -
so far, have not found clear answer this.
i'd know equivalent sql type datetime , java type, using preparedstatement.
i have found: http://www.java2s.com/code/java/database-sql-jdbc/standardsqldatatypeswiththeirjavaequivalents.htm
but states sql type "datetime" same sql.date, when looking @ sql date docs (http://download.oracle.com/javase/7/docs/api/java/sql/date.html), says time truncated (all zeros).
what want able specify preparedstatement.setdatetime()
or sort.
the other way see using timestamp, require me change column type, while cannot imagine else never had problem before?
any hints?
edit: using mysql.
the java.sql package has 3 date/time types:
java.sql.date
- date (no time part)java.sql.time
- time (no date part)java.sql.timestamp
- both date , time
you want last one: java.sql.timestamp
.
if using these types, don't need call specific setter; use:
java.util.date date = new date(); object param = new java.sql.timestamp(date.gettime()); // jdbc driver knows java.sql type: preparedstatement.setobject(param);
Comments
Post a Comment