Meaningless Drivel is fun!*
The moose likes Other Java Products and Servers and the fly likes Possible problem with satic declaration or datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Possible problem with satic declaration or datasource" Watch "Possible problem with satic declaration or datasource" New topic
Author

Possible problem with satic declaration or datasource

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
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.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

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.

JBoss In Action
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi Peter..

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...
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

This is a glassfish question (glassfish failed to fill in the @Resource), moving
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi..

One thing I don't understand is when I am connecting to the database and doing read writes to the table via servlets I am using this:



but I dont have a problem there, why is it different when called from a main method in a non servlet java file??

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible problem with satic declaration or datasource