Jave Basics: JDBC Tips

zhaozj2021-02-16  61

Database operation is performed using JDBC, which is divided into the following steps: 1. Load drive format: Class.Forname () E.g.class.Forname ("Weblogic.jdbc.MssqlserVer4.driver")

2. Dissipate the data source. CONNECTION con = 0.GETCONNECTION (, ) Con = DriverManager.getConnection (, , )

3. Execute statement stmt = con.creatStatement (); ---- Execute Storage Procedure: Stmt.execute () ---- Execute multiple statements in batches: stmt.executebatch () --- - Update processing: int updateCount = stmt.executeUpdate () ---- Query ResultSet RS = Stmt.executeQuery ()

Commonly used: while (rs.next ()) {} utilization. PrepairedStatement Advantages: No need to be generated, as long as the parameters are modified, EG prepairedState pstmt1 pstmt1 = con.prepairedStatement ("SELECT * from TableName WHERE A =? And b =? ") pstmt1.setstring (Text1.getText, Text2.getText) ResultSet RS = PSTMT1.EXECUTEQUERY ();

Using ResultSetMetadata to get the number of fields in the data table, type, etc., you can use the result of getMetadata (), and the return result is saved with the ResultSetMetadata object. EG RESULTSET RS = Stmt.getResultSet () ResultSetMetadata RSMD = rs.getMetadata (); // Field Number, INT ColuMecount = rsmd.getColumnCount () for (i = 1; i <= columncount; i ) {system.out.println (RSMD.GetClumnname ())

}

// The above is for reference only,

转载请注明原文地址:https://www.9cbs.com/read-19517.html

New Post(0)