I have a simple Java application that needs to connect to a PostgresSQL running on local host. The DB is up and running, and I can connect to it using the username and password using the psql command line utility. Here's the code:
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(DbLoader.class.getName()).log(Level.SEVERE, null, ex);
}
try (
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/db",
"user",
"pass");
){
// PROBLEM: con is null at this point
} catch ( SQLException sqex ) {
sqex.printStackTrace( System.out );
}
Using Mac OS X.8.3. There is no exception thrown.
Here is the output of pg_config:
BINDIR = /Applications/Postgres.app/Contents/MacOS/bin
DOCDIR = /Applications/Postgres.app/Contents/MacOS/share/doc
HTMLDIR = /Applications/Postgres.app/Contents/MacOS/share/doc
INCLUDEDIR = /Applications/Postgres.app/Contents/MacOS/include
PKGINCLUDEDIR = /Applications/Postgres.app/Contents/MacOS/include
INCLUDEDIR-SERVER = /Applications/Postgres.app/Contents/MacOS/include/server
LIBDIR = /Applications/Postgres.app/Contents/MacOS/lib
PKGLIBDIR = /Applications/Postgres.app/Contents/MacOS/lib
LOCALEDIR = /Applications/Postgres.app/Contents/MacOS/share/locale
MANDIR = /Applications/Postgres.app/Contents/MacOS/share/man
SHAREDIR = /Applications/Postgres.app/Contents/MacOS/share
SYSCONFDIR = /Applications/Postgres.app/Contents/MacOS/etc
PGXS = /Applications/Postgres.app/Contents/MacOS/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/Users/mattt/Code/heroku/PostgresApp/Postgres/Vendor/postgres' '--enable-thread-safety' '--without-docdir' '--with-openssl' '--with-gssapi' '--with-bonjour' '--with-krb5' '--with-libxml' '--with-libxslt' '--with-perl' '--with-python'
CC = gcc
CPPFLAGS = -I/usr/include/libxml2
CFLAGS = -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif- labels -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL =
LDFLAGS = -Wl,-dead_strip_dylibs
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm
VERSION = PostgreSQL 9.1.4
Any ideas? Thanks in advance
try { ... } catch(Exception e){ e.printStackTrace(); }
– Barranka May 17 '13 at 20:08jdbc:postgresql://localhost/db
needs it. – Luiggi Mendoza May 17 '13 at 20:11