• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

Testing to connect to DB and MissingResourceException

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,
I trying to test a simple servlet to connect to Oracle DB (8.1.7) and Jboss (3.0.6). I have .properties file (Connection.properties) which contains url, userid and password to be used to connect to DB. I have placed this file into the WEB-INF/classes directory since this directory is automatically on the CLASSPATH. Here is the exact location:
C:\java\jboss-3.0.6_tomcat-4.1.18\server\default\deploy\jmx-console.war\WEB-INF\classes
(I am using default config of JBoss).
Here is what I do to load the connection properties file:
ResBundle = ResourceBundle.getBundle("Connection");
But here is what I get:
ERROR [STDERR] java.util.MissingResourceException: Can't find bundle for base name Connection, locale en_US
How can I narrow down and figure out why my servlet is unable to locate this file?
TIA!
Amer
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by testing? Are you just manually browsing the web application to make the servlet do something or are you running some kind of unit tests when you get this exception?
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lesse,
Thanks for your time.
I have a jsp page where I input some values. I want to store these values into a table in the DB. JSP calls the "servlet" (action=contextParh+"/servlet" method="post")that tries to load the "Connection.properties" file as I mentioned in my previous post. Right at this point, I get the exception.
This servlet is not part of any application.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My apologies Lasse, I misspelled your name in my previous post.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(sorry to respond with yet another question...)
What do you mean by the servlet not belonging to any application? Do you mean that the JSP and servlet are part of different applications?
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please pardon me for not explaining my issue properly.
OK, let me put it this way. All of my stuff I am trying to test is part of a small app. I am using ant to build it and deploy. Everything was going OK until I hit the MissingResourceException. Then I copied my "Connection.properties" file into the WEB-INF/classes folder so that it becomes visible to my servlet (in other words, it is in a directory that is on the CLASSPATH).
But my servlet is not able to see it and I am getting this exception.
Hope this clears any confusions I might have caused.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you access the properties file using getClass().getResourceAsStream("Connection.properties") directly?
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your time Lasse!
I have solved the problem. All I needed to do was place the "Connection.properties" file into "WEB-INF/classes" directory of my app in the development hierarchy.
But I wonder is this how we should be doing in real life?
Cheers!
 
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saeed,
We do that (put properties files in the classes directory) for struts config files. For other config files (like the db properties), we use a separate /config folder and put this folder in the classpath.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jeanne,
Thanks for the valuable tip.
Does this /config directory has to be somewhere in directory hierarchy of the Web Server (JBoss in my case)?
If yes, where?
Thanks and regards,
Saeed
 
Jeanne Boyarsky
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saeed,
It has to be somewhere on the same machine as JBoss. You pick the directory and include it in your application's classpath.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! I got it.
Thanks!
 
I'm full of tinier men! And a tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic