File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes MS Access NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MS Access NullPointerException " Watch "MS Access NullPointerException " New topic
Author

MS Access NullPointerException

Marc O'Ceallaigh
Greenhorn

Joined: Feb 15, 2006
Posts: 4
Hello All,
I am currently doing a Java struts project in college. THe project uses microsoft access. Everything works fine on the machine i use in college but when i try to run my project on my laptop it will not work. The main problem occurs when i try to register a customer to my access database. Why i do this i get a javax.servlet.ServletException whos root cause is a java.lang.NullPointerException on the prepared statement in my method for adding a customer to my database. I have tested this methos using literals and it adds these to the database without any problems but when i try and add from the JSP the above problem occurs. Any help on this would be great as i have tried all i can think of.Thanks in advance
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Hey if any Exceptions are thrown please post it.Its easy to find the exceptions. Also Check if the connections to the database are properly established.
[ February 15, 2006: Message edited by: Sri Ram ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18708
    
    8

Probably you have code that tries to create a connection but fails, doesn't report an exception, and continues on trying to use that (null) connection variable. The reason for failing to create a connection would probably be because the configurations on the two machines are different.

You can post your code if you want suggestions on how to improve it.
Marc O'Ceallaigh
Greenhorn

Joined: Feb 15, 2006
Posts: 4

----------------------------------------------------------------------------
Above is my action class the exception occurs in this class on the line where the insertClient method is called.
Could you possibly tell me where to check the relevant configurations to this situation please??? Thanks

[edited to add code tags]
[ February 16, 2006: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

What does getConnection() do if a SQLException is thrown?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Marc O'Ceallaigh
Greenhorn

Joined: Feb 15, 2006
Posts: 4
Originally posted by Sri Ram:
Hey if any Exceptions are thrown please post it.Its easy to find the exceptions. Also Check if the connections to the database are properly established.

[ February 15, 2006: Message edited by: Sri Ram ]


exception

javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NullPointerException
struts.UserDBUtil.insertCustomer(UserDBUtil.java:60)
struts.RegisterCustomerAction.execute(RegisterCustomerAction.java:77)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

this is the exception that is thrown. Any help with this would be great thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18708
    
    8

It looks to me as if your comments were trying to say the exception occurs here:Was that right? If so, then the conn variable is null. And you can see that it is set just two lines earlier, to the value returned by getConnection(). So that value must be null also. How can getConnection() return null? Shouldn't this lineset it to a non-null value? Well, not if it throws an exception. So that's what's happening. That line of code throws an exception -- which you just print to a log file and ignore -- and then you run into trouble later when you ignore the possibility that there was no connection.
Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
Are there any database field which dont accept null values then they might cause a problem.
Marc O'Ceallaigh
Greenhorn

Joined: Feb 15, 2006
Posts: 4
Was that right? If so, then the conn variable is null. And you can see that it is set just two lines earlier, to the value returned by getConnection(). So that value must be null also. How can getConnection() return null? Shouldn't this lineset it to a non-null value? Well, not if it throws an exception. So that's what's happening. That line of code throws an exception -- which you just print to a log file and ignore -- and then you run into trouble later when you ignore the possibility that there was no connection.[/qb]<hr></blockquote>

That sounds correct. But how can this code work on one machine and not another?? Thanks anyway thats been very helpful.
[ February 23, 2006: Message edited by: Marc O'Ceallaigh ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MS Access NullPointerException