Results 1 to 4 of 4
  1. #1
    Tulsa is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default 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;
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    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?

  3. #3
    Tulsa is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    database.property is the property file where i have defined all the connection strings of the databse such as server name, driver type ..etc ...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Which didn't answer my question.

    Where is the file in relation to the rest of your code?

Similar Threads

  1. Load A Property File From Classpath?
    By miko5054 in forum New To Java
    Replies: 2
    Last Post: 06-29-2010, 01:06 PM
  2. Replies: 13
    Last Post: 09-16-2009, 02:05 PM
  3. File Property
    By Juggler in forum New To Java
    Replies: 0
    Last Post: 08-10-2008, 08:23 AM
  4. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 11:16 AM
  5. Property File
    By Peter in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 04:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •