• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MS Access NullPointerException

 
Marc O'Ceallaigh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21001
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

----------------------------------------------------------------------------
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
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does getConnection() do if a SQLException is thrown?
 
Marc O'Ceallaigh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21001
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1870
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any database field which dont accept null values then they might cause a problem.
 
Marc O'Ceallaigh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic