943,708 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 1073
  • JSP RSS
Sep 22nd, 2009
0

load database info in a JSP using a config file

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ash2401 is offline Offline
2 posts
since Sep 2009
Sep 23rd, 2009
0

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

Check the Read Me post at the top of the jsp forum:
JSP database connectivity according to Model View Controller (MVC) Model 2
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Sep 23rd, 2009
0

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

This is what I am trying to do

java Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ash2401 is offline Offline
2 posts
since Sep 2009
Sep 25th, 2009
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
emnidhi is offline Offline
2 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: JSP and MySql connectivity
Next Thread in JSP Forum Timeline: how do i send text from one page to another using javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC