• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 !
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

This issue is usually to do with CLASSPATH, e.g. The resource bundle must be on the CLASSPATH for that running Servlet.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a reading about Internationalization. Try a simple Hello world style application to make sure you understand it correctly.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i make runtime manipulation for the properties file if it lie inside WEB-INF/classes folder ?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i modified the property file and its working fine ....
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read .properties file this way too ..
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic