BBS论坛无法更新问题
数据库已经连接上,可以注册,可以查询
但无法对帖子,版面,类别进行增加和删除操作,也无法回帖
下面是部分代码
DB.java
{
public void doPstm(String sql,Object[] params){
if(sql!=null&&!sql.equals("")){
System.out.println(sql);
getCon();
try {
pstm=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
if(params==null){
params=new Object[0];
}
for(int i=0;i<params.length;i++){
pstm.setObject(i+1,params[i]);
}
pstm.execute();
} catch (SQLException e) {
System.out.println("调用DB类中doPstm方法时出错!");
e.printStackTrace();
}
}
}
public ResultSet getRs(){
try {
return pstm.getResultSet();
} catch (SQLException e) {
System.out.println("DB类中的getRs()方法出错!");
e.printStackTrace();
return null;
}
}
public int getUpdate(){
try {
return pstm.getUpdateCount();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
}
OpDB.java
{
public int OpUpdate(String sql,Object[] params){
DB mydb=new DB();
mydb.doPstm(sql,params);
int i=mydb.getUpdate();
return i;
}
}
AdminAction.java
{
/** 后台-删除版面 */
public ActionForward deleteBoard(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
String boardId=request.getParameter("boardId");
if(boardId==null||boardId.equals(""))
boardId="-1";
String sql="delete tb_board where board_id=?";
Object[] params={boardId};
OpDB myOp=new OpDB();
int i=myOp.OpUpdate(sql, params);
ActionMessages messages=new ActionMessages();
String forwardPath="";
if(i<=0){
System.out.println("删除版面失败!");
forwardPath="error";
messages.add("adminOpR",new ActionMessage("luntan.admin.delete.board.E"));
}
else{
System.out.println("删除版面成功!");
forwardPath="success";
messages.add("adminOpR",new ActionMessage("luntan.admin.delete.board.S"));
}
saveErrors(request,messages);
return mapping.findForward(forwardPath);
}
}
AdminAccess.java
{
public void doFilter(ServletRequest Srequest, ServletResponse Sresponse, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest)Srequest;
HttpServletResponse response=(HttpServletResponse)Sresponse;
HttpSession session=request.getSession();
Object obj=session.getAttribute("logoner");
if(obj!=null&&(obj instanceof UserForm)){
UserForm logoner=(UserForm)obj;
String able=logoner.getUserAble();
if(able.equals("2")){
chain.doFilter(request, response);
}
else{
request.setAttribute("message","<b><li>您没有权限进行该操作!</li></b>");
RequestDispatcher rd=request.getRequestDispatcher("/pages/message.jsp");
rd.forward(Srequest,Sresponse);
}
}
else{
request.setAttribute("message","<b><li>您没有登录,请先登录!</li></b>");
RequestDispatcher rd=request.getRequestDispatcher("/pages/login.jsp");
rd.forward(Srequest,Sresponse);
}
}
}
UserAccess.java
{
public void doFilter(ServletRequest Srequest, ServletResponse Sresponse, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest)Srequest;
HttpServletResponse response=(HttpServletResponse)Sresponse;
HttpSession session=request.getSession();
Object obj=session.getAttribute("logoner");
if(obj!=null&&(obj instanceof UserForm)){
chain.doFilter(request, response);
}
else{
request.setAttribute("message","<b><li>您没有登录!请先登录!</li></b>");
RequestDispatcher rd=request.getRequestDispatcher("/pages/login.jsp");
rd.forward(Srequest,Sresponse);
}
}
}
下面是错误提示:
delete tb_board where board_id=?
调用DB类中doPstm方法时出错!
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where board_id='16'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:874)
at com.yxq.dao.DB.doPstm(DB.java:49)
at com.yxq.dao.OpDB.OpUpdate(OpDB.java:373)
at com.yxq.action.AdminAction.deleteBoard(AdminAction.java:431)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.yxq.filter.UserAccess.doFilter(UserAccess.java:31)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.yxq.filter.AdminAccess.doFilter(AdminAccess.java:33)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
删除版面失败!
JSP 论坛 mysql
[解决办法]
delete from tb_board where board_id=?
[解决办法]
//你打印看下
System.out.println(classId+"--------->classId");
System.out.println(boardName+"--------->boardName");
System.out.println(boardMaster+"--------->boardMaster");
System.out.println(boardPcard+"--------->boardPcard");