Oracle inserts timestamp data, and oracle inserts timestamp

Source: Internet
Author: User

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





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.