0

I have this code. It does not work because it says "No suitable driver found for ..." I need to find the database url. How can I find it? What do I need to change so my code gets connected to database and work?...

  import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.SQLException;

       /**
    *
    * @author postgresqltutorial.com
   */
     public class InsertApp{

private final String url = "jdbc:postgresql://host:5432/lejdiprifti";
private final String user = "postgres";
private final String password = "<add your password>";

/**
 * Connect to the PostgreSQL database
 *
 * @return a Connection object
 */
public Connection connect() {
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(url, user, password);
        System.out.println("Connected to the PostgreSQL server successfully.");
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }

    return conn;
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    InsertApp app = new InsertApp();
    app.connect();
}
 }
Lejdi Prifti
  • 29
  • 1
  • 12
  • 1
    not the url but the jdbc driver https://mvnrepository.com/artifact/postgresql/postgresql/9.1-901-1.jdbc4 add the jar to your library of use maven dependency – YCF_L Jul 20 '18 at 21:40
  • so what should i do with that – Lejdi Prifti Jul 20 '18 at 21:42
  • C'mon please helppp – Lejdi Prifti Jul 20 '18 at 21:43
  • So, are you sure the proper Postgres JDBC jar is in your classpath? And you're still getting the error? – fvu Jul 20 '18 at 21:48
  • i added this org.eclipse.datatools.enablement.postgresql_1.1.1.v201205252207 – Lejdi Prifti Jul 20 '18 at 21:51
  • I added it in java build path. Is it right? – Lejdi Prifti Jul 20 '18 at 21:52
  • 1
    No, and no: 1- YCF_L gave you the download link for the JDBC jar (whatever that thing you mention is, it's **not** a Postgres JDBC driver and 2 - it needs to be in the classpath at **runtime**. You could read https://stackoverflow.com/questions/219585/including-all-the-jars-in-a-directory-within-the-java-classpath – fvu Jul 20 '18 at 22:05

0 Answers0