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

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

  2. #2
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    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.

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

Similar Threads

  1. Property file cannot be read
    By Tulsa in forum JDBC
    Replies: 3
    Last Post: 02-11-2011, 05:48 PM
  2. Load A Property File From Classpath?
    By miko5054 in forum New To Java
    Replies: 2
    Last Post: 06-29-2010, 01:06 PM
  3. Replies: 13
    Last Post: 09-16-2009, 02:05 PM
  4. File Property
    By Juggler in forum New To Java
    Replies: 0
    Last Post: 08-10-2008, 08:23 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
  •