[ start | index | login ]
start > knowledgebase > linux > java > accessing postgres via jdbc

accessing postgres via jdbc

Created by retep. Last edited by retep, 3 years and 5 days ago. Viewed 2,442 times. #1
[edit] [rdf]
labels
attachments
In /var/lib/pgsql/data/postgresql.conf set: tcpip_socket = true

This permits access to postgresql using sockets rather than Linux socket files.

In /var/lib/pgsql/data/pg_hba.conf, uncomment: host all all 127.0.0.1 255.255.255.255 trust

This allows clients on the server to connect to the postgresql server.

The postgresql connection url is decribed at: >>http://www.postgresql.org/docs/7.4/static/jdbc-use.html#JDBC-CONNECT.

For example: jdbc:postgresql://host:port/database (host defaults to localhost, port defaults to 5432).

A quick bit of code to test your connectivity would be something like:

Class.forName("org.postgresql.Driver");
Connection c = DriverManager.getConnection("jdbc:postgresql:dbname", "username", "password"); 
System.out.println("Connected OK");    
c.close();
请以发表评论身份登录
Powered by snipsnap.org Found a mistake in a howto? Let us know via an email to p.blikibugs at rimuhosting com.