B4J Question Connectionpool Mysql

jayel

Active Member
Licensed User
Longtime User
Hello,

I do this :
B4X:
Private Sub GetMachineDetails(s_machnr As String) As MachineDetail
    Dim query As StringBuilder
    Dim mymachinedetail As MachineDetail
    mymachinedetail.Initialize
    query.Initialize
   
    query.Append("SELECT * FROM tblmachine WHERE MachNr = ?")
    SQLMachines = MachinesConnectionPool.GetConnection
    
    s_machnr = s_machnr.SubString(1)
   
    Dim rs As ResultSet
   
    rs = SQLMachines.ExecQuery2(query,Array(s_machnr))
    Do While rs.NextRow
       
        mymachinedetail.id = 0'rs.GetInt("idNummer")
        mymachinedetail.munt = rs.GetDouble("Munt")
        mymachinedetail.naam = rs.GetString("MachNaam")
        mymachinedetail.nr = rs.GetInt("MachNr")
        mymachinedetail.aantal = 0
        mymachinedetail.bedrag = 0     
       
    Loop
    rs.Close
   
   
    Return mymachinedetail
    SQLMachines.Close
   
End Sub


It goes well, but suddenly I get this error :
Error occurred on line: 78 (Main)
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:687)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at anywheresoftware.b4j.object.ConnectionPool.GetConnection(ConnectionPool.java:41)
at telmachine.robotonic.be.main._getmachinedetails(main.java:350)
at telmachine.robotonic.be.main._astream_newdata(main.java:287)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.sh
ell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:111)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:301)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMetho
dAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at telmachine.robotonic.be.main.main(main.java:29)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@41eaa2 -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1416)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0P
ooledConnectionPool.java:682)
... 30 more

Can somebody help me in the right direction to resolve this error?

Greets,

John
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Try to close SQL connection before exit the Sub (
B4X:
 Return mymachinedetail
)

Possibly
B4X:
SQLMachines.close
isn't executed as you exit the sub before with Return
 
Upvote 0
Top