Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 69440 invoked from network); 8 Apr 2002 21:55:08 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 8 Apr 2002 21:55:08 -0000 Received: (qmail 14233 invoked by uid 97); 8 Apr 2002 21:54:51 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 14217 invoked by uid 97); 8 Apr 2002 21:54:50 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 14206 invoked from network); 8 Apr 2002 21:54:50 -0000 Message-ID: <71B56021D147D411A2C700508BADCA3C01E7981A@DENMAIL1> From: "Philip Kazmier, CEM R&D" To: 'Tomcat Users List' Subject: RE: NullPointerException when using JDBC ResultSet next() method Date: Mon, 8 Apr 2002 15:54:39 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I apologize but I posted the wrong code. Here is the correct code. Line 45 is rs.next. I am not sure that the driver has loaded properly. How can I tell? Thanks. import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class ListAllOpenBugs extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Connection con = null; //Statement stmt = null; ResultSet rs = null; int i = 0; res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { // Load Oracle driver //DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); // Load the MySQL driver Class.forName("org.gjt.mm.mysql.Driver"); // Connect to the local database //Connection conn = //DriverManager.getConnection("jdbc:oracle:thin:172.24.230.20:1521:ORCL", "system", "manager"); // Get a connection to the database con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pssoftware?user=phi lk&password=kirov"); // Query the employee names Statement stmt = con.createStatement (); //ResultSet rset = stmt.executeQuery ("select b.bug_row_id, b.status, ps.name, b.short_desc, b.date_opened from bug b, ps_software ps where b.software_id = ps.pss_row_id and b.status = 1"); ResultSet rset = stmt.executeQuery ("select sc_id from bug_status_codes"); // Display the result set as a list out.println("All Open Bugs"); out.println(""); out.println(""); out.println(""); out.println(""); while(rs.next()) { // if (i == 1) // { // i=0; //out.println(""); //out.println(""); out.println(""); // } // else // { // i=1; //out.println(""); //out.println(""); // } } out.println("
" + rs.getString("bug_row_id") + "" + rs.getString("name") + "" + rs.getString("status") + "" + rs.getString("date_opened") + "" + rs.getString("short_desc") + "
" + rs.getString("bug_row_id") + "
" + rs.getString("sc_id") + "
" + rs.getString("bug_row_id") + "" + rs.getString("name") + "" + rs.getString("status") + "" + rs.getString("date_opened") + "" + rs.getString("short_desc") + "
" + rs.getString("bug_row_id") + "
"); out.println(""); } catch (ClassNotFoundException e) { out.println("Couldn't load the database driver-> " + e.getMessage()); } catch(SQLException e) { out.println("SQLException caught: " + e.getMessage()); } finally { try { if (con != null) con.close(); } catch(SQLException ignored) { } } } }; -----Original Message----- From: August Detlefsen [mailto:augustd123@yahoo.com] Sent: Monday, April 08, 2002 1:19 PM To: Tomcat Users List Subject: Re: NullPointerException when using JDBC ResultSet next() method The stack trace says that your NullPointer occurs on line 45, but line 45 is blank. Is there some more code that you didn't ost? Import statements, perhaps? I think it probably happened here: stmt = con.createStatement(); -IE: You were not able to get a Connection, con is null and calling its methods will give you the NullPointer. Are you sure the driver loaded properly? --- "Philip Kazmier, CEM R&D" wrote: > > > I am getting this error in a servlet compiled on Win2K, using > JDK1.3.1 and > Tomcat 3.3 with MySQL 3.23.47: > > Location: /PSSoftware/servlet/ListAllOpenBugs > Internal Servlet Error: > java.lang.NullPointerException > at ListAllOpenBugs.doGet(ListAllOpenBugs.java:45) > at javax.servlet.http.HttpServlet.service(HttpServlet.java) > at javax.servlet.http.HttpServlet.service(HttpServlet.java) > at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source) > at org.apache.tomcat.core.Handler.invoke(Unknown Source) > at org.apache.tomcat.core.Handler.service(Unknown Source) > at org.apache.tomcat.facade.ServletHandler.service(Unknown Source) > at org.apache.tomcat.core.ContextManager.internalService(Unknown > Source) > at org.apache.tomcat.core.ContextManager.service(Unknown Source) > at > org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Unknown > Source) > at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source) > at > org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown > Source) > at java.lang.Thread.run(Thread.java:484) > > > Here is the servlet code: > > public class MySQLTest extends HttpServlet > { > public void doGet(HttpServletRequest req, HttpServletResponse res) > throws ServletException, IOException > { > Connection con = null; > Statement stmt = null; > ResultSet rs = null; > > res.setContentType("text/html"); > PrintWriter out = res.getWriter(); > > try > { > // Load the MySQL driver > Class.forName("org.gjt.mm.mysql.Driver"); > //try { > > //Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver"); > //} > //catch(Exception e){out.println(e);} > > // Get a connection to the database > con = > DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&pass > word=typhoon"); > > // Create a statement object > stmt = con.createStatement(); > > // Execute and SQL query, get a result set > rs = stmt.executeQuery("SELECT * from test"); > > // Display the result set as a list > > out.println("Test"); > out.println(""); > out.println("
    "); > while(rs.next()) > { > out.println("
  • " + rs.getString("test")); > } > out.println("
"); > out.println(""); > > } > catch (ClassNotFoundException e) > { > out.println("Couldn't load the database driver-> " + > e.getMessage()); > } > catch(SQLException e) > { > out.println("SQLException caught: " + > e.getMessage()); > } > > finally > { > try > { > if (con != null) con.close(); > } > catch(SQLException ignored) { } > } > } > }; > > As you can see I tried this with Oracle. I get the same result when > I used > Oracle. > > Thanks. > > Phil Kazmier > Developer, CEM > NICE Systems > Denver, Colorado > Office (720) 264-4284 > > > -- > To unsubscribe: > For additional commands: > Troubles with the list: > __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ -- To unsubscribe: For additional commands: Troubles with the list: -- To unsubscribe: For additional commands: Troubles with the list: