B4J Question How do I connect to SQL Server using OLE DB

npsonic

Active Member
Licensed User
The title says it all. I have trying to find ways to connect SQL server using OLE DB. It seems that there isn't many ways to achieve this kind of connection.
There is JACOB, but it seems kind of complicated and I'm not sure how to use it in B4J.

Any help is appreciated.
 

OliverA

Expert
Licensed User
Longtime User
Which SQL Server? MSSQL? PostgreSQL? etc...
 
Upvote 0

npsonic

Active Member
Licensed User
Which SQL Server? MSSQL? PostgreSQL? etc...
MSSQL

Other possibility would be to use some other language like C++ or C# to create app that creates connection to the SQL server.
Then use B4J to control this other app.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

npsonic

Active Member
Licensed User
Why not use B4J's jSQL and the jTDS JDBC driver?
I have connection string that contains Provider, Data source name and Data source.

Example: Provider=<Some Provider>;Catalog=<Name of the data source>;Data Source=<Some data source>

I would want to create connection using this kind of string. Is it possible by using B4J's jSQL?
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Looking at these sources:
https://docs.microsoft.com/en-us/sq...ta-source-sql-server-import-and-export-wizard
https://docs.microsoft.com/en-us/sq...nd-connection-strings-report-builder-and-ssrs

Provider = JDBC/JTDS
Data Source = IP Address/Hostname + Port Number of MSSQL Server
Catalog = database name

Then yes, all doable.

Examples of URL setup (from this post at stackoverflow):

So, to connect to a database called "Blog" hosted by a MS SQL Server running on MYPC, you may end up with something like this:

jdbc:jtds:sqlserver://MYPC:1433/Blog;instance=SQLEXPRESS;user=sa;password=s3cr3t
 
Upvote 0

miker2069

Active Member
Licensed User
Longtime User
To connect to MS SQL Server I use something like...

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
    #AdditionalJar: sqljdbc42.jar
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private sql1 As SQL
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    Dim url As String
    Dim mariadb_url As String
  
    url = "jdbc:sqlserver://LENOVO\SQLEXPRESS;database=NORTHWND;user=sa;password=secretpassword"
    sql1.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver",url)
  
  
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…