0

我在使用以下 JSP 代码创建表时遇到问题。该错误与我的代码的第 17 行有关。我已经包含了我得到的错误以及我的代码。任何帮助深表感谢!

我的代码

<%@ page import="java.sql.*" %>
<%
 String url = "jdbc:odbc:productDSN";
 String username="";
 String password="";
 Connection  conn=null;
 String classpath = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
    Class.forName(classpath);
    conn = DriverManager.getConnection(url,username,password);
   }catch(Exception exc){
     out.println(exc.toString());
}

%>
<%
    Statement stm= conn.createStatement();
    String query1, query2;
    query1="CREATE TABLE product(id char(3) PRIMARY KEY,"+
           "name varchar(15),model varchar(5), price float,"+
           "manufacturerID integer)";
    query2="CREATE TABLE manufacturer("+
  "manufacturerID integer PRIMARY KEY,"+
      "name varchar(15),address varchar(20), city varchar(20),"+
      "state varchar(15), zipCode char(5), phone varchar(15))";
try{
stm.executeUpdate(query1);
stm.executeUpdate(query2);

  out.println("Two tables were successfully created.");
}catch(Exception exc){
  out.println("These tables exist already.");
}
stm.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: An exception occurred processing JSP page /example1.jsp at line 17

14: 
15: %>
16: <%
17:     Statement stm= conn.createStatement();
18:     String query1, query2;
19:     query1="CREATE TABLE product(id char(3) PRIMARY KEY,"+
20:            "name varchar(15),model varchar(5), price float,"+


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.NullPointerException
    org.apache.jsp.example1_jsp._jspService(example1_jsp.java:82)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.

Apache Tomcat/7.0.21
4

1 回答 1

0

Your Connection is NULL

Have you created DSN ? If not then, Create the System DSN and then try again.

于 2012-04-17T04:28:12.297 回答