tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeff.guttada...@abbott.com
Subject Re: NullPointerException when using JDBC ResultSet next() method
Date Mon, 08 Apr 2002 19:04:34 GMT

You sure that your "test" table has a "test" column?  Change rs.getString
("test") to rs.getString(1) to see if that works...
HTH



                                                                                         
                           
                    "Philip                                                              
                           
                    Kazmier, CEM           To:     "'tomcat-user@jakarta.apache.org'"    
                           
                    R&D"                   <tomcat-user@jakarta.apache.org>    
                                     
                    <philip.kazmier        cc:                                        
                              
                    @nice.com>             Subject:     NullPointerException when using
JDBC ResultSet next() method 
                                                                                         
                           
                    04/08/02 12:55                                                       
                           
                    PM                                                                   
                           
                    Please respond                                                       
                           
                    to "Tomcat                                                           
                           
                    Users List"                                                          
                           
                                                                                         
                           
                                                                                         
                           






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("<HTML><HEAD><TITLE>Test</TITLE></HEAD>");
                               out.println("<BODY>");
                               out.println("<UL>");
                               while(rs.next())
                               {
                                          out.println("<LI>" + rs.getString
("test"));
                               }
                               out.println("</UL>");
                               out.println("</BODY></HTML>");

                     }
                     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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>






--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message