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
  • 13

0 Answers0