Wu Yuxiong - natural born JAVA Database Programming: ORACLE database using JDBC connection

DROP TABLE person ;
DROP SEQUENCE myseq ;
CREATE SEQUENCE myseq ;
CREATE TABLE person
(
    id        INT        PRIMARY KEY NOT NULL ,
    name        VARCHAR(50)    NOT NULL ,
    age        INT ,
    birthday     DATE
) ;
Import the java.sql.Connection;
 Import the java.sql.DriverManager;
 Import java.sql.SQLException;
 Import java.sql.PreparedStatement;
 public  class JDBCOracle {
     // database driver defines the MySQL 
    public  static  Final String dbDriver = "the oracle.jdbc .driver.OracleDriver " ;
     // define MySQL database connection address 
    public  static  Final String dburl =" jdbc: the Oracle: Thin: @localhost: 1521: MLDN " ;
     // connect MySQL database user name 
    public  static  Final String = DBUSER" scott " ;
     //MySQL database connection password 
    public  static  Final String = DBPASS in "Tiger" ;
     public  static  void main (String args []) throws Exception {     // all exceptions thrown 
        Connection Conn = null ;         // database connection 
        Class.forName (DBDRIVER);     // load the driver 
        conn = DriverManager.getConnection (dburl, DBUSER, DBPASS); 
        PreparedStatement pstmt = null ; 
        String SQL = "INSERT INTO the Person (the above mentioned id, name, Age, Birthday) VALUES (myseq.nextVal,,,??? ) " ; 
        pstmt= Conn.prepareStatement (SQL); 
        pstmt.setString ( . 1, "Li Xinghua" ); 
        pstmt.setInt ( 2,30 ); 
        pstmt.setDate ( . 3, new new a java.sql.Date ( new new java.util.Date (). the getTime ())); 
        pstmt.executeUpdate ();     // update operation 
        pstmt.close (); 
        conn.Close ();             // close the database 
    } 
};

 

Guess you like

Origin www.cnblogs.com/tszr/p/12158926.html