Jave based learning: jdbc tips

  Jave based learning: jdbc tips jdbc use database operations, are divided into the following steps: 
  1. Loading 
  ?? Format: Class.forName (<JDBC? Driver Class Name>) 
  ?? EGClass.forName ( "Weblogic.jdbc.mssqlserver4.Driver") 

  2. Connected data source. 
  ? Connection con 
  ? One of the following optional 
  ? Con = DriverManager.getConnection (<url>) 
  ? Con = DriverManager.getConnection (<url>, <proporties>) 
  ? Con = DriverManager.getConnection (<url>, <user>, <password>) 

  3. Implementation 
  ? Statement stmt = con.creatStatement (); 
  ? Executive storage process: stmt.execute (<String sql>) 
  ? - To run multiple batch mode statement: stmt.executeBatch () 
  ? - Updating:? Int updateCount = stmt.executeUpdate (<String? sql>) 
  ? - For ???????????? ResultSet rs = stmt.executeQuery (<String sql>) 

  ??????? Commonly used is: while (rs.next ()) 
  ????????????????????????????????????? () 
  Use. PrepairedStatement 
  ? Advantages: not in the re-formation, as long as the parameters can be modified, 
  ? Eg? PrepairedStatement pstmt1 
  ? Pstmt1 = con.PrepairedStatement ( "select * from tableName where? A =? And b =?") 
  ? Pstmt1.setString (text1.getText, text2.getText) 
  ? ResultSet? Rs = pstmt1.executeQuery (); 

  Use ResultSetMetaData 
  ?? To obtain field data in the table number, type, and so on, can use the Result of the getMetaData (), the results are returned to the preservation ResultSetMetaData object. 
  ?? Eg 
  ?? ResultSet rs = stmt.getResultSet () 
  ?? ResultSetMetaData rsmd = rs.getMetaData (); 
  ?? / / Number of fields, 
  ?? Int columeCount = rsmd.getColumnCount () 
  ???????? For (i = 1; i <= columnCount; i + +) 
  ?????????? ( 
  ?????????????? System.out.println (rsmd.getClumnName ()) 

  ?????????????) 

  Posted on 2006-05-23 23:05 javaPlayer reading (234) Comments (0) edit collections cited 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply