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

あなたConnectionNULL

DSN を作成しましたか? そうでない場合は、 を作成してSystem DSNから再試行してください。

于 2012-04-17T04:28:12.297 に答える