JDBC for Oracle database operations.

Source: Internet
Author: User

1, follow Oracle

2, CREATE DATABASE footsteps

DROP TABLE person; DROP SEQUENCE myseq ; //Set the self-increment sequence. CREATE SEQUENCE myseq; The CREATE TABLE person (    ID        INT        PRIMARY KEY is not null,    name        VARCHAR () is not    null,    Age        INT,    birthday     DATE);

3, then configure the driver.

4, execute:

Get program: Dbdriver = "Oracle.jdbc.driver.OracleDriver",

JDBC Address: Dburl = "Jdbc:oracle:thin: @localhost: 1521:sys"

 Packageclass set;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.SQLException;Importjava.sql.PreparedStatement; Public classjdbcoracle{//define a MySQL database driver     Public Static FinalString dbdriver = "Oracle.jdbc.driver.OracleDriver" ; //Define the connection address of the MySQL database     Public Static FinalString Dburl = "Jdbc:oracle:thin: @localhost: 1521:sys" ; //connection user name for MySQL database     Public Static FinalString DBUSER = "Scott" ; //connection password for MySQL database     Public Static FinalString Dbpass = "Tiger" ;  Public Static voidMain (String args[])throwsexception{//all exceptions ThrownConnection conn =NULL;//Database ConnectionClass.forName (Dbdriver);//Load Driverconn =drivermanager.getconnection (Dburl,dbuser,dbpass); PreparedStatement pstmt=NULL ; String SQL= "INSERT into person (id,name,age,birthday) VALUES (Myseq.nextval,?,?,?)";//Manually set the primary Key's self-increment pstmt=conn.preparestatement (SQL); Pstmt.setstring (1, "Xiao Hua") ; Pstmt.setint (2,30) ; Pstmt.setdate (3,NewJava.sql.Date (Newjava.util.Date (). GetTime ()))        ;    Pstmt.executeupdate (); //Perform an update operationPstmt.close ();            Conn.close (); //Database Shutdown    }};

When using Oracle connectivity, Oracle will automatically configure the new JRE environment as soon as it is used, and to make its own JRE work, you must remove these configurations from Oracle,

JDBC for Oracle database operations.

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.