aspose file tools
The moose likes Java in General and the fly likes how to call property file ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to call property file ?" Watch "how to call property file ?" New topic
Author

how to call property file ?

harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Hi All,

Anybody please tell me how to call property file in util classes ?
I have a util class where I have defined the query as :
pstmt = con.prepareStatement("select password from registration where username='"+username+"'");

And I want to use property file instead of writing query in this utility class

please help.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56150
    
  13

Moved to Java in General (intermediate).


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Raymond Villeno
Ranch Hand

Joined: Jun 21, 2005
Posts: 63
Well first ou must create a FileInputStream Object then load it to a Properties Object.

Ex.



Something like that...

Cheers!


"Work Smart Not Hard"
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Thanks for your response.

So this will be done in util class. ?
I am not still clear how to do that. Or how to call querysql.property file in util class ?

Please answer with code ?

Thanks

Harish pathak
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Thanks for your response.

Well I have placed "querysql.property" file inside "C:\orion\default-web-app" and I am retrieving the file as :


FileInputStream fis = new FileInputStream("querysql.property");
Properties dbProp = new Properties();
dbProp.load(fis);
pstmt = con.prepareStatement(dbProp.getProperty("password.query"));



But it gives me the following error:

Exception: verifyPassword=java.io.FileNotFoundException: \querysql.property (The
system cannot find the file specified)

I don't know where I am wrong.

Please reply.

Thanks

harish pathak
harish pathak
Ranch Hand

Joined: Dec 17, 2005
Posts: 51
Also can we use ResourceBundle to call property file.
What is the use of Locale ?

Please explain.

Thanks

harish pathak
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by harish pathak:
Also can we use ResourceBundle to call property file.
What is the use of Locale ?


http://java.sun.com/docs/books/tutorial/i18n/resbundle/index.html


There is no emoticon for what I am feeling!
Vinayak patil
Ranch Hand

Joined: Aug 30, 2005
Posts: 67
Hi,

Is "C:\orion\default-web-app" the root of your project?
The program will try to get the file from the root directory of your project and if it does not find it then it throws a FileNotFoundException

-Vinayak


"I can resist everything except temptation"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call property file ?
 
Similar Threads
Exception while calling stored proc from hibernate. URGENT Help
Help in connecting to oracle10 database using struts
static method vs singleton with static method
Properties in struts
Urgent Help to call Stored Proc from Hibernate Mapping Exception.