<%@ page language="java" import="java.util.*" pageEncoding="GBK"
contentType="text/html;charset=gbk"
%>
<%@ page import="java.sql.*"%>
<%
int id = Integer.parseInt(request.getParameter("id"));
int rootId = Integer.parseInt(request.getParameter("rootid"));
String title = request.getParameter("title");
String cont = request.getParameter("cont"); Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);

conn.setAutoCommit(false); String sql = "insert into article values (null,?,?,?,?,now(),0";
PrepareStatement pstmt;
pstmt = conn.prepareStatement(sql);
Statement stmt = conn.createStatement(); pstmt.setInt(1, id);
pstmt.setInt(2, rootId);
pstmt.setString(3, title);
pstmt.setString(4, cont);
pstmt.executeUpdate(); stmt.executeUpdate("update article set isleaf = 1 where id = "+ id);
    
    conn.commit();
    conn.setAutoCommit(true);
    
    stmt.close();
    pstmt.close();
    conn.close();
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'ReplyOK.jsp' starting page</title>
  </head>
  
  <body>
     <font color="red" size="7">OK</font>
  </body>
</html>
这是源码 问题我再贴

解决方案 »

  1.   

    HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 18 in the jsp file: /ReplyOK.jsp
    PrepareStatement cannot be resolved to a type
    15:  conn.setAutoCommit(false);
    16: 
    17:  String sql = "insert into article values (null,?,?,?,?,now(),0";
    18:  PrepareStatement pstmt;
    19:   pstmt = conn.prepareStatement(sql);
    20:  Statement stmt = conn.createStatement();
    21: 
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.
    --------------------------------------------------------------------------------Apache Tomcat/6.0.32
      

  2.   

    我发现String sql = "insert into article values (null,?,?,?,?,now(),0";少了一个括号
      

  3.   

    编译错误
    PrepareStatement pstmt;
    这个类型是不存在的吧。
    java.sql.PreparedStatement