想在数据库中取到uname所对应的某些字段,uname是用户登录所获取来的<%=(String) session.getAttribute("uname")%>。
Class.forName("com.mysql.jdbc.Driver");
Connection ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/lastproject", "root", "#口令无误#");
Statement sm = ct.createStatement();
ResultSet rs = sm.executeQuery("select count(*) from Comment");
if (rs.next()) {
rowCount = rs.getInt(1);
}
//计算pageCount
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
//查询出需要显示的记录
String kk=(String) session.getAttribute("uname");
rs = sm.executeQuery("select cid,cname,cdate,content from Comment where creceiver in (select uname from User where uname=kk) limit " + pageSize * (pageNow - 1) + "," + pageSize);
最后两句有错误,请问如何取到本页面session获取到的uname在数据库中所对应的一些字段呢???executeQuery()中的语句该怎么写呢??
Class.forName("com.mysql.jdbc.Driver");
Connection ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/lastproject", "root", "#口令无误#");
Statement sm = ct.createStatement();
ResultSet rs = sm.executeQuery("select count(*) from Comment");
if (rs.next()) {
rowCount = rs.getInt(1);
}
//计算pageCount
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
//查询出需要显示的记录
String kk=(String) session.getAttribute("uname");
rs = sm.executeQuery("select cid,cname,cdate,content from Comment where creceiver in (select uname from User where uname=kk) limit " + pageSize * (pageNow - 1) + "," + pageSize);
最后两句有错误,请问如何取到本页面session获取到的uname在数据库中所对应的一些字段呢???executeQuery()中的语句该怎么写呢??
本文介绍了一种使用Java从MySQL数据库中查询特定用户评论的方法。通过连接数据库并执行SQL语句,可以获取到由session中获取的用户名所对应的评论信息,并进行分页处理。
1559

被折叠的 条评论
为什么被折叠?



