B4J Question Connection pool, I am on the right ways?

yfleury

Active Member
Licensed User
Longtime User
I am not very familar whit connection pool. I just want to know if my understand is good. So, I copy a class module server handler.
web server B4J:
'Handler class
Sub Class_Globals
    Private mysql1 As SQL
    Private Pool1 As ConnectionPool
End Sub

Public Sub Initialize
    Pool1.Initialize("com.mysql.cj.jdbc.Driver","jdbc:mysql://localhost:3308/rappeltravail?characterEncoding=utf8&useTimezone=true&serverTimezone=America/New_York","user","password")
    mysql1=Pool1.GetConnection
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)

' do something 
' acces to database
'send result to servletRasponse by resp
'job done, close the pool
    Pool1.ClosePool
End Sub

Is it a correct approach for connection pool?
I have many class module server handler. Is it good for these class?
 
Solution
hi!
Is it a correct approach
no!

for connection pool:
1. dim it in Global variables in main
2. initialize on appstart
3. everytime you want to use the pool call getConnection
3. close everytime the created connection

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
dim sql as sql = main.pool.getconnection
try
...
catch
log("lol")
end try
sql.close
end sub

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
hi!
Is it a correct approach
no!

for connection pool:
1. dim it in Global variables in main
2. initialize on appstart
3. everytime you want to use the pool call getConnection
3. close everytime the created connection

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
dim sql as sql = main.pool.getconnection
try
...
catch
log("lol")
end try
sql.close
end sub
 
Upvote 1
Solution
Top