什么问题造成的呢?还请高手解答~ 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);
}
} 展开
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);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询