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.

Recommended Answers

All 3 Replies

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.