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)