?? db.java
字號:
package connect;import java.sql.*;import java.util.logging.Level;import java.util.logging.Logger;public class DB { private PreparedStatement pstmt; public Connection getConn() throws IllegalAccessException, InstantiationException { Connection conn = null; try { try { Class.forName(DBConst.CLASSNAME).newInstance(); } catch (ClassNotFoundException ex) { Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex); } conn = DriverManager.getConnection(DBConst.URL, DBConst.NAME, DBConst.PWD); } catch (SQLException e) { e.printStackTrace(); } return conn; } public void add(String addSQL) { try { pstmt = getConn().prepareStatement(addSQL); System.out.println(pstmt); } catch (Exception ex) { System.out.println(ex); } } public Statement getStatement(Connection conn) { Statement stmt = null; try { if (conn != null) { stmt = conn.createStatement(); } } catch (SQLException e) { e.printStackTrace(); } return stmt; } public PreparedStatement getPstmt() { return pstmt; } public void setPstmt(PreparedStatement pstmt) { this.pstmt = pstmt; } public ResultSet getResultSet(Statement stmt, String sql) { ResultSet rs = null; try { if (stmt != null) { rs = stmt.executeQuery(sql); } } catch (SQLException e) { e.printStackTrace(); } return rs; } public void closeConn(Connection conn) { try { if (conn != null) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } public void closeStmt(Statement stmt) { try { if (stmt != null) { stmt.close(); stmt = null; } } catch (SQLException e) { e.printStackTrace(); } }public void closePreStmt(PreparedStatement pstmt) { try { if (pstmt != null) { pstmt.close(); pstmt = null; } } catch (SQLException e) { e.printStackTrace(); } } public void closeRs(ResultSet rs) { try { if (rs != null) { rs.close(); rs = null; } } catch (SQLException e) { e.printStackTrace(); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -