Table structure:
CREATE TABLE TEST ( ID INTEGER, BIRTHDAY TIMESTAMP);
inserting dates into the timestamp type 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 = Drivermanag Er.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 ()); Current time String sql = "INSERT INTO Test (Id,birthday) VALUES (' 1 ', To_timestamp ('" + mydate + "', ' yyyy-mm-dd hh24:mi:ss ')";p St = conn.preparestatement (sql);p St.executeupdatE ();//Omit IO stream Close}}
use To_timestamp to turn character types into timestamp
Itmyhome
Source: http://blog.csdn.net/itmyhome1990/article/details/41776721
Oracle inserts timestamp type data