estou tendo a seguinte exception quando tento conectar em em banco de dados postgresql:
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:204)
at org.postgresql.Driver.connect(Driver.java:139)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at db_test.main(db_test.java:20)
o codigo eh o seguinte:
import java.sql.*;
public class db_test {
public static void main(String[] args) {
String url = "jdbc:postgresql://localhost:5432/teste?user=carlos&password=carlos";
Connection con = null;
try {
Class.forName("org.postgresql.Driver");
}
catch( Exception e ) {
e.printStackTrace();
return;
}
try {
con = DriverManager.getConnection(url);
}
catch( SQLException e ) {
e.printStackTrace();
}
finally {
if( con != null ) {
try { con.close(); }
catch( SQLException e ) {
e.printStackTrace();
}
}
}
}
}
