• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in thread "main" java.lang.NullPointerException (cannot connect to database)

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys

would you kno what i am missing?

i am just new to spring and i was ask first to connect to the database using bean.
found a helpful tutorial about it but it still seems not working with me.

im getting this error :




would appreciate your help.

Thank you and God Bless


here is my java ..

DashboardDetailsDaoImpl .java




now here is the ApplicationContext in which i place the connection in a bean.

ApplicationContext .xml



thanks so much
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so this is a stand alone application? I see you are using Spring 2.5? Is that a requirement? If it is not then upgrade to the newest. Currently 3.1.2

This is sufficient



get rid of this



I would use JDBCTemplate you are not gaining any of the advantages of exception translation or other benefits that Spring provides.

You are not bootstrapping your application correctly. @Autowired only happens in Spring managed beans. You are actually not even bootstrapping Spring at all.

Your main method needs to have something more like this.



Also your transaction manager is not going to work outside of a JEE container.

try this:



Also be aware that DriverManagerDataSource is fine for testing but it should not be used in production.


I think you may need to take a few steps back, buy a book or start with some beginner tutorials and work your way up to what you are trying to do here.

You can start with some of the suggestions I gave but you will find there is a lot to learn, so I would start with the basics like dependency injection and then start adding things as your understanding of what Spring is and how it works increases.

Good Luck!
 
khamhielle gabriel
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill


Thank you for your reply
i admit im not yet familiar with what Spring can truly offer.
so i kind off, find it difficult still, to grasp some functionality.

anyways, i have tried to implement your suggestion like this.






then

applicationContext.xml



fyi applicationContext.xml resides under target/DasboardDetails/WEB-INF



but now im having this error :






would again appreciate your help ..
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the stack trace it says

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

It is not finding applicationContext.xml.

in the code you posted it looks like you are loading Spring.xml not applicationContext.xml. What is actually the name of the file? Also is the file directly on the class path? i.e src/main/resources? If it is under a subdirectory then you must specify this when you load it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic