Oracle inserts timestamp data
Oracle 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 ();
}
}
/**
* Obtain the 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 stub
PreparedStatement pst = null;
Connection conn = getConnection ();
SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
String myDate = df. format (new Date (); // current time
String SQL = "insert into test (id, birthday) values ('1', to_timestamp ('" + myDate + "', 'yyyy-mm-dd hh24: mi: ss '))";
Pst = conn. prepareStatement (SQL );
Pst.exe cuteUpdate ();
// Omitted IO stream close
}
}
Use to_timestamp to convert struct type to timestamp
Install Oracle 11gR2 (x64) in CentOS 6.4)
Steps for installing Oracle 11gR2 in vmwarevm
Install Oracle 11g XE R2 In Debian
Install Oracle 11.2.0.4 x64 in Oracle Linux 6.5