when i try to create some connection in java with JDCB Postgresql , i have some problem . I cant create connection succesfully .
here the code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package Testapp;
/**
*
* @author penguintengil
*/
import java.sql.*;
import javax.swing.JOptionPane;
public class Login {
public Connection conn=null;
public final String driver=”org.postgresql.Driver”; //drivernya postgre
public final String user=”root”; //username
public final String pass=”root”; //password
public final String url=”jdbc:postgresql://localhost/test”; //url postgrepublic void conn(){
try {
Class.forName(driver);
conn=DriverManager.getConnection(url,user,pass);
System.err.println(“Connection Success”);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,”Connection Failed”);
System.err.println(“Error: “+e);
}}
public static void main (String[]arg){
Login k = new Login();
k.conn();
}Statement createStatement() {
throw new UnsupportedOperationException(“Not yet implemented”);
}
}
Compile > Run
if you got an error like
Lets try to fix this
check configuration in /var/lib/pgsql/data/pg_hba.conf
put some
# TYPE DATABASE USER ADDRESS METHOD
# “local” is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with thelocal all all trust
host all all 127.0.0.1 255.255.255.255 trust
host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff trust
save
and then check /var/lib/pgsql/data/postgresql.conf
change
listen_addresses=’*’
restart service
#service postgresql restart
Finally , running program .
and connection will be succesfull 🙂
On windows with postgre 9.2 service not getting started for local domain and even after commenting local part and starting the service ,,My application is still giving the same error.
LikeLike
Same problem facing, if i edit the file you mentioned, postgresql is not starting. what is the problem?
LikeLike
can you paste your error here ?
LikeLike