想在数据库中取到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()中的语句该怎么写呢??