B4J Tutorial SQL Tutorial

sorex

Expert
Licensed User
Longtime User
Does anyone know what the driver name is for MS's original MSSQL JDB driver?
 

sorex

Expert
Licensed User
Longtime User
this is working

B4X:
#AdditionalJar: sqljdbc4.jar

B4X:
sql1.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://sqlserver:1433;databaseName=intranet;user=xxx;password=xxx;")

sqljdbc.jar doesn't work on java 1.8

you can download sqljdbc_4.0.2206.100_enu.tar.gz which doesn't require an install from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

extract it or browse with Total Commander and copy the file sqljdbc_4.0\enu\sqljdbc4.jar to you additional libraries folder.
 

sorex

Expert
Licensed User
Longtime User
thanks for the hint, @Erel.

that one seems to be up to 4 times faster than the one from Microsoft in some cases.
 

sorex

Expert
Licensed User
Longtime User
it seems that I was too quick with my results.

when I ran it in release mode I got errors that the resultset was not initialized.

I had both MSSQL & JTDS as additional JAR in my project.

When I remove the MSSQL one it doesn't work in debug mode either.

Funny thing is that when I make a typo in the driver class name (net.sourceforge.jtds.jdbc.Driver) its not working either so my guess is it tried to use the right one anyway.

Is there an error that I can display that might show more info about the connect failure?
 

sorex

Expert
Licensed User
Longtime User
ok, I missed the JTDS part in the connection string which is apparently needed. Strange that it worked without when the MSSQL lib was added.

B4X:
sql1.Initialize("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://servername:1433/databasename;user=xxx;password=xxx")
 

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
Is it a good practice, when we have a thread pool of connections, to do the following(?):
B4X:
If Not(SQL.IsInitialized) Then SQL = Pool.GetConnection
Thank you in advance!
 

Croïd

Active Member
Licensed User
Longtime User
Thanks Erel

It is a base of a service provider. With B4A application you can connect

Is it different between B4A and b4j ?
 

Croïd

Active Member
Licensed User
Longtime User
Yes with " lib: MSMySql no SQL

B4X:
Dim db As MySQL
------
db.Initialize("MySQL","sqlx.freemysql.net","sqluser","sqlpassw","sqluser")
db.QueryASync("SELECT * FROM Table;","")
db.CloseDatabase

sample express write db
 
Last edited:

Croïd

Active Member
Licensed User
Longtime User
Because if I take the first post : Error: (UnknownHostException) java.net.UnknownHostException: sql7.freemysqlhosting.net;user=sqluser;password=passw

B4X:
#AdditionalJar: mysql-connector-java-5.1.39-bin.jar
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…