在JavaBean中使用prepareStatement查询数据,如何把查询的结果传回JSP页面中
//查看数据publicResultSetgetselect(intid){Connectionconn=null;PreparedStatementps=null;Re...
//查看数据
public ResultSet getselect(int id){
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=Mydao.getConnection();
String sql="select * from person where id=?";
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
rs=ps.executeQuery();
}catch (Exception e) {
e.printStackTrace();
}
return rs;
}
@SuppressWarnings("static-access")
private person mappingPerson(ResultSet rs) throws SQLException {
person per = new person();
per.setId(rs.getInt("id"));
per.setUid(rs.getString("uid"));
per.setName(rs.getString("name"));
per.setPassword(rs.getString("password"));
return per;
}
select.jsp用来输出数据 展开
public ResultSet getselect(int id){
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=Mydao.getConnection();
String sql="select * from person where id=?";
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
rs=ps.executeQuery();
}catch (Exception e) {
e.printStackTrace();
}
return rs;
}
@SuppressWarnings("static-access")
private person mappingPerson(ResultSet rs) throws SQLException {
person per = new person();
per.setId(rs.getInt("id"));
per.setUid(rs.getString("uid"));
per.setName(rs.getString("name"));
per.setPassword(rs.getString("password"));
return per;
}
select.jsp用来输出数据 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询