public boolean query(String sql) { try { Statement stmt = getStatement(); if (stmt != null) stmt.close(); ResultSet rs = getResultSet(); if (rs != null) rs.close(); Connection con = getConnection(); if (con == null) return false; stmt = con.createStatement(); setStatement(stmt); rs = stmt.executeQuery(sql); setResultSet(rs); } catch (Exception e) { Debug.warning(e); return false; } return true; }
public boolean fetch() { boolean fetchRet = false; try { ResultSet rs = getResultSet(); if (rs == null) return false; fetchRet = rs.next(); if (!fetchRet) { Statement stmt = getStatement(); if (stmt != null) { stmt.close(); setStatement(null); } rs.close(); setResultSet(null); } } catch (Exception e) { Debug.warning(e); } return fetchRet; }
public int update(String sql) { int numOfUpdated = 0; try { Statement stmt = getStatement(); if (stmt != null) { stmt.close(); setStatement(null); } ResultSet rs = getResultSet(); if (rs != null) { rs.close(); setResultSet(null); } Connection con = getConnection(); if (con == null) return 0; stmt = con.createStatement(); numOfUpdated = stmt.executeUpdate(sql); stmt.close(); } catch (Exception e) { Debug.warning(e); } return numOfUpdated; }