B4J Question Abmaterial

spiroskaras

Member
Licensed User
Longtime User
Can i connect to MSSQL database to execute transactions with Abmaterial framework.(like DBM.InitializeMySQL for mysql)
 
First, find on the web and download the mssql jdbc driver (e.g mssql-jdbc-8.2.2.jre11.jar).
Put it in the B4J Additional Libraries folder.

In your program's main module, add:

#AdditionalJar:mssql-jdbc-8.2.2.jre11.jar

Then, you can initialize the connection to MSSQL by calling the Sub below (modify the IP, port and databaseName, per your setup):

B4X: Copy
Sub InitializeSQLServer(login As String, password As String, poolSize As Int)
'    Log("init SQL Server")
    UsePool = True
 
    Try
       pool.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://xxx.xxx.xxx.xxx:1433;databaseName=xxxxxxx", login, password)
    Catch
       Log("Last Pool Init Except: "&LastException.Message)
    End Try

   ' change pool size...
    Dim jo As JavaObject = pool
    jo.RunMethod("setMaxPoolSize", Array(poolSize))
End Sub

Hint: To work with your database, you can use AlwaysBusy's excellent DBM module from the ABMFeedback (included in the ABMaterial package). Just add the above Sub in the DBM module.
 
Last edited:
Upvote 0
Same for MariaDB:
Code: Copy
Sub InitializeMariaDB(jdbcUrl As String ,login As String, password As String, poolSize As Int) 'ignore
    Log("init mariadb")
    UsePool = True
    Try
       pool.Initialize("org.mariadb.jdbc.Driver", jdbcUrl, login, password)
    Catch
       Log("Last Pool Init Except: "&LastException.Message)
    End Try

   ' change pool size...
    Dim jo As JavaObject = pool
    jo.RunMethod("setMaxPoolSize", Array(poolSize))   
End Sub

But how to recompile DBM.bas? I can't override this static module: error ABM 2 times used in my own project. I am using it within a ABMaterial lite project.
 
Upvote 0
Back
Top