首页>代码>jquery ajax分页插件特效源代码demo完整版>/JqueryAjaxPage/src/com/jiang/DB/DBop.java
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日
最近浏览更多
小白小怪  LV10 2022年9月18日
 LV6 2022年6月30日
mylzdy  LV12 2021年8月31日
qq70081337  LV6 2021年8月26日
Altria  LV5 2021年8月13日
liqi666  LV7 2021年7月23日
 LV1 2021年6月26日
123821218  LV2 2021年3月10日
test123123  LV6 2021年3月10日
seagullliwei  LV1 2021年2月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友