B4J Question jRDC java.sql.SQLException: No suitable driver

Georg Machacek

New Member
Licensed User
Hello I can't get the JRDC example run with MsSql.

'my main
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: mssql-jdbc-7.2.1.jre8.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

'my config.properties file
B4X:
#Lines starting with '#' are comments.
#Backslash character at the end of line means that the command continues in the next line.

#DATABASE CONFIGURATION

#DriverClass=com.mysql.jdbc.Driver
#JdbcUrl=jdbc:mysql://localhost/toptech?characterEncoding=utf8
User=sa
Password=123456
#Java server port
ServerPort=17178

#example of MS SQL Server configuration:

#with this driver class I got DriverClass not found!
#DriverClass=net.sourceforge.jtds.jdbc.Driver

#with this ist looks I am a step further
DriverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
JdbcUrl=jdbc:jtds:sqlserver://localhost/test

#example of postegres configuration:
#JdbcUrl=jdbc:postgresql://localhost/test
#DriverClass=org.postgresql.Driver

#SQL COMMANDS
sql.create_table=CREATE TABLE IF NOT EXISTS animals (\
     id INTEGER PRIMARY KEY AUTO_INCREMENT,\
     name CHAR(30) NOT NULL,\
     image BLOB)
#sql.insert_animal=INSERT INTO animals VALUES (null, ?,?)
#sql.select_animal=SELECT name, image, id FROM animals WHERE id = ?;
#sql.create_table=CREATE TABLE article (col1 numeric(10,4) ,col2 text);
#sql.select=select * from article
#sql.insert=INSERT INTO article VALUES(?, ?)

'the protocol
B4X:
Waiting for debugger to connect...
Program started.
2019-03-26 16:02:04.472:INFO::main: Logging initialized @597ms to org.eclipse.jetty.util.log.StdErrLog
Mär 26, 2019 4:02:04 PM com.mchange.v2.log.MLog
INFORMATION: MLog clients using java 1.4+ standard logging.
Mär 26, 2019 4:02:04 PM com.mchange.v2.c3p0.C3P0Registry
INFORMATION: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2019-03-26 16:02:05.176:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 1.8.0_192-b12
2019-03-26 16:02:05.214:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2019-03-26 16:02:05.214:INFO:oejs.session:main: No SessionScavenger set, using defaults
2019-03-26 16:02:05.230:INFO:oejs.session:main: node0 Scavenging every 660000ms
2019-03-26 16:02:05.230:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@262b2c86{/,file:///C:/toptech/jRDC2/jRDC/Objects/www,AVAILABLE}
2019-03-26 16:02:05.230:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\toptech\jRDC2\jRDC\Objects\logs\b4j-2019_03_26.request.log
2019-03-26 16:02:05.261:INFO:oejs.AbstractConnector:main: Started ServerConnector@569cfc36{HTTP/1.1,[http/1.1]}{0.0.0.0:17178}
2019-03-26 16:02:05.261:INFO:oejs.Server:main: Started @1390ms
Emulated network latency: 100ms
jRDC is running (version = 2.22)
Mär 26, 2019 4:02:12 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFORMATION: 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 -> 1hge9saa11fr4f401mkptu4|445b84c0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.microsoft.sqlserver.jdbc.SQLServerDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge9saa11fr4f401mkptu4|445b84c0, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jtds:sqlserver://localhost/test, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800,...
Mär 26, 2019 4:02:42 PM com.mchange.v2.resourcepool.BasicResourcePool
WARNUNG: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@264f240e -- 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)
Mär 26, 2019 4:02:42 PM com.mchange.v2.resourcepool.BasicResourcePool
WARNUNG: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@58c4d06b -- 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)

Thx in advance
Georg
 

OliverA

Expert
Licensed User
Longtime User
JdbcUrl=jdbc:jtds:sqlserver://localhost/test
This is incorrect. At minimum, you need to take out the jtds: portion
B4X:
JdbcUrl=jdbc:sqlserver://localhost/test
At that point you may still not get a server connection if //localhost/test is incorrect
For some MSSQL related url's see:
https://www.b4x.com/android/forum/threads/mssql-jdbc-minimalistic-example.90548/#content
https://www.b4x.com/android/forum/threads/cannot-connect-to-sql-server-jrdc.91806/#post-579912
https://www.b4x.com/android/forum/threads/sql-simplyfying-calling-stored-procedures.73181/
 
Upvote 0
Top