0
I’m very interested in programming but I’m new in the area and I need to give this work to the teacher. But I can’t solve this mistake.
package dal;
import java.sql.*;
import javax.swing.JOptionPane;
public class ConectaBd {
public static Connection conectabd() throws ClassNotFoundException, SQLException{
try{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432","postgres","123");
JOptionPane.showMessageDialog(null, "Conecxão bem sucedida !");
return con;
}
catch(SQLException error){
JOptionPane.showMessageDialog(null, "Não foi possível conectar !");
return null;
}
}
}
That is the mistake:
mai 22, 2017 10:19:47 pm org.postgresql.Driver connect GRAVE: Error in url: jdbc:postgresql://localhost:5432 HALTED CONSTRUCTION (total time: 3 minutes 23 seconds)
Apparently the database name is missing from the connection url
jdbc:postgresql://localhost:5432/suaDataBase
ingetConnection
– brow-joe
the user @Brow-joe is correct, https://jdbc.postgresql.org/documentation/80/connect.html
– David Schrammel