Oracle inserts timestamp type data

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.