Results 1 to 4 of 4
Thread: Property file cannot be read
- 02-10-2011, 04:20 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Property file cannot be read
I am facing an exception when i am trying to create a connection to database.
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, 06:39 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Not that this has a great deal to do with databases, but Java can't find that file.
Where is that file in relation to the rest of your code?
- 02-11-2011, 04:00 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
database.property is the property file where i have defined all the connection strings of the databse such as server name, driver type ..etc ...
- 02-11-2011, 04:48 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
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 -
How to store property file into key value pair
By Java Tip in forum java.utilReplies: 0Last Post: 04-05-2008, 10:16 AM -
Property File
By Peter in forum JDBCReplies: 2Last Post: 07-04-2007, 03:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks