zoukankan      html  css  js  c++  java
  • 银行营业网点管理系统——dao包(BaseDao)

    package BranchesMgr.dao;
    /**
     * 数据库操作类
     * @author Administrator
     *
     */
    import java.sql.*;
    import java.util.List;
    public class BaseDao {
    	Connection conn=null;
    	PreparedStatement ps=null;
    	ResultSet rs=null;
    	public void getConnection(){
    		try {
    			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		if(conn==null){
    			try {
    				conn=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databasename=CityDB;User=sa;Password=171268");
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	//增删改
    	public int excuteUpdate(String sql,List<Object> prams) throws SQLException{
    		int rel=0;
    		getConnection();
    		ps=conn.prepareStatement(sql);
    		if(prams!=null){
    			for (int i = 0; i < prams.size(); i++) {
    				ps.setObject(i+1, prams.get(i));
    			}
    		}
    		 rel=ps.executeUpdate();
    		return rel;
    	}
    	
    	//查询
    	public ResultSet excuteQurey(String sql,List<Object>prams) throws SQLException{
    		getConnection();
    		ps=conn.prepareStatement(sql);
    		if(prams!=null){
    			for (int i = 0; i < prams.size(); i++) {
    				ps.setObject(i+1, prams.get(i));
    			}
    		}
    		rs=ps.executeQuery();
    		return rs;
    	}
    
    	//关闭资源
    	public void closeAll(){
    		if(rs!=null){
    			try {
    				rs.close();
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		if(ps!=null){
    			try {
    				ps.close();
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		if(conn!=null){
    			try {
    				conn.close();
    				conn=null;
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    	}
    }
    

  • 相关阅读:
    Sprinig.net 双向绑定 Bidirectional data binding and data model management 和 UpdatePanel
    Memcached是什么
    Spring.net 网络示例 codeproject
    jquery.modalbox.show 插件
    UVA 639 Don't Get Rooked
    UVA 539 The Settlers of Catan
    UVA 301 Transportation
    UVA 331 Mapping the Swaps
    UVA 216 Getting in Line
    UVA 10344 23 out of 5
  • 原文地址:https://www.cnblogs.com/a1111/p/6540282.html
Copyright © 2011-2022 走看看