aspose file tools*
The moose likes Tomcat and the fly likes get DB information parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "get DB information parameters" Watch "get DB information parameters" New topic
Author

get DB information parameters

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
I need to get
user_name,
password,
database name
from the text file.
with out xml how can i do that.
or is there any other easy way to set database_name........
in a web application?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

Please take the time to make your question clear. I really don't have a good notion of what you are asking.

Are you saying that you need to read some value from a text file?

If you are just looking for the best way to connect to the database, then a container-managed connection pool is the best way to go. Which container are you using? Tomcat? Other?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
I am using Tomcat.
I need to get always changing data(user name,password,db name) from text file.
But if there is a another better way to do that tell me
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Use Properties API load() , and getProperty() method. But your password would be clear text. is that ok !!
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
I mean if my password or database name or username change i don't need to recompile my servlet.
so i need to separate my varing things from servlet.
what is the best way to do that?
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

aruna sameera wrote:I mean if my password or database name or username change i don't need to recompile my servlet.
so i need to separate my varing things from servlet.
what is the best way to do that?


you dont need to re compile anything!! place your file out of webapp. Load your property file using .load() method taking InputStream as argument.
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Properties props = new Properties();
try {
props.load(new FileInputStream("properties"));
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
But it says there is no method name load()
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Check if you are using java.util.Properties. there might be another class with same name Properties that you have created.

Also i m surprised "But it says there is no method name load()" , you wont even believe Java API ( link which i pointed) ?
Mark Williams
Ranch Hand

Joined: Aug 01, 2008
Posts: 66
An alternative to using properties is to store the values in the web.xml as environment entries and use JNDI to retrieve the values.
The last time I checked, passwords were still stored in plain text with this method as well though. But, since your application already has a deployment descriptor, why not use it to store this info?
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
it is ok.i am using another kind of property.
but it still gives null as result.anyway i can find it
Thanks for help
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Mark Williams wrote:An alternative to using properties is to store the values in the web.xml as environment entries and use JNDI to retrieve the values.
The last time I checked, passwords were still stored in plain text with this method as well though. But, since your application already has a deployment descriptor, why not use it to store this info?


That requries a server bounce , when values changed.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

Tomcat has a great DBCP connection pooling mechanism. I strongly suggest you use it. Then your DB information is stored in the Tomcat config and Tomcat manages all the connection pooling for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get DB information parameters
 
Similar Threads
Multiple scripting errors
Java joke
Future of Java Professionals
It has something to do with iron.
16th Nov Riddle