B4J Code Snippet jtds jdbc driver with standalone package

1. Download the attached zip. Put the jar file in the additional libraries folder and Charsets.properties in your project folder.
2. jtds-1.3.1-a.jar replaces jtds-1.3.1.jar.
B4X:
#AdditionalJar: jtds-1.3.1-a
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ Charsets.properties

Full example:
B4X:
#AdditionalJar: jtds-1.3.1-a
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ Charsets.properties
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim sql As SQL
    sql.Initialize("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://localhost:1433/test;instance=SQLEXPRESS;?user=test&password=test")
    For i = 1 To 10
        sql.AddNonQueryToBatch("INSERT INTO table1 VALUES(?, ?)", Array(i.As(String), i))
    Next
    Dim SenderFilter As Object = sql.ExecNonQueryBatch("SQL")
    Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
    Log("NonQuery: " & Success)
End Sub

If you get an error such as: "SSO Failed: Native SSPI library not loaded" then you should download the package: https://sourceforge.net/projects/jtds/files/latest/download
Copy x64\sso\ntlmauth.dll to Windows\System32.
 

Attachments

  • jtds-1.3.1-a.zip
    301.5 KB · Views: 525

Johan Schoeman

Expert
Licensed User
Longtime User
1. Download the attached zip. Put the jar file in the additional libraries folder and Charsets.properties in your project folder.
2. jtds-1.3.1-a.jar replaces jtds-1.3.1.jar.
B4X:
#AdditionalJar: jtds-1.3.1-a
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ Charsets.properties

Full example:
B4X:
#AdditionalJar: jtds-1.3.1-a
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ Charsets.properties
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim sql As SQL
    sql.Initialize("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://localhost:1433/test;instance=SQLEXPRESS;?user=test&password=test")
    For i = 1 To 10
        sql.AddNonQueryToBatch("INSERT INTO table1 VALUES(?, ?)", Array(i.As(String), i))
    Next
    Dim SenderFilter As Object = sql.ExecNonQueryBatch("SQL")
    Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
    Log("NonQuery: " & Success)
End Sub

If you get an error such as: "SSO Failed: Native SSPI library not loaded" then you should download the package: https://sourceforge.net/projects/jtds/files/latest/download
Copy x64\sso\ntlmauth.dll to Windows\System32.
What can I say......picture perfect! Thanks Erel - it is working 100%
 

Johan Schoeman

Expert
Licensed User
Longtime User
BTW, why do you prefer jtds over Microsoft JDBC driver?
Erel, in all honesty - just because I am a dummy at networking and I knew you would find a solution. I am now also using jtds on my mobile device to connect to the MSSQL server and can query and assemble some nice reports - needed to connect to the server making use of Forticlient that I installed on my mobile. Thanks for your kind assistance - much appreciated.

Rgds

JS
 
Top