Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Possible problem with satic declaration or datasource

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??

 
reply
    Bookmark Topic Watch Topic
  • New Topic