0

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.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by emnidhi
0

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

0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.