Search code examples
javaswinghibernateswingworker

GenericJDBCException: Cannot open connection ** Performance Metrics Report **


I have the following

javax.swing.Timer timer = new javax.swing.Timer(3000, new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        jLabelMsgL.setText("");
        NitgenSwingWorker sWorker = new NitgenSwingWorker();
        sWorker.execute();
    }
});
timer.start();

private final class NitgenSwingWorker extends SwingWorker<Boolean, Void> {
    @Override
    protected Boolean doInBackground() throws Exception {
        return nitgen.checkFinger();
    }

    @Override
    protected void done() {
        try {
            Boolean isCheckFinger = get();
            if(isCheckFinger){
                delegate.getListaByIdEmpleado(123);
            }else{
                delegate.getListaByIdEmpleado(123);
            }
        } catch (InterruptedException | ExecutionException e) {
            System.err.println("NitgenSwingWorker Error: " + e.getMessage());
        }
    }
}

but when 'isCheckFinger' is true, throws

Mon Jun 29 10:44:14 CDT 2015 INFO: ** Performance Metrics Report **

Longest reported query: 0 ms
Shortest reported query: 9223372036854775807 ms
Average query execution time: NaN ms
Number of statements executed: 0
Number of result sets created: 0
Number of statements prepared: 0
Number of prepared statement executions: 0
Mon Jun 29 10:44:14 CDT 2015 TRACE: send() packet payload:
0a 00 00 00 03 73 65 6c     . . . . . s e l 
65 63 74 20 31 3b           e c t . 1 ; 

org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
...

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
...

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
...

only send me the error when nitgen.checkFinger returns true, nitgen is a library of a fingerprint reader. I guess when this return true, it changes something in swing and can not access hibernate. The exception is sent until it try to do this:

getSession().beginTransaction()

Otherwise no problems, anyone can help me?


Solution

  • I solved The problem was that I was using a JNI library, and when a value is changed, this happened. To fix and change the default value and ready solved.

    public boolean checkFinger() throws Exception {
        //Boolean thereIsFinger = Boolean.FALSE; //original line
        Boolean thereIsFinger = Boolean.TRUE;   //solution
        //bsp is a JNI Library 
        bsp.CheckFinger(thereIsFinger);
        return thereIsFinger;
    }