package com.jiang.DB; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.sun.rowset.CachedRowSetImpl; import javax.sql.RowSet; import javax.sql.rowset.CachedRowSet; import java.sql.ResultSet; public class DBop { public static boolean save(String sql){ DB db=new DB(); Connection conn=db.getConnection(); PreparedStatement pstm=null; try { pstm=conn.prepareStatement(sql); return pstm.execute(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } public static RowSet search(String sql){ DB db=new DB(); Connection conn=db.getConnection(); PreparedStatement pstm=null; try{ pstm=conn.prepareStatement(sql); ResultSet rs=pstm.executeQuery(); CachedRowSet crs=new CachedRowSetImpl(); crs.populate(rs); return crs; }catch(Exception e){ e.printStackTrace(); return null; }finally{ if(pstm!=null){ try { pstm.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(conn!=null){ try { conn.close(); } catch (SQLException e) { System.out.println("关闭数据库链接时出现问题....."); e.printStackTrace(); } } } } } public static int getNum(String tableName,String where){ StringBuilder sb=new StringBuilder(); sb.append("select count(*) as num from "+tableName); if(!"".equals(where)){ sb.append(" "); if(where.startsWith("where")){ sb.append(" "+where); }else{ sb.append(" where "+where); } } DB db=new DB(); Connection conn=db.getConnection(); PreparedStatement pstm=null; try{ pstm=conn.prepareStatement(sb.toString()); ResultSet rs=pstm.executeQuery(); if(rs.next()){ return rs.getInt("num"); }else{ return 0; } }catch(Exception e){ e.printStackTrace(); return 0; }finally{ if(pstm!=null){ try { pstm.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(conn!=null){ try { conn.close(); } catch (SQLException e) { System.out.println("关闭数据库链接时出现问题....."); e.printStackTrace(); } } } } } }

余 LV1
2021年6月26日
seagullliwei LV1
2021年2月18日
lclinlclin LV14
2021年1月25日
129448 LV1
2020年5月25日
adminxu LV13
2020年5月3日
18035189975 LV1
2020年3月18日
zhourunfav LV1
2019年12月12日
ss1522886278 LV2
2019年12月11日
guysma LV1
2019年11月15日
messiaaaaa LV1
2019年10月18日