Connection error between Java and postgresql

Asked

Viewed 752 times

0

I’m trying to make a graphical Java interface connect with a database, so I’m using Netbenas and Postegresql. I created a table in Postegresql. I downloaded the postgresql-9.4.1208.jre6. jar and added it to the project. I have two Classes one of the connection and the other of the Form, but when I try to connect leaves this message:

Java.sql.SQLExeption: No suitable driver found for jdbc:postgresql://localhost:5432

Does anyone know what that means ? OBS : As a test I did the interface in the Netbeans editor. Follows the classes:

    package Visual;
import java.sql.*;
import Dal.ConectaBd;
import java.util.logging.Level;
import java.util.logging.Logger;
public class frmlogin extends javax.swing.JFrame {

    Connection con=null;
    PreparedStatement pst=null;
    ResultSet rs = null;
    public frmlogin() throws ClassNotFoundException {
        initComponents();
        this.setLocationRelativeTo(null);
        con=ConectaBd.Conectabd();
    }
    public static void main(String args[]) {
 /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new frmlogin().setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(frmlogin.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

Second class :

package Dal;
import java.sql.*;
import javax.swing.JOptionPane;
public class ConectaBd {
    public static Connection Conectabd() throws ClassNotFoundException {

        try {
          // conecta com o banco
            Class.forName("org.postgresql.Driver");
            Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432","postgres","");
            JOptionPane.showMessageDialog(null, "Conectado com sucesso");
            return con;
        }catch(SQLException erro){
            JOptionPane.showMessageDialog(null, erro);
            return null;
        } 

    }
}  
  • 1

    Are you sure you added the drive jar to the classpath? Check again.

  • hi Renam usually when we downloaded psql it has a menu that requests the installation of drivers this happened to vc.

  • Check that the drive is in your application postgresl is installed on the same machine as the application? Is the password really blank? Firewall enabled?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.