Results 1 to 3 of 3
Thread: Property file can't be read
- 02-11-2011, 04:03 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Property file can't be read
I am facing an exception when i am trying to create a connection to database.I have all the database connection strings in the database.property file .Is there anything to change in my code
java.io.FileNotFoundException: database.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.jpmc.efs.tcrr.pillar.release2.JavaPoller.getCo nnection(JavaPoller.java:41)
at com.jpmc.efs.tcrr.pillar.release2.JavaPoller.main( JavaPoller.java:97).
Code:
public static Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in = new FileInputStream("database.properties");
props.load(in);
in.close();
Connection conn = null;
try
{
OracleDataSource ods = new OracleDataSource();
ods.setDriverType(props.getProperty("driver.type") );
ods.setServerName(props.getProperty("server.name") );
ods.setNetworkProtocol(props.getProperty("network. protocol"));
ods.setDatabaseName(props.getProperty("database.na me"));
ods.setPortNumber(Integer.parseInt(props.getProper ty("port.number")));
ods.setUser(props.getProperty("user.name"));
ods.setPassword(props.getProperty("password"));
conn = ods.getConnection();
}
catch(SQLException e)
{
e.printStackTrace();
}
return conn;
}
- 02-11-2011, 04:56 PM #2
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
Your database.properties file needs to be in the directory from which you're running the program, since you didn't specify any path information in the call to new FileInputStream(). If it's somewhere else, then either change the path you're passing in, or move the file to the current working directory.
- 02-11-2011, 05:49 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Property file cannot be read
By Tulsa in forum JDBCReplies: 3Last Post: 02-11-2011, 04:48 PM -
Load A Property File From Classpath?
By miko5054 in forum New To JavaReplies: 2Last Post: 06-29-2010, 12:06 PM -
Alternative of FileInputStream to read Property File
By SE123 in forum Java ServletReplies: 13Last Post: 09-16-2009, 01:05 PM -
File Property
By Juggler in forum New To JavaReplies: 0Last Post: 08-10-2008, 07:23 AM -
Property File
By Peter in forum JDBCReplies: 2Last Post: 07-04-2007, 03:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks