JDBC Inserts date type data into Oracle

Source: Internet
Author: User

Import the database jar package with the following path:

E:\oracle\product\10.1.0\Db_3\jdbc\lib\ojdbc14.jar

The table statement is as follows:

CREATE TABLE T_user (

ID int PRIMARY KEY,

Username varchar (40),

Password varchar (16),

Phone varchar (40),

Address varchar (255),

CreateDate Date

)

The JDBC code is as follows:

Public void Save () {

Connection con=db. getconnection ();

String sql= "INSERT into T_user (username,password,phone,address,createdate) VALUES (?,?,?,?,?)";

PreparedStatement ps=db. getpreparedstatement (Con,sql); Note: If you want to insert date type data into Oracle, you must use the PreparedStatement object

Try {

Ps.setstring (1,username);

Ps.setstring (2,password);

Ps.setstring (3,phone);

Ps.setstring (4,address);

Ps.settimestamp (5,new Timestamp (Createdate.gettime ()));

Ps.executeupdate ();

} catch (SQLException e) {

E.printstacktrace ();

}finally{

Db. closepreparedstatement (PS);

Db. CloseConnection (con);

}

   }

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.