jdbc programming

jdbc programming

1 transation
 performance it is not easy to say , turn off auto-commiting it will cut down on the number of commits.decreasse the comunication between  client and the dbserver and but the db need to hold the locks on multiple statements.
 turn on the auto-commits , in case where there may be conflicts with other users, turn on auto-commiting will improve the preformance because no lock need to hode, but it will caused conflicts.
transaction isolation :control the dirty data, saving points is a point in a transation.

SQLWarning warning = stmt.getWarnings(); if (warning != null) { System.out.println("/n---Warning---/n"); while (warning != null) { System.out.println("Message: " + warning.getMessage()); System.out.println("SQLState: " + warning.getSQLState()); System.out.print("Vendor error code: "); System.out.println(warning.getErrorCode()); System.out.println(""); warning = warning.getNextWarning(); } }

2, rows order in result set dose nothing with the db

3, insert row, every rs has it.

4, commit is means using the sql statement ,and insertRow or updateRow is means using the jdbc api.

5, addBatch(sqlstring) executeBatch() return a int array(), its execution order is fixed, support parameterized batch


 

1, SQL types:

sql date ,time and timestamp , but java only have the date, it can repsents all the sql date types.

data returned from result set mostly is sql types.

jdbc 3.0 types , blob , clob, array, struct , ref.
udt is corresponding to struct, ref is ref.

 the program example :

while (rs.next()) { int storeNo = rs.getInt("STORE_NO"); Struct location = (Struct)rs.getObject("LOCATION"); Object[] locAttrs = location.getAttributes(); Array coffeeTypes = rs.getArray("COF_TYPE"); String[] cofTypes = (String[])coffeeTypes.getArray(); Ref managerRef = rs.getRef("MGR"); PreparedStatement pstmt = con.prepareStatement( "SELECT MANAGER FROM MANAGERS WHERE OID = ?"); pstmt.setRef(1, managerRef); ResultSet rs2 = pstmt.executeQuery(); rs2.next(); Struct manager = (Struct)rs2.getObject("MANAGER"); Object[] manAttrs = manager.getAttributes(); System.out.print(storeNo + " "); System.out.print(locAttrs[0] + " " + locAttrs[1] + " " + locAttrs[2] + ", " + locAttrs[3] + " " + locAttrs[4] + " "); for (int i = 0; i < cofTypes.length; i++) System.out.print(cofTypes[i] + " "); System.out.println(manAttrs[1] + ", " + manAttrs[2]); rs2.close(); pstmt.close(); } rs.close(); stmt.close(); con.close(); } catch(BatchUpdateException b) { System.err.println("-----BatchUpdateException-----"); System.err.println("SQLState: " + b.getSQLState()); System.err.println("Message: " + b.getMessage()); System.err.println("Vendor: " + b.getErrorCode()); System.err.print("Update counts: "); int [] updateCounts = b.getUpdateCounts(); for (int i = 0; i < updateCounts.length; i++) { System.err.print(updateCounts[i] + " "); } System.err.println(""); } catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); System.err.println("SQLState: " + ex.getSQLState()); System.err.println("Message: " + ex.getMessage()); System.err.println("Vendor: " + ex.getErrorCode()); }


 2, oracle jdbc driver, after u set up the connecting with oracle server, conn.getCatalog() will return null, and also u can't set the catalog, so u only can see the things which only belong to this user.like the tables, viewes, procedures.this dose make sense.


 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值