I do not know what happens

208 views
Skip to first unread message

Miguel Angel Hernandez vergara

unread,
Nov 16, 2014, 7:05:06 PM11/16/14
to hika...@googlegroups.com
I'm making a connection to the database without connecting to postgresql
this is my code:
try {
           
Properties mConnect = new Properties();
            mConnect
.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
            mConnect
.setProperty("dataSource.ServerName", H);
            mConnect
.setProperty("dataSource.PortNumber", "3306");
            mConnect
.setProperty("maximumPoolSize", "100");
            mConnect
.setProperty("dataSource.databaseName", D);
            mConnect
.setProperty("dataSource.user", U);
            mConnect
.setProperty("dataSource.password", C);
           
HikariConfig pConnect = new HikariConfig(mConnect);
           
this.xConnect = new HikariDataSource(pConnect);

           
if(this.xConnect == null)
               
System.out.println("Connection failed!");
           
else
               
System.out.println("Database connected!");
       
}
       
catch (Exception e) {
            e
.printStackTrace();
       
}

Sorry for my english, i'm spanish.

Brett Wooldridge

unread,
Nov 16, 2014, 7:24:41 PM11/16/14
to hika...@googlegroups.com
Make sure you are using the latest HikariCP (2.2.5).  If HikariCP cannot create an initial connection, it will throw a RuntimeException from the HikariDataSource constructor.  This exception will wrap the SQLException thrown by PostgreSQL to let you know why it failed.

If the initial connection succeeds, but you get exceptions later in getConnection(), check that your PostgreSQL configuration supports the 100 connections that you specified as maximumPoolSize.

The rest of your configuration looks correct to me.

-Brett

Robstar

unread,
Nov 22, 2014, 3:14:47 PM11/22/14
to hika...@googlegroups.com
[main] WARN com.zaxxer.hikari.HikariConfig - The jdbcConnectionTest property is now deprecated, see the documentation for connectionTestQuery
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariCP pool HikariPool-0 is starting.

Make sure the firewall is enabled.  Attempting connection in 5 seconds...

Now attempting getConnection(), expecting a timeout...
[main] INFO com.zaxxer.hikari.pool.HikariPool - HikariCP pool HikariPool-0 is shutting down.


I do not understand much English, sorry.

Brett Wooldridge

unread,
Nov 22, 2014, 11:19:51 PM11/22/14
to hika...@googlegroups.com
Use HikariCP 2.2.5, try:

try {
   HikariConfig pConnect = new HikariConfig();
   
pConnect.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
   pConnect.setUsername(U);
   pConnect
.setPassword(C);
   pConnect.setMaximumPoolSize(100);
   pConnect.setConnectionTestQuery("SELECT 1");
   pConnect.addDataSourceProperty("serverName", H);
   pConnect.addDataSourceProperty("portNumber", "3306");
   pConnect.addDataSourceProperty("databaseName", D);
   HikariDataSource ds = new HikariDataSource(pConnect);

   Connection conn = ds.getConnection();
}
catch (Exception e) {
   e.printStackTrace();
}
Reply all
Reply to author
Forward
0 new messages