关于返回 RusultSet问题
返回ResultSet 的话 跟数据库连接不能关闭
public ResultSet executeQuery(String UserName) throws Exception//接收SQL查询语句
{
Connection conn=null;
ResultSet rs=null;
Statement stmt = null;
try
{
conn= DriverManager.getConnection(url, "sa ", " ");
stmt=conn.createStatement();
if(UserName!=null&&!UserName.equals( " "))
{
rs= stmt.executeQuery( "select* from [User] where UserName= ' "+UserName+ " ' ");
}
else
{
rs= stmt.executeQuery( "select* from [User] ");
}
}
catch(
SQLException ex)
{
System.out.println( "更新数据操作失败! "+ex.getMessage());
}
return rs;
}
我是这么写的要怎么改 返回什么数据库才能关闭
------解决方案--------------------返回List吧。你这样返回是不可以关闭的、