my.driver = oracle.jdbc.driver.OracleDriver
my.dburl = jdbc:oracle:thin:@localhost:1521:XE
my.dbuser = local
my.dbpwd = test
my.sql = select * from employee
import java.sql.*;
import java.util.*;
import java.io.*;
class PropertiesTest
{
public static void main(String[] args) throws Exception
{
//Locate text properties file
FileInputStream fis = new FileInputStream("myfile.properties");
//create an empty object of java.util.Properties class
Properties prop = new Properties();
//load the content of myfile.properties into java.util.Properties class
prop.load(fis);
//read value from java.util.Properties
String dname = prop.getProperty("my.driver");
String url = prop.getProperty("my.dburl");
String user = prop.getProperty("my.dbuser");
String pwd = prop.getProperty("my.dbpwd");
String qry = prop.getProperty("my.sql");
//create jdbc connection object
Class.forName(dname);
Connection con = DriverManager.getConnection(url, user, pwd);
//create statement object
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(qry);
System.out.println("Id Name");
System.out.println("-------------");
while (rs.next())
{
System.out.println(rs.getInt(1)+" "+
rs.getString(2));
}
System.out.println("-------------\n");
rs.close();
con.close();
st.close();
}
}