Any idea?
I get this error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /test2.jsp at line 7
4: <title>DB Test</title>
5: </head><body>
6: <% DBConnect d = new DBConnect();
7: ResultSet rs = d.getResult("SELECT name FROM items");
8:
9: while (rs.next()) {
10: String name = rs.getString("name");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
com.monkeygarage.DBConnect.getResult(Unknown Source)
org.apache.jsp.test2_jsp._jspService(test2_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Here's the code for the JSP:
<%@page import="com.monkeygarage.DBConnect,java.sql.*"%>
<html>
<head>
<title>DB Test</title>
</head><body>
<% DBConnect d = new DBConnect();
ResultSet rs = d.getResult("SELECT name FROM items");
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);}
%>
</body>
</html>
And I should mention, when I run the DBconnect.java bit in Eclipse, it works just fine and actually will return the answer to:
public static void main(String[] args) {
try {
DBConnect d = new DBConnect();
ResultSet rs = d.getResult("SELECT name FROM items");
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
which is simply, mustang