public int executeUpdate(String sql) throws SQLException{ if (con == null con.isClosed()) makeConnection(); Statement stmt = con.createStatement(); //這個stmt在執行更新操作時更加節省內存,永遠記住,能節省的時候要節省每一個字節的內存,雖然硬件設備可能會有很大的物理內存,但內存是給用戶用的而不是給程序員用的(!!!!!!!!!!!!!!!!!!) int s = stmt.executeUpdate(sql); return s; }
//以上實現了常用功能,還有兩個通用的功能也是/"共性/"的,我們一起在這個封裝類中實現: public PreparedStatement getPreparedStmt(String sql) throws SQLException{ if (con == null con.isClosed()) makeConnection(); PreparedStatement ps = con.prepareStatement(sql); return ps; } public CallableStatement getCallableStmt(String sql) throws SQLException{ if (con == null con.isClosed()) makeConnection(); PreparedStatement ps = con.prepareCall(sql); return ps; }
public class OracleDBOperater extends DBOperater{ public OracleXMLQuery getOXQuery(String sql,String table) throws Exception { OracleXMLQuery qry = new OracleXMLQuery(con,sql); qry.setRowsetTag(table); qry.setRowTag(/"RECORD/"); return qry; } public int insertXML(String path,String table) throws Exception { OracleXMLSave sav = new OracleXMLSave(con,table); URL url = sav.createURL(path); sav.setRowTag(/"RECORD/"); int x = sav.insertXML(url); sav.close(); return x; } }