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 {
//这里加上关闭数据库的方法不能运行 也不报错 去掉后能运行
}
}
}