java中访问一个数据库把读取的结果保存为list
3个回答
展开全部
遍历这个list中的每个xx对象for(xx
x:list){
System.out.println(x.getXXX());}
x:list){
System.out.println(x.getXXX());}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/**
*
查找所有的注册用户信息
*
@return
用户列表
*/
public
List
selectAllUser(){
List
list=new
ArrayList();
String
sql
=
"select
*
from
users
";
try
{
conn
=
this.getConn();
pstmt
=
conn.prepareStatement(sql);
rs
=
pstmt.executeQuery();
while(rs.next())
{
Users
user
=
new
Users();
user.setUserID(rs.getInt("userID"));
user.setUserName(rs.getString("userName"));
user.setPassword(rs.getString("password"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
}
catch
(Exception
e)
{
e.printStackTrace();
}
finally
{
this.closeAll(conn,
pstmt,
rs);
}
return
list;
}/**
*
查找所有的注册用户信息
*
@return
用户列表
*/
public
List
selectAllUser(){
List
list=new
ArrayList();
String
sql
=
"select
*
from
users
";
try
{
conn
=
this.getConn();
pstmt
=
conn.prepareStatement(sql);
rs
=
pstmt.executeQuery();
while(rs.next())
{
Users
user
=
new
Users();
user.setUserID(rs.getInt("userID"));
user.setUserName(rs.getString("userName"));
user.setPassword(rs.getString("password"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
}
catch
(Exception
e)
{
e.printStackTrace();
}
finally
{
this.closeAll(conn,
pstmt,
rs);
}
return
list;
}
*
查找所有的注册用户信息
*
@return
用户列表
*/
public
List
selectAllUser(){
List
list=new
ArrayList();
String
sql
=
"select
*
from
users
";
try
{
conn
=
this.getConn();
pstmt
=
conn.prepareStatement(sql);
rs
=
pstmt.executeQuery();
while(rs.next())
{
Users
user
=
new
Users();
user.setUserID(rs.getInt("userID"));
user.setUserName(rs.getString("userName"));
user.setPassword(rs.getString("password"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
}
catch
(Exception
e)
{
e.printStackTrace();
}
finally
{
this.closeAll(conn,
pstmt,
rs);
}
return
list;
}/**
*
查找所有的注册用户信息
*
@return
用户列表
*/
public
List
selectAllUser(){
List
list=new
ArrayList();
String
sql
=
"select
*
from
users
";
try
{
conn
=
this.getConn();
pstmt
=
conn.prepareStatement(sql);
rs
=
pstmt.executeQuery();
while(rs.next())
{
Users
user
=
new
Users();
user.setUserID(rs.getInt("userID"));
user.setUserName(rs.getString("userName"));
user.setPassword(rs.getString("password"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
}
catch
(Exception
e)
{
e.printStackTrace();
}
finally
{
this.closeAll(conn,
pstmt,
rs);
}
return
list;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |