Example #1
0
 public boolean update(String sql) {
   Connection conn = null;
   Statement st = null;
   boolean rs = true;
   try {
     conn = ConnectionDateBase.getConnection();
     st = conn.createStatement();
     st.executeUpdate(sql);
   } catch (SQLException e) {
     rs = false;
     e.printStackTrace();
   } finally {
     try {
       st.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
     try {
       conn.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return rs;
 }
Example #2
0
 /**
  * 查询数据库,返回结果集
  *
  * @param sql 要执行的查询语句
  * @return
  */
 public ResultSet select(String sql) {
   Connection conn = null;
   Statement st = null;
   ResultSet rs = null;
   try {
     conn = ConnectionDateBase.getConnection();
     st = conn.createStatement();
     rs = st.executeQuery(sql);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   //		finally {
   //			try {
   //				st.close();
   //			} catch (SQLException e) {
   //				e.printStackTrace();
   //			}
   //			try {
   //				conn.close();
   //			} catch (SQLException e) {
   //				e.printStackTrace();
   //			}
   //		}
   return rs;
 }