我的原码是:
<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="wuhui";
//数据库名
String dbName="hokenn";
//表名
String tableName="wode";
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement Statement=conn.createStatement();
Statement.executeUpdate(\"INSERT into wode(numble,name,xing)\" + \"values(\'numble\',\'name\')\");
out.println(\"记录插入完毕!\");
Statement.close();
conn.close();
%>
可是运行就出现以下错误:
HTTP Status 500 -
type Exception report
message
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: 9 in the jsp file: /t.jsp Generated servlet error: conn cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: statement cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: Stmt cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: conn cannot be resolved org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: conn cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: statement cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: Stmt cannot be resolved An error occurred at line: 9 in the jsp file: /t.jsp Generated servlet error: conn cannot be resolved org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414) org.apache.jasper.compiler.Compiler.compile(Compiler.java:297) org.apache.jasper.compiler.Compiler.compile(Compiler.java:276) org.apache.jasper.compiler.Compiler.compile(Compiler.java:264) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.