B4J Question [SOLVED] Jrdc2 example error

makis_best

Well-Known Member
Licensed User
Longtime User
Hi

I try to make a connection with one MSSql Server
The Server run on a local network and I try to connect using my client computer.
When I run the Jrdc example I get the error
B4X:
Waiting for debugger to connect...
Program started.
2019-06-19 11:30:46.802:INFO::main: Logging initialized @597ms to org.eclipse.jetty.util.log.StdErrLog
Ιουν 19, 2019 11:30:46 ΠΜ com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
Ιουν 19, 2019 11:30:47 ΠΜ com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2019-06-19 11:30:47.619:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 1.8.0_172-b11
2019-06-19 11:30:47.673:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2019-06-19 11:30:47.673:INFO:oejs.session:main: No SessionScavenger set, using defaults
2019-06-19 11:30:47.677:INFO:oejs.session:main: node0 Scavenging every 660000ms
2019-06-19 11:30:47.684:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@e720b71{/,file:///C:/Users/malagrakism.LOGIOS/Desktop/jRDC2/jRDC/Objects/www,AVAILABLE}
2019-06-19 11:30:47.690:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\Users\malagrakism.LOGIOS\Desktop\jRDC2\jRDC\Objects\logs\b4j-2019_06_19.request.log
2019-06-19 11:30:47.714:INFO:oejs.AbstractConnector:main: Started ServerConnector@2a70a3d8{HTTP/1.1,[http/1.1]}{0.0.0.0:17178}
2019-06-19 11:30:47.714:INFO:oejs.Server:main: Started @1511ms
Emulated network latency: 100ms
jRDC is running (version = 2.22)

My jrdc example is modified like this
B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

'change based on the jdbc jar file
'#AdditionalJar: mysql-connector-java-5.1.27-bin
'#AdditionalJar: postgresql-9.4.1207
#AdditionalJar: sqljdbc42.jar

Sub Process_Globals
    Public srvr As Server
    Public rdcConnector1 As RDCConnector
    Public const VERSION As Float = 2.22
    Type DBCommand (Name As String, Parameters() As Object)
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
End Sub

Sub AppStart (Args() As String)
    srvr.Initialize("")
    rdcConnector1.Initialize
    srvr.Port = rdcConnector1.serverPort
    srvr.AddHandler("/test", "TestHandler", False)
    srvr.AddHandler("/rdc", "RDCHandler", False)
    srvr.Start
    Log($"jRDC is running (version = $1.2{VERSION})"$)
    StartMessageLoop
End Sub

And my config.properties is like
B4X:
#DATABASE CONFIGURATION
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://server:1443/MainDB
User=sa
Password=password1
#Java server port
ServerPort=17178
 

jimmyF

Active Member
Licensed User
Longtime User
jRDC is running (version = 2.22)
Unless I am totally blind, I don't see an error.
It appears to be running.
What is NOT happening?
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
What is the ip address of "server" where your sqlserver is running?
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
192.168.1.2
I try inserting it but I get the same result
JdbcUrl=jdbc:jtds:sqlserver://192.168.1.2:1443/MainDB
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
Does your sqlserver allow remote access?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The jRDC2 logging on the console should give you more information. The underlying JDBC connection pooling used (3CP0) should spit out an error message that can help in further diagnosing this issue (if necessary, run the jRDC2 server in debug mode).
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Open up your jRDC2 source code via the B4J IDE and run the code in Debug Mode. Your initial log entries in the Logs tab will be as you show in your first post
Waiting for debugger to connect...
Program started.

2019-06-19 11:30:46.802:INFO::main: Logging initialized @597ms to org.eclipse.jetty.util.log.StdErrLog
Ιουν
19, 2019 11:30:46 Ξ Ξœ com.mchange.v2.log.MLog
INFO: MLog clients using java
1.4+ standard logging.
Ιουν
19, 2019 11:30:47 Ξ Ξœ com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-
0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2019-06-19 11:30:47.619:INFO:eek:ejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 1.8.0_172-b11
2019-06-19 11:30:47.673:INFO:eek:ejs.session:main: DefaultSessionIdManager workerName=node0
2019-06-19 11:30:47.673:INFO:eek:ejs.session:main: No SessionScavenger set, using defaults
2019-06-19 11:30:47.677:INFO:eek:ejs.session:main: node0 Scavenging every 660000ms
2019-06-19 11:30:47.684:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@e720b71{/,file:///C:/Users/malagrakism.LOGIOS/Desktop/jRDC2/jRDC/Objects/www,AVAILABLE}
2019-06-19 11:30:47.690:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened C:\Users\malagrakism.LOGIOS\Desktop\jRDC2\jRDC\Objects\logs\b4j-2019_06_19.request.log
2019-06-19 11:30:47.714:INFO:eek:ejs.AbstractConnector:main: Started ServerConnector@2a70a3d8{HTTP/1.1,[http/1.1]}{0.0.0.0:17178}
2019-06-19 11:30:47.714:INFO:eek:ejs.Server:main: Started @1511ms
Emulated network latency: 100ms
jRDC is running (version = 2.22)
Then on the same machine that your are the B4J IDE and the jRDC2 server, use a browser and go to
B4X:
http://localhost:17178/test
Switch back to the B4J IDE and you should see an entry similar to this
[main] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge17ya3wg1xib1sgukx5|769e7ee8, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge17ya3wg1xib1sgukx5|769e7ee8, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://xxx.xxx.xxx.xxx:3306/dbutils, maxAdministrativeTaskTime -> 0, maxCo...
After this entry above, if any errors occur, you'll receive various Exception erros.

For incorrect IP/Hostname and/or port number you should get a CommunicationsException error. In my case (using mysql driver) it is
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

If the password or the user is wrong, you should get a java.sql.SQLException: Access denied for user error message.

If you database name is wrong, you should get an Unknown database error message from your JDBC driver. For the mysql driver it looks something like this:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'dbutils___'

If your JDBC URL portion that pertains to the driver is wrong (in your case jdbc:jtds:sqlserver:) then you should be getting a java.sql.SQLException: No suitable driver error message

Please note, out of the box, the only config.properties file that jRDC2 server will use is located in the Files directory under the Objects directory. When you make any changes to that file, you have to recompile the jRDC2 server to recognize any changes to that file.
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
Thnx for the explanation...

When I do as you say I get the error

Ιουν 21, 2019 1:35:54 ΜΜ com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge166a3xqourw1fam2cx|7bb11784, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.microsoft.sqlserver.jdbc.SQLServerDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge166a3xqourw1fam2cx|7bb11784, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jdbc:jtds:sqlserver://192.168.1.2/EXPIosif, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 180...
Ιουν 21, 2019 1:36:24 ΜΜ com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@23a215f8 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Ιουν 21, 2019 1:36:24 ΜΜ com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@10834326 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Ιουν 21, 2019 1:36:24 ΜΜ com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@403e701d -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
I wouldn't recommend using the JTDS driver as it was last updated in 2013. I would use the official Microsoft driver.Forget JRDC2 for the minute and just try a JSQL connection. For this to work I am assuming you have enabled TCP /IP in SQL Server Configuration Manager and that the SQL Server Authentication is set to SQL Server and Windows Authentication mode.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #AdditionalJar: mssql-jdbc-7.2.2.jre11.jar
#End Region
 
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Public MSSQLConnection As SQL
End Sub

 
Sub AppStart (Form1 As Form, Args() As String)
  MSSQLConnection.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://MYSERVER\MYSQLSERVER:56860;databaseName=MYDB;user=****;password=****;")

End Sub

For the connection string:
MYSERVER is the fully qualified name of the server you want to connect to.
MYSQLSERVER:56860 is the name and port of the SQL server where the database is located (you can run multiple instance of SQL Server on the same server)
MYDB is the name of the database you want to connect to.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
#AdditionalJar: sqljdbc42.jar
This is not the correct .jar file for jTDS. That' is why you are getting
java.sql.SQLException: No suitable driver
messages. The latest version should be a jtds-1.3.1.jar file. The file you are including is the JDBC driver from Microsoft, albeit a really old one. You should ignore both and go with @keirS's recommendation and use the latest Microsoft drivers (he provides a link). Please note that you may have two version included in each download. For example, if you go with the latest 7.2 branch (recommended), you'll get a mssql-jdbc-7.2.2.jre8.jar, used with JDK8/JRE8and a mssql-jdbc-7.2.2.jre11.jar, used with JDK10/JRE10 and up (notice no JDK9/JRE9 support).
 
Upvote 0
Top