File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ResourceBundle - Creating required fields in properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ResourceBundle - Creating required fields in properties" Watch "ResourceBundle - Creating required fields in properties" New topic
Author

ResourceBundle - Creating required fields in properties

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi guys! I'm using ResourceBundle class to store some SQL query and command line execution. Then I have to replace this by going through a loop. My properties file looks like this...

command=mysqldump -User -pPassword --host=localhost --quick --where="user_id=<username>" <database> <table> > file


I was thinking of doing

String command = commandManager.getString("command");

then going through a loop by doing

String tmpCommand = new String(command);

and then replaceing the <user>, <database> and <table> parts with something. But this seems very expensive. Is there any better way of doing this?

I was thinking like...

command=mysqldump -User -pPassword --host=localhost --quick --where="user_id={0}" {1} {2} > file

But nothing in those can be optional. All is required... Please help... Thanks!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why are you using these instead of the command line itself? And why a ResourceBundle? These are intended to be used for locale-specific property substitution, and since there is no such thing as locale specific SQL I'm not sure you need it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Thanks for your reply!

I was instructed to replace a PHP script used for backing up the database with a Java version. So I'm creating a small app for this purpose. The ResourceBundle is used for flexibility so the client won't have to ask me to modify the source code when they need to add something like add an extra option to the command.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ok. In that case why not just use a properties file? It doesn't sound like you need to support different language versions of these command line parameters so a ResourceBundle is a bit unnecessary.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hmmm...After reading stuff about dependency injection I realized what you mean to say(saw it through example). But it's too late since I used ResourceBundle in every properties file I made. I'll remember this on my next project and do as you say. Thank you.

Now what I need to know about ResourceBundle is that I plan to make an ala-PreparedStatement feature where I could just replace something in the value String that I get from the bundle. Like

command=mycommand <param1> <param2>

but I don't want it to look like the above. I want it like

command=mycommand {0} {1}

and I know ResourceBundle supports something like that. But I don't know how to apply it and I haven't read that much about it. Thank you!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

ResourceBundle doesn't support that, but java.text.MessageFormat does.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResourceBundle - Creating required fields in properties