aspose file tools*
The moose likes Servlets and the fly likes SQLQueries.properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SQLQueries.properties" Watch "SQLQueries.properties" New topic
Author

SQLQueries.properties

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hello everyone,

Does someone know how can I make a special file only for the SQL Queries? And how can I use these queries in a jsp/servlet file? I tried to make a SQLQuesrie.properties but i still get the following errors:

java.util.MissingResourceException: Can't find bundle for base name SQLQueries,
locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:839)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:808)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:552)
at test.TestDatabase.doGet(TestDatabase.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:534)

It's maybe that I've placed the SQLQueries.properties in a wrong dir. Could someone help me to fix this problem?
I use Resin 2.1.14 webserver.

Abu Romaysa

[ December 08, 2004: Message edited by: Azz Romaysa ]
[ December 08, 2004: Message edited by: Azz Romaysa ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The ResourceBundle you are trying to load would be in a file called SQLQueries_en_US.properties. And that file would need to be in the classpath. Are both of these things true? And why are you trying to internationalize SQL queries? Unless you are connecting to different schemas dependent on Locale I can't see why you'd do this.
[ December 08, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi Paul,

Thnx for ur replay.
My file called SQLQueries.properties and it's in the calsspath.

The reason why I did that is that I want to separate the sql queries from the java code.

This is my SQLQueries.properties


And this is a Databasetest calss:


Before that, I used the traditional method in my webapplications, a databaseConnection calss, en all my jsp's call a method in that class to make the connection with the database. I want now to separate that, because I've a lot of queries.

Thanks
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 140
Hi,
Its one of the approaches to make the application maintainable, but having the SQL queries in DAO objects would be the right aproach, rather than using property files.

Cause, reading property files would rather tend to slow down the system.

See java Blue Prints to know more about DAO Objects.


Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Could you place an example please. I want to try it and see if it'll work.

Thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Cause, reading property files would rather tend to slow down the system.

Except that Azz Romaysa seems to want to use ResourceBundles for this, which are cached after being read.


My file called SQLQueries.properties and it's in the calsspath

And where is SQLQueries_en_US.properties? Because you are using ResourceBundles, the getBundle() method is looking for a properties file which contains the resources for the current default Locale, which in your case seems to be en_US.

I still don't understand why you need to internationalize your SQL though.

DAO's may well be a better way to go though.
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi,
I tried to rename my properties file from SQLQueries.properties to SQLQueries_en_US.properties but resin still give me the same error.

Here is a csreenshot of the structure of my resin:


the SQLQueries_en_US.propertie is under props dir.
[ December 08, 2004: Message edited by: Azz Romaysa ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well I don't know Resin at all, but I always assumed that the classpath for WebApps usually only included WEB-INF/classes and WEB-INF/lib. A simplified explanation of what the getBundle method does is trawls the classpath looking for the file. If it can't find it it is because:
  • There isn't a properties file for the Locale you are using
  • There is a typo either in your code or in the properties file name
  • The properties file is not in the classpath

  • So its one of those reasons, and I suspect its the last.

    I still don't see why you need to internationalize your SQL though.
    [ December 09, 2004: Message edited by: Paul Sturrock ]
    Azz Romaysa
    Ranch Hand

    Joined: Dec 08, 2004
    Posts: 66
    Thanks,

    It works now great. The problem was that I should restart resin even I changed the servlet or the .properties file.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: SQLQueries.properties