The moose likes JDBC and the fly likes Using ResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using ResourceBundle" Watch "Using ResourceBundle" New topic

Using ResourceBundle

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I'm trying to load driver info, URL info, userID info, and password info for my MySQL database by using a ConnectU.properties file that contains:

I trying to get this info from a java file with that contains the following snippet:

I keep getting the error:
Specific Error: Can't find bundle for base name ConectU cal.en_US
which is printed from the above catch statement.
Can someone please explain how the properties file works and how I can get a program to access this file if I need to write a program for a DB in which the user will not need to know the driver location, URL, login, and password? I hope all of this makes sense as I am green in this area.
Thanks in advance, Brian!!!
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I actually answered my own question with thanks to long sun. I didn;t realize you had to actually set the properties using a properties file. Thanks!!
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
I compiled and tested your original code, and it worked fine for me. Are you absolutely sure about the properties file name? It has to be "ConnectU.properties", in the same directory as the .class file (or in the same relative path in a JAR file), otherwise you'll get the error you mention. From the error message, it looks like you tried to load "ConectU.properties", with one "n". Also, if the program is in a package (foo.bar.ConnectU), the getBundle() method must use the full package name prefix ("foo.bar.ConnectU").
So you don't have to explicitly treat the properties file as a java.util.Properties object - it can be a ResourceBundle as well, exactly as you have written it.

Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks Phil. I works for me now as well. It must have been a typo. I was also working on that problem at 4:00 AM. I slept on it and the next day, all was well. Sorry for the confusion!!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Using ResourceBundle
Similar Threads
Database connection problem
Establishing Connections to a Data base on a different machine
Bean New class wont compile
Problem in inserting record to Oracle Database.
JSP UseBean. How to pass PATH-info.