什么问题造成的呢?还请高手解答~ javax.servlet.ServletException: Servlet execution threw an exception

java.lang.StackOverflowErrorcom.classmate.dao.PostDao.<init>(PostDao.java:20)PostDao.... java.lang.StackOverflowError
com.classmate.dao.PostDao.<init>(PostDao.java:20)
PostDao.java代码:
public class PostDao {
private ClassInfoDao cDao=new ClassInfoDao();
private UserDao uDao=new UserDao();
public List<Post> getAllPost(int classid) throws MyException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

conn = JDBCConnection.getConnection();
List<Post> list=new ArrayList<Post>();
ClassInfo c = null;
try {
c=cDao.findById(classid);
if(c!=null){
stmt = conn.createStatement();
String sql = "select * from post_tbl where classid=" + classid;
rs = stmt.executeQuery(sql);
while(rs.next()) {
Post post=new Post();
post.setId(rs.getInt("id"));
post.setPosttitle(rs.getString("posttitle"));
post.setPostcontent(rs.getString("postcontent"));
post.setParentpostid(rs.getInt("parentpostid"));
post.setTimestr(rs.getTimestamp("timestr"));
post.setPostusername(rs.getString("username"));
post.setPostclassid(classid);
list.add(post);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCConnection.close(conn, stmt, rs);
}
return list;
}
public Post findById(int id) throws MyException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

conn = JDBCConnection.getConnection();
Post post=null;
try {
stmt = conn.createStatement();
String sql = "select * from post_tbl where id=" + id;
rs = stmt.executeQuery(sql);
if(rs.next()) {
post=new Post();
post.setId(id);
post.setPosttitle(rs.getString("posttitle"));
post.setPostcontent(rs.getString("postcontent"));
post.setParentpostid(rs.getInt("parentpostid"));
post.setTimestr(rs.getTimestamp("timestr"));
post.setPostusername(rs.getString("username"));
post.setPostclassid(rs.getInt("classid"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCConnection.close(conn, stmt, rs);
}
return post;
}
public void add(String title,String content,int pid,String username, int classid)throws MyException{
Connection conn = null;
Statement stmt = null;

conn = JDBCConnection.getConnection();
User user = null;
ClassInfo classinfo=null;
try {
user=uDao.findByUNameCId(username, classid);
classinfo=cDao.findById(classid);
if(user!=null && classinfo!=null ){
stmt = conn.createStatement();
String sql = "insert into post_tbl values(POST_SEQ_COMMON.nextval,'" + title +"','"+content+"',"+ pid +",,'"+username
+ "'," + classid + ")";
stmt.execute(sql);
conn.commit();
}else{
JOptionPane.showConfirmDialog(null, "此同学还未注册同学录!");
}
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
} finally {
JDBCConnection.close(conn, stmt, null);
}
}
}
此类还包括这段代码:
public void delete(int ppid)throws MyException{
Connection conn = null;
Statement stmt = null;

conn = JDBCConnection.getConnection();
String sql = "delete from post_tbl where id=" + ppid;
try {
stmt = conn.createStatement();
stmt.execute(sql);
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
} finally {
JDBCConnection.close(conn, stmt, null);
}
}
展开
 我来答
百度网友2031e6a
2012-05-05 · 超过16用户采纳过TA的回答
知道答主
回答量:40
采纳率:0%
帮助的人:43.5万
展开全部
一直new Post()内存溢出了啊 查询可能错了
haohongwei610
2012-05-06
知道答主
回答量:10
采纳率:0%
帮助的人:9.4万
展开全部
请问您一直跑出的myException 在哪里定义过了!!! 你还不如直接跑出 Exception
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
13059055107
2012-05-09
知道答主
回答量:37
采纳率:100%
帮助的人:9.2万
展开全部
中毒了吧?!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式