954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

load database info in a JSP using a config file

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.

ash2401
Newbie Poster
2 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Check the Read Me post at the top of the jsp forum:
JSP database connectivity according to Model View Controller (MVC) Model 2

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This is what I am trying to do

Properties properties = new Properties();
		try {
			properties.load(new FileInputStream("database.properties"));
		      } catch (IOException e) 
			 {
			 System.err.println(e.getMessage());
			 }


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).

ash2401
Newbie Poster
2 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

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.

emnidhi
Newbie Poster
2 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You