user3983913
user3983913

Reputation:

JDBC connect with ProgreSQL

I'm trying to connect my ProgreSQL DB, which runs on my PC, with JDBC.

package postgres;
import java.sql.*;
import java.util.Properties;


public class SQLConnector {
String url = "jdbc:postgresql://localhost:5432/postgres";
Properties props = new Properties();
Connection con;

public SQLConnector() throws SQLException {
    props.setProperty("user", "postgres");
    props.setProperty("password", "admin");

    this.con = DriverManager.getConnection(url, props);
}
public boolean isOpen() throws SQLException {

    return con.isValid(5);

}
public static void main(String[] args)throws SQLException {
    SQLConnector sqldb = new SQLConnector();
    if (sqldb.isOpen()) {
        System.out.println("Connection successfully established.");
    }
}
}

I always get the following Exception:

Exception in thread "main" java.lang.AbstractMethodError: org.postgresql.jdbc3g.Jdbc3gConnection.isValid(I)Z
at postgres.SQLConnector.isOpen(SQLConnector.java:21)
at postgres.SQLConnector.main(SQLConnector.java:27)

The Driver is in Referenced Libraries of the project.

Would be happy about help.

Timon

Upvotes: 1

Views: 2593

Answers (1)

Adam111p
Adam111p

Reputation: 3727

Welcome Timon.

Unfortunately, "jdbc3" method "isValid" is not implemented.

I suggest you use the "jdbc4".

Upvotes: 2

Related Questions