views:

17

answers:

0

Hello

Having rebuilt my Windows 7 PC, I am trying to get Tomcat running under NetBeans to connect to MySQL.

I believe MySQL is alright because the various tools retrieve data correctly. But when my Java web app is run from NetBeans, Tomcat shows the homepage but then gives a Java null pointer error. The logs tell me this is to do with retrieving user data from the database. So I'm assuming that the two system components are not able to talk to each other. But why?

I have mySQLConnector in the NetBeans library my web app is using. I've placed MySQL Connector in Tomcat's config folder, MySQL Connector is also in the classpath of the PC. The context.xml file in the web app is set to use the root user in MySQL and all relevant authorities in MySQL are set.

But I get nothing! Although I have the same tools on another PC and they are fine.

Any ideas? Is there something I've missed?

The Apache log when I run the application is:

11-Oct-2010 11:42:15 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet IndexServlet threw exception

java.lang.NullPointerException
        at visualRSS.index.Index_Servlet.doGet(Index_Servlet.java:91)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
        at java.lang.Thread.run(Thread.java:619)

Line at visualRSS.index.Index_Servlet.doGet(Index_Servlet.java:91) refers to

User user = User_DB.get(userNo);
activeUser = Active_User_Writer.write(request, user, Valid.FALSE);

In my code to get a user from the DB. But nothing... I am assuming it to be a config issue as this code works on another PC.

Code to get a user from the database is as follows:

// Gets a User.
public static User get(String userNo) {
    ConnectionPool_DB pool = ConnectionPool_DB.getInstance();
    Connection connection = pool.getConnection();
    PreparedStatement ps = null;
    ResultSet rs = null;

    String query = ("SELECT * " +
                    "FROM User " +
                    "WHERE UserNo = ?;");

    try {
        System.out.println("Debug userNo: " + userNo);
        ps = connection.prepareStatement(query);
        ps.setString(1, userNo);
        rs = ps.executeQuery();
        System.out.println("Debug query: " + query);
        if (rs.next()) {                
            User u = new User();
            u.setUserNo(rs.getString("UserNo"));
            ...
            System.out.println("Debug: get User");
            return u;
        }
        else {
            System.out.println("Debug: error");
            return null;
        }
    }
    catch(Exception ex) {
        logger.error("Error getting User " + userNo + "\n", ex);
        return null;
    }
    finally {
        Database_Utils.closeResultSet(rs);
        Database_Utils.closePreparedStatement(ps);
        pool.freeConnection(connection);
    }
}

Thanks

Mr Morgan.