title: reading dbConnection.properties file in java to connect to database using eclipse
body: <p>I have create a dbConnection.properties file and placed it into WEB-INF. To read that file and connect to database I hava written a class as</p>
  
  <pre><code>public class DbConnection {
  
  public static Connection connection()
  {
      Connection con=null;
      //String connectionURL = "jdbc:mysql://localhost:3306/demo";
      try
      {
          Properties prop=new Properties();
          FileInputStream in = new FileInputStream(System.getProperty("WEB-INF/dbConnection.properties"));
          prop.load(in);
          in.close();
  
          String drivers = prop.getProperty("jdbc.drivers");
          String connectionURL = prop.getProperty("jdbc.url");
          String username = prop.getProperty("jdbc.username");
          String password = prop.getProperty("jdbc.password");
  
          //Class.forName("com.mysql.jdbc.Driver").newInstance();
          Class.forName(drivers);
          con=DriverManager.getConnection(connectionURL,username,password);
  
              System.out.println("Connection Successful");
              return con;     
      }
      catch(Exception e)
      {
          System.out.println("error !!");
      }
      return null;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Its going into catch block. How can i read .properties file?</p>