load database info in a JSP using a config file

Reply

Join Date: Sep 2009
Posts: 2
Reputation: ash2401 is an unknown quantity at this point 
Solved Threads: 0
ash2401 ash2401 is offline Offline
Newbie Poster

load database info in a JSP using a config file

 
0
  #1
Sep 22nd, 2009
I am new to JSPs. I would like to know how can I get the database info (drivername, url, username, password etc.) to load from a config file into the JSP rather than hard coding the values there.

Thank you everyone in advance.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,672
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 225
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: load database info in a JSP using a config file

 
0
  #2
Sep 23rd, 2009
Check the Read Me post at the top of the jsp forum:
JSP database connectivity according to Model View Controller (MVC) Model 2
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 2
Reputation: ash2401 is an unknown quantity at this point 
Solved Threads: 0
ash2401 ash2401 is offline Offline
Newbie Poster

Re: load database info in a JSP using a config file

 
0
  #3
Sep 23rd, 2009
This is what I am trying to do

  1. Properties properties = new Properties();
  2. try {
  3. properties.load(new FileInputStream("database.properties"));
  4. } catch (IOException e)
  5. {
  6. System.err.println(e.getMessage());
  7. }

but this is apparently not retrieving any data from the properties file. Can someone tell me where exactly does the .properties file needs to be placed (the directory structure).
Last edited by peter_budo; Sep 25th, 2009 at 4:37 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: emnidhi is an unknown quantity at this point 
Solved Threads: 0
emnidhi emnidhi is offline Offline
Newbie Poster

Re: load database info in a JSP using a config file

 
0
  #4
Sep 25th, 2009
Step1: import java.sql.*;[/B]
Step 2: use ResourceBundle sql= ResourceBundle.getBundle("resource.propertiesFileName");
Step 3: use sql.getString("dbUrlStringInPropertiesFile") etc to get values of url, user and pwd.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC