This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible problem with satic declaration or datasource

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a glassfish question (glassfish failed to fill in the @Resource), moving
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic