title: Java JDBC - No suitable Driver found
body: <p>I've got a problem with my code accessing a local database. I am using Eclipse and postgresql. </p>
  
  <p>I am well aware that there are already several posts like that but they didn't help me on my problem so that is why I am asking myself. </p>
  
  <p>The jar file for the drivers is already in the library and is also added to the Build Path. However I am still getting the error from the Driver not being found.</p>
  
  <blockquote>
    <p>Can't get a connection: java.sql.SQLException: No suitable driver found for psql -h localhost beleg postgres</p>
  </blockquote>
  
  <p>My code looks like this: </p>
  
  <pre><code>package DB;
  import java.sql.*;
  
  public class Connections {
  
  private Connection dbcon;
  private Statement stmt;
  private Statement stmt2;
  
  Connections(String db_url, String username, String password) {
      try {
          Class.forName("org.postgresql.Driver");
          dbcon = DriverManager.getConnection(db_url, username, password);
  
          stmt = dbcon.createStatement();
          stmt2 = dbcon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
          ResultSet.CONCUR_READ_ONLY);
      } catch (Exception e) {
          System.out.println("Can't get a connection: " + e.toString());
  
          try {
              if (stmt != null)
                  stmt.close();
          } catch (SQLException f) {
          }
  
          try {
              if (stmt2 != null)
                  stmt2.close();
          } catch (SQLException f) {
          }
          try {
              if (dbcon != null)
                  dbcon.close();
          } catch (SQLException f) {
          }
          System.exit(0);
      }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yPUXy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yPUXy.jpg" alt="added the JAR with Add Jar, since it is in the lib folder of the project.. "></a></p>