B4J Question Cannot connect to SQL Server - JRDC

Bernaert Dominique

Member
Licensed User
Longtime User
Hi,

I'm trying to configure a JRDC services to connect to a Sql Server 2017 database.
I've downloaded the jdbc driver from Microsoft and included it in the project.
I have a local database running and I can access the database using the Server Manager using the credentials specified in the config file.

When I try to access the /test using a browser I get a no suitable driver error.

Any ideas what I could be doing wrong?

This is the content of my config file:

#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.microsoft.sqlserver.jdbc.SQLServerDriver
#DriverClass=com.mysql.jdbc.Driver
JdbcUrl="jdbc:sqlserver://localhost:1433;databaseName=AdmConcept;user=sa;password=Zandstraat11;"
#JdbcUrl=jdbc:mysql://localhost/test?characterEncoding=utf8
User=sa
Password=Zandstraat11
#Java server port
ServerPort=17178
#example of MS SQL Server configuration:
#DriverClass=net.sourceforge.jtds.jdbc.Driver
#JdbcUrl=jdbc:jtds:sqlserver://<server address>/<database>
#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
sql.create_table=CREATE TABLE article (col1 numeric(10,4) ,col2 text);
sql.select=select * from article
sql.insert=INSERT INTO article VALUES(?, ?)


Thx,
Bernaert Dominique
 

Attachments

  • Screenshot1.PNG
    Screenshot1.PNG
    187.1 KB · Views: 501

Bernaert Dominique

Member
Licensed User
Longtime User
Sorry,

here it is.

Waiting for debugger to connect...
Program started.
2018-04-12 09:11:00.946:INFO::main: Logging initialized @608ms to org.eclipse.jetty.util.log.StdErrLog
Apr 12, 2018 9:11:01 AM com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
Apr 12, 2018 9:11:01 AM com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2018-04-12 09:11:01.463:INFO:eek:ejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-04-12 09:11:01.503:INFO:eek:ejs.session:main: DefaultSessionIdManager workerName=node0
2018-04-12 09:11:01.503:INFO:eek:ejs.session:main: No SessionScavenger set, using defaults
2018-04-12 09:11:01.505:INFO:eek:ejs.session:main: Scavenging every 660000ms
2018-04-12 09:11:01.512:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@2bbf4b8b{/,file:///D:/Google%20Drive/Projecten/Adm-Concept/Ontwikkeling/CrmObjects/jRDC/Objects/www,AVAILABLE}
2018-04-12 09:11:01.527:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened D:\Google Drive\Projecten\Adm-Concept\Ontwikkeling\CrmObjects\jRDC\Objects\logs\b4j-2018_04_12.request.log
2018-04-12 09:11:01.548:INFO:eek:ejs.AbstractConnector:main: Started ServerConnector@6abf25b9{HTTP/1.1,[http/1.1]}{0.0.0.0:17178}
2018-04-12 09:11:01.548:INFO:eek:ejs.Server:main: Started @1212ms
Emulated network latency: 100ms
jRDC is running (version = 2.21)
Apr 12, 2018 9:11:05 AM 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 -> 1hge1259u1f8ukm2ekyaov|43556938, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.microsoft.sqlserver.jdbc.SQLServerDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge1259u1f8ukm2ekyaov|43556938, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> "jdbc:sqlserver://localhost:1433;databaseName=AdmConcept;user=sa;password=Zandstraat11;", maxAdministrativeTaskTime -...
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3997013e -- 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)
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@704d6e83 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@af401f8 -- 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)
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@704d6e83 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3dd95c00 -- 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)
Apr 12, 2018 9:11:35 AM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@704d6e83 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
 
Upvote 0

Bernaert Dominique

Member
Licensed User
Longtime User
Hi Erel,

yes, this is the sourcecode.
All I changed is that line from the original source.

'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
'change based on the jdbc jar file
#AdditionalJar: mssql-jdbc-6.4.0.jre8
Sub Process_Globals
Public srvr As Server
Public rdcConnector1 As RDCConnector
Public const VERSION As Float = 2.21
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
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
B4X:
JdbcUrl="jdbc:sqlserver://localhost:1433;databaseName=AdmConcept;user=sa;password=Zandstraat11;"

Remove the semicolon at the end of the string.

B4X:
JdbcUrl="jdbc:sqlserver://localhost:1433;databaseName=AdmConcept;user=sa;password=Zandstraat11"
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
B4X:
JdbcUrl="jdbc:sqlserver://localhost:1433;databaseName=AdmConcept;user=sa;password=Zandstraat11;"
#JdbcUrl=jdbc:mysql://localhost/test?characterEncoding=utf8
User=sa
Password=Zandstraat11

You don't need the user name and password in the JdbcUrl if you are setting the user name and password in the config file.
Also have you configured your Server Authentication for Windows Authentication and SQL Server authentication?
 
Upvote 0

Bernaert Dominique

Member
Licensed User
Longtime User
Changed it, does not help.
Yes, I have this configured as you can see in the screenshots.
In Sql server management studio I'm actually connected using these credentials (sa - Zandstraat11)
 

Attachments

  • Screenshot1.PNG
    Screenshot1.PNG
    20.5 KB · Views: 353
  • Screenshot2.PNG
    Screenshot2.PNG
    65.6 KB · Views: 360
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Other error solved:
.SERVER\SQL2012 must be writer as SERVER\\Sql2012 (JdbcUrl=jdbc:sqlserver://localhost\\SQL2017;databaseName=nombrebasedatos;)
.Remember: open firewall
.No intregratedSecurity for sql server
. DriverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver for sql server driver
 
Upvote 0
Top