日期:2014-05-17  浏览次数:20858 次

怎样查询出数据库的帖子标题?遇到点问题,看下面具体代码,求大神赐教啊···
这里涉及到两张表,一张帖子,一张用户表。下面主要是想查询出用户发的帖子的标题.数据库通过登录时session等到的userName来查询用户所发的帖子。下面是我写的查询代码。(帖子表中的PostSender和用户表中的UserName 是相等的)

但是运行时会报错,错误代码在下面。我不知道怎么错的,请大家教教我啊···
public List<Poster> listpraPost(String userName) throws SQLException {
ArrayList<Poster> postList = new ArrayList<Poster>();
Connection conn = null;
PreparedStatement stat = null;
ResultSet rst = null;
Poster poster = new Poster();
User user=new User();
try {
conn = db.getConnection();
stat = conn.prepareStatement("select PostTitle from Bbs_Post,tbl_Assistant where Bbs_Post.PostSender=tbl_Assistant.UserName and UserName=? ");
stat.setString(1,poster.getPostTitle());
stat.setString(2,userName);
rst=stat.executeQuery();
while (rst.next()) {
poster.setPostTitle(rst.getString(1));
user.setUserName(rst.getString(2));
//poster.setPostSender(rst.getString(2));
postList.add(poster);
}
} finally {
DB.release(conn, stat, rst);
}
return postList;
}


JSP页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"
  pageEncoding="UTF-8"%>
  <%@page import="valuebean.User" %>
  <%@page import="dao.UsersDao" %>
  <%@page import="valuebean.Poster" %> 
  <%@page import="dao.PostDao" %>
  <jsp:useBean id="connBean" scope="page" class="db.connDB"/>
  <%-- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%>
<%
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath() + "/";
/* User user=new User();
Poster poster=new Poster(); */
%>

<%
String userName=(String)session.getAttribute("userName");
User user=new User();
UsersDao usersdao=new UsersDao();
user=usersdao.selectInfo(userName);
  String userName1=(String)user.getUserName();
  int grade=user.getGrade();
  Poster poster=new Poster();
  PostDao postdao=new PostDao();
  postdao.listpraPost(userName);
  String posttitle=poster.getPostTitle();
%>
下面的代码省略···


错与提示:org.apache.jasper.JasperException: An exception occurred processing JSP page /front/myplace.jsp at line 26

23: int grade=user.getGrade();
24: Poster poster=new Poster();
25: PostDao postdao=new PostDao();
26: postdao.listpraPost(userName);
27: String posttitle=poster.getPostTitle();
28: %>
29: 


Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.c