aspose file tools*
The moose likes Servlets and the fly likes Properties File Error java.util.Resource Bundle. throw Missing Resource Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Properties File Error java.util.Resource Bundle. throw Missing Resource Exception" Watch "Properties File Error java.util.Resource Bundle. throw Missing Resource Exception" New topic
Author

Properties File Error java.util.Resource Bundle. throw Missing Resource Exception

carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

Hi i created a property file named DatabaseConnection_en_US.properties in my application the property file is accessed in a .java class to get connected with the database

DatabaseConnection_en_US.properties
[code]

Driver=net.sourceforge.jtds.jdbc.Driver
URL=jdbc:jtds:sqlserver://DCSRV02:1433/REGISTRATION_TEMP_LTR_PRINT


My DBConnection.java file
[code]

import java.sql.*;
import java.util.*;

public class DBConnection {
public Connection connection =null;
public void connect()
{
ResourceBundle bundle = ResourceBundle.getBundle("PlotManagement.DatabaseConnection");

try {
Class.forName(bundle.getString("Driver"));
String connectionUrl = bundle.getString("URL");
connection = DriverManager.getConnection(connectionUrl,"sa","water");
System.out.println("Connected");
}
catch (Exception e)
{
System.out.println( "<h1>exception: "+e+e.getMessage()+"</h1>" );
e.printStackTrace();
}


}

}

when i execute the .java file by adding main method the file shows its connected with database but when i inialise the file in some servlet and try to get connected with database it gives me exception:-

java.util.MissingResourceException: Can't find bundle for base name PlotManagement.DatabaseConnection, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at PlotManagement.DBConnection.connect(DBConnection.java:10)
at PlotManagement.GetPropertyDetails.doGet(GetPropertyDetails.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)

Please suggest me to solve this issue..
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1



Checkout for the PlotManagement directory , its must contain DatabaseConnection.propertise file and must in class path and rename the "DatabaseConnection_en_US.properties" to "DatabaseConnection.properties" ..

See this for details !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there!

This issue is usually to do with CLASSPATH, e.g. The resource bundle must be on the CLASSPATH for that running Servlet.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

i modified the DatabaseConnection_en_US.properties to DatabaseConnection.properties, my property file,DBConnection.java,servlets are under the package PlotManagement. In my classpath i added c:\tomcat5.5\webapps\MyPlots\src\PlotManagement\DatabaseConnection.properties.
But still it is giving the same error. :roll:
[ October 06, 2008: Message edited by: ruquia tabassum ]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by ruquia tabassum:
my property file,DBConnection.java,servlets are under the package PlotManagement.


If so, then remove that package name , like
do



Try this,
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

It still gives me the same error

exception: java.util.MissingResourceException: Can't find bundle for base name DatabaseConnection, locale en_
Yves Zoundi
Ranch Hand

Joined: Aug 31, 2008
Posts: 47
Have a reading about Internationalization. Try a simple Hello world style application to make sure you understand it correctly.


Author of VFSJFileChooser and XPontus XML Editor
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by ruquia tabassum:
It still gives me the same error

exception: java.util.MissingResourceException: Can't find bundle for base name DatabaseConnection, locale en_


Ok, Make some changes , like this ,



Put all the fields in same package , i.e in 'PlotManagement' ( and please follow Java naming conventions, define package in small alphabet , like plotmanagement, for better programming practice !)
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

when i place the DatabaseConnection.properties inside WEB-INF/classes folder it solved the problem now its connected to the database... whenever i change my database i need to change the driver and url inside property file which is present in WEB-INF/classes folder?
[ October 06, 2008: Message edited by: ruquia tabassum ]
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

how can i make runtime manipulation for the properties file if it lie inside WEB-INF/classes folder ?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by ruquia tabassum:
how can i make runtime manipulation for the properties file if it lie inside WEB-INF/classes folder ?


You can manipulate that resource file, try to change DB URL , and see whether those affect the servlet execution !!
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

Yeah i modified the property file and its working fine ....
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You can read .properties file this way too ..
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by ruquia tabassum:
when i place the DatabaseConnection.properties inside WEB-INF/classes folder it solved the problem now its connected to the database


Thats the expected behavior.

[Edited]
To clarify the things. It looks for resource/s under your WEB-INF/classes directory.
[ October 07, 2008: Message edited by: Adeel Ansari ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by ruquia tabassum:
Yeah i modified the property file and its working fine ....


Don't forget to reload the webapp. Or set it to suto-reload, otherwise.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties File Error java.util.Resource Bundle. throw Missing Resource Exception
 
Similar Threads
Web App cannot see Mysql data
connection problem in mysql
How to use MBean in HibernateAnnotation
driver cannot be found error
How to update a database using web forms