Possible problem with satic declaration or datasource
Varnam Aayiram
Ranch Hand
Joined: Dec 23, 2008
Posts: 88
posted
0
Hi Folks...
I was trying to run the following code and am getting this error:
Exception in thread "main" java.lang.NullPointerException at com.ProjecteBooking4.controller.writeBean.main(writeBean.java:36)
Here is the code:
The error is pointing to the line:
What could be causing this problem? Is the satic declaration of DataSource the problem? but unless I decalre it as static I dont think I can access it from the main method. I hope someone can advise. Thanks.
Looks like the @Resource annotation failed to find the JNDI entry.
What mechanism/container are you using to processes the @Resource annotation? What container is maintaining the data sources and the JNDI tree? (Spring? An app server? Something else?)
By the way, this is not a database issue, rather it is a container issue.
I appreciate the reply. I am using glassfish as the appserver. Datasource has already been set up. The database is MySQL, the IDE I am using is NetBeans. The code I posted was part of a web app. I was actually testing this particular piece of code seperately to see if I can use this bean to write to the table. The Servlets in this webapp dont seem to have any problem writing to the table in the database. I am not sure what else to do...