hi everyone !
I'm using MySql Connector , but when the server stays running for some time, it gets this error :
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out
how can i fix it ?
this is the code [DB_Class_Module]:
I'm using MySql Connector , but when the server stays running for some time, it gets this error :
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out
how can i fix it ?
this is the code [DB_Class_Module]:
B4X:
Sub Process_Globals
Public pool As ConnectionPool
End Sub
Public Sub Initialize
pool.Initialize("com.mysql.jdbc.Driver","jdbc:mysql://localhost/kadyi?characterEncoding=utf8","root","")
End Sub
Public Sub Sync
Dim sql1 As SQL = pool.GetConnection
Dim rs As ResultSet = sql1.ExecQuery("SELECT * FROM usuario")
End Sub
Public Sub CheckLogin(user As String,pass As String) As String
Dim sql1 As SQL = pool.GetConnection
Dim rs As ResultSet = sql1.ExecQuery("SELECT * FROM usuario WHERE email = '"&user&"' AND senha = '"&pass&"'")
If rs.NextRow Then
Log(rs.GetString2(0))
If (rs.GetString2(0) <> "") Then
Log("Usuario Logado !")
Return "Success:"&rs.GetString2(0)&":"&rs.GetString2(1)&":"&rs.GetString2(5)
Else
Log("Detalhes incorretos ...")
Return "Error"
End If
End If
rs.Close
Return "Error"
End Sub
Public Sub ListCidades() As String
Dim sql1 As SQL = pool.GetConnection
Dim rs As ResultSet = sql1.ExecQuery("SELECT * FROM cidades")
Do While rs.NextRow Then
Log(rs.GetString2(0))
If (rs.GetString2(0) <> "") Then
Log("Usuario Logado !")
Return "Success:"&rs.GetString2(0)&":"&rs.GetString2(1)&":"&rs.GetString2(5)
Else
Log("Detalhes incorretos ...")
Return "Error"
End If
Loop
rs.Close
Return "Error"
End Sub
Public Sub ListpClinicas(cidade As String,estado As String) As String
Dim sql1 As SQL = pool.GetConnection
Dim rs As ResultSet = sql1.ExecQuery("SELECT * FROM clinicas WHERE premium = 1 AND cidade = '"&cidade&"' AND estado = '"&estado&"' ORDER BY RAND() LIMIT 50;")
Dim RowCount As Int = 0
Dim Clista As String = ""
Dim Resto As Int = 0
Do While rs.NextRow Then
RowCount = RowCount + 1
If (rs.GetString2(0) <> "") Then
Clista = Clista & rs.GetString2(0)&":"&rs.GetString2(1)&":"&rs.GetString2(5)&","
End If
Loop
If (RowCount < 50) Then
Resto = 50 - RowCount
Dim rs2 As ResultSet = sql1.ExecQuery("SELECT * FROM clinicas WHERE premium = 0 AND cidade = '"&cidade&"' AND estado = '"&estado&"' ORDER BY RAND() LIMIT "&Resto&";")
Do While rs2.NextRow Then
RowCount = RowCount + 1
If (rs2.GetString2(0) <> "") Then
Clista = Clista & rs2.GetString2(0)&":"&rs2.GetString2(1)&":"&rs2.GetString2(3)&":"&rs2.GetString2(4)&":"&rs2.GetString2(5)&","
End If
Loop
End If
If (RowCount > 0) Then
Return "Success:"&RowCount&":"&Clista
Else
Return "NoClinicas"
End If
rs.Close
Return "Error"
End Sub