0

I am having issues creating a table using the following JSP code. The error is related to line 17 of my code. I have included both the error I am getting, as well as my code. Any help is much appreciated!

My Code

<%@ 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();
%>

ERROR

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
ajj
  • 127
  • 1
  • 4
  • 10
  • 1
    Aw no, please, don't use scriptlets `:'(` http://stackoverflow.com/a/3180202/139010 – Matt Ball Apr 17 '12 at 00:53
  • @ajj where is your Datasource `productDSN` pointing to, Did you create an excel spreadsheet to populate? and where have you saved it? – mykey Apr 17 '12 at 07:56

1 Answers1

0

Your Connection is NULL

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

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96