JDBC Learning notes (1)

Source: Internet
Author: User

Jdbc:java database Connector Java connected databases Technology

First, the development of JDBC
1, Java-to-ODBC-to-DB (bicyclic)
2, Java--Local client Tools--DB (local Clientapi)
3, Java--DB (direct Connect)
4, Java--WebServer---DB (Connection pool)

Second, the JDBC Direct Connect drive contains content
1, interface, provided by Sun company, in the JDK java.sql and javax.sql package.
2, the driver class, the database vendor provides, to the database manufacturer homepage Downloads Ojdbc5.jar Odbc6.jar
1) DOS Compile run: Modify environment variable Classpath value is.;D: \ Javaweb\jdbc\ Data \ojdbc5.jar
2) IDE compile run: Right-click project name-->build path-->configure Build path--> right-click libraies
-->add External jars--> Select Ojdbc5.jar file-->ok on the hard drive.

Third, the steps of JDBC "Focus"

I. For insert, delete, update (that is, five steps to complete without query results)

1. Registered Driver class

Class.forName ("Oracle.jdbc.driver.OracleDriver");

2. Create a connection

String url= "Jdbc:oracle:thin: @localhost: 1521:xe";
Connection conn = drivermanager.getconnection (URL, "hr", "HR");

3. Create statement

Statement stm = Conn.createstatement ();

4. Execute SQL statements

String sql = "Insert ..."; int row = stm.executeupdate (SQL);

5. Release resources (first created after close)///First created after release

if (STM! = null) {stm.close ();    } if (conn! = null) {conn.close (); }


II. For select (that is, the operation with query results, six steps)

1. Registered Driver class

Class.forName ("Oracle.jdbc.driver.OracleDriver");

2. Create a connection

String url= "Jdbc:oracle:thin: @localhost: 1521:xe";
Connection conn = drivermanager.getconnection (URL, "hr", "HR");

3. Create statement

Statement stm = Conn.createstatement ();

4. Execute SQL statements

sql = "Select ..."; ResultSet rs = stm.executequery (SQL);

5. Processing Query Results

while (Rs.next ()) {//get field Xxx x = rs.getxxx ("field name"); Xxx x = rs.getxxx (columnindex); }

5. Release resources (first created after close)///First created after release

if (rs! = null) {rs.close ();  } if (STM! = null) {stm.close ();    } if (conn! = null) {conn.close (); }


JDBC Learning notes (1)

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.