Why can not I connect to PostgreSQL?

0

I'm very interested in programming but I'm new to the field and I need to deliver this work to the teacher. But I can not resolve this error.

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;    
        }
    }
}

This is the error:

  

May 22, 2017 10:19:47 PM org.postgresql.Driver connect GRAVE: Error in   url: jdbc: postgresql: // localhost: 5432 STOP CONSTRUCTION (total time:   3 minutes 23 seconds)

    
asked by anonymous 23.05.2017 / 03:23

1 answer

0

The name of the database is missing.

public static Connection getConnection() throws SQLException{
        try {
             Class.forName("com.mysql.jdbc.Driver");                             
             return DriverManager.getConnection("jdbc:mysql://xxx.xxx.xxx.xxx/mybd?user=eu&password=eu");                         
        } catch (ClassNotFoundException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());            
            throw new SQLException();            
        }        
    } 
}
    
24.05.2017 / 00:41