当前位置: 代码迷 >> Java Web开发 >> sqlserver2000 关闭连接出现的问题
  详细解决方案

sqlserver2000 关闭连接出现的问题

热度:569   发布时间:2010-11-03 21:55:30.0
sqlserver2000 关闭连接出现的问题
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


import db.DBconn;

import entity.User_info;

public class LoginDao {
    Connection conn;
   
    public User_info checkLogin(String name,String password){
        conn=DBconn.getconn();
        try {
            PreparedStatement pstmt=conn.prepareStatement("select * from login where name=? and password=?");
            pstmt.setString(1, name);
            pstmt.setString(2, password);
            ResultSet rs=pstmt.executeQuery();
            if(rs.next()){
                User_info user=new User_info();
                user.setName(rs.getString(1));
                user.setPassword(rs.getString(2));
               
                return user;
            }
            
            else    return null;
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }finally {
                       //这里加上关闭数据库的方法不能运行 也不报错  去掉后能运行
                      }
        
    }

}

----------------解决方案--------------------------------------------------------
  相关解决方案