Oracle inserts timestamp data, and oracle inserts timestamp
Table Structure:
create table TEST( ID INTEGER, BIRTHDAY TIMESTAMP);
Insert a date to a TIMESTAMP field using JDBC
Import java. SQL. connection; import java. SQL. driverManager; import java. SQL. preparedStatement; import java. SQL. SQLException; import java. text. simpleDateFormat; import java. util. date; public class Test {static {try {Class. forName ("oracle. jdbc. driver. oracleDriver ");} catch (ClassNotFoundException e) {e. printStackTrace () ;}}/*** get Connection ** @ return */public static Connection getConnection () {Connection conn = null; try {conn = DriverManager. getConnection ("jdbc: oracle: thin: @ localhost: 1521/orcl", "root", "root");} catch (SQLException e) {e. printStackTrace ();} return conn;} public static void main (String [] args) throws SQLException {// TODO Auto-generated method stubPreparedStatement pst = null; connection conn = getConnection (); SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); String myDate = df. format (new Date (); // The current time String SQL = "insert into test (id, birthday) values ('1', to_timestamp ('" + myDate + "', 'yyyy-mm-dd hh24: mi: ss') "; pst = conn.preparestatement(sql1_1_pst.exe cuteUpdate (); // omitted IO stream close }}
Use to_timestamp to convert struct type to timestamp
Author: itmyhome
Source: http://blog.csdn.net/itmyhome1990/article/details/41776721