Am getting below exception while connecting to postgresql,
INFO: HHH000046: Connection properties: {user=postgres, password=****}
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:214)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
at org.sri.hibernate.main.MainClass.main(MainClass.java:16)
Here is my hibernate.cfg.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">"jdbc:postgresql://localhost:5432/TestDataBase</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<mapping class="org.sri.hibernate.beans.UserDetails"/>
</session-factory>
</hibernate-configuration>
My connection URL, user Name and password are correct. Am trying to connect by using,
public static void main(String args[])
{
SessionFactory sf=new Configuration().configure().buildSessionFactory();
Session ss=sf.openSession();
Transaction tran=null;
UserDetails det= new UserDetails();
det.setDateOfBirth(new Date());
det.setUserName("SomeName");
try
{
tran=ss.beginTransaction();
ss.save(det);
tran.commit();
ss.close();
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
I use the same code to connect Oracle DB ( after changing the properties in xml ) it works fine, am I missing something specific to postgres ? Please help
"jdbc:postgresql://localhost:5432/TestDataBase
. It has a leading double quote that shouldn't be there. – JB Nizet Jun 1 at 12:12