B4J Question [Solved][Server] Run the ServerExample on Synology with MariaDB

Elric

Active Member
Licensed User
Hello!

I'm trying to run the ServerExample (https://www.b4x.com/android/forum/threads/webapp-web-apps-overview.39811/#content) on my NAS Synology.

This device uses MariaDB10 instead of MySQL.

So, I've done some modification to ServerExample (renamed in ServerExampleMariaDB) code:
  1. I've downloaded "mariadb-java-client-2.7.1.jar" library (from here) and I've added it in Additional libraries folder
  2. in the Main module I've substituted
    B4X:
    #AdditionalJar: mysql-connector-java-5.1.27-bin
    with
    B4X:
    #AdditionalJar: mariadb-java-client-2.7.1
  3. in the settings.txt file I've substituted
    B4X:
    JdbcUrl=jdbc:mysql://localhost/b4j_server?characterEncoding=utf8
    DriverClass=com.mysql.jdbc.Driver
    DBUser=root
    DBPassword=
    RecaptchaPrivateKey=
    Port=51042
    [*]
    with
    B4X:
    JdbcUrl=jdbc:mariadb://localhost/b4j_server?characterEncoding=utf8
    DriverClass=org.mariadb.jdbc.Driver
    DBUser=root
    DBPassword=
    RecaptchaPrivateKey=
    Port=51052
    [*]
  4. I've run the ServerExampleMariaDB code in release mode and copied on web folder the ServerExampleMariaDB.jar, the "www" folder; I've created at same level of "www" folder on NAS, the folder "libs" with all the libraries listed by the info compile windows:
B4X:
B4J Version: 8.50
Java Version: 8
Parsing code.    (0.10s)
Building folders structure.    (0.03s)
Compiling code.    (0.09s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    (0.01s)
Building jar file.    (0.05s)
    Jar file created: D:\B4X\B4J-Projects\ServerExample\Objects\ServerExample.jar
    Libraries were not merged into jar file.
The following libraries should be distributed in the libs folder:
    ByteConverter.jar
    Encryption.jar
    jCore.jar
    jCustomToast.jar
    jDateUtils.jar
    jExcel.jar
    jHTTP.jar
    jServer.jar
    Json.jar
    jSQL.jar
    jStringUtils.jar
    jxl.jar
    httpcore-4.0.jar
    commons-logging-1.1.3.jar
    jetty_b4j.jar
    c3p0-0.9.5.2.jar
    c3p0-oracle-thin-extras-0.9.5.2.jar
    mchange-commons-java-0.2.11.jar
    sqlite-jdbc-3.7.2.jar
    mariadb-java-client-2.7.1.jar
Running application.    (5.30s)
Completed successfully.

Then I opened the chosen port (51052 as set in setting.txt) on router and run the ServerExampleMariaDB.jar in Task Scheduler, following "my precedent success" for the HelloWorldServer example.

But the server program doesn't work and the task results "Interrupted" and I've gotten "ERR_CONNECTION_REFUSED".

This is my first attempt to manage a client-server DB; maybe do I miss some basic passage?

Any support will be welcome!

Thank you!
 
Last edited:

Elric

Active Member
Licensed User
Have you also added: #AdditionalJar: mariadb-java-client-2.7.1 .jar ?

I've updated the code:
B4X:
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: false
    '#AdditionalJar: mysql-connector-java-5.1.27-bin 'this is the original string in the ServerExample
    #AdditionalJar: mariadb-java-client-2.7.1
    #AdditionalJar: sqlite-jdbc-3.7.2
#End Region

and make sure that the correct library "mariadb-java-client-2.7.1.jar" is in the path:
1609136927002.png

1609137683556.png

and got this nohup.out file:
B4X:
2020-12-28 07:45:09.500:INFO::main: Logging initialized @2630ms to org.eclipse.jetty.util.log.StdErrLog
Dec 28, 2020 7:45:11 AM com.mchange.v2.log.MLog 
INFO: MLog clients using java 1.4+ standard logging.
Dec 28, 2020 7:45:12 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]
Dec 28, 2020 7:45:13 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 -> z8kfltae1an1g8c1f0u5l7|140564, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.mariadb.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> z8kfltae1an1g8c1f0u5l7|140564, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jdbc:mariadb://localhost/b4j_server?characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 150, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
db._createusertableifneeded (java line: 151)
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at anywheresoftware.b4j.object.ConnectionPool.GetConnection(ConnectionPool.java:45)
    at b4j.example.db._createusertableifneeded(db.java:151)
    at b4j.example.main._appstart(main.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:28)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@1686d1f -- timeout at awaitAvailable()
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1467)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
    ... 11 more
 
Upvote 0

Elric

Active Member
Licensed User
Not sure why you added sqlite, but it is not related to this error.
It's not me. As is in the example. :)

This is a different error. It means that jRDC2 wasn't able to get a connection. Maybe the password is wrong. Maybe the db server is not open for TCP connections. Maybe the port is wrong.
I'm using as DBUser "root" and I've checked the password several times and is correct. I use the same user and password I use to access with phpMyAdmin.

I've ensured to enable TCP/IP connection (as per attached image). About the port: do you mean the MariaDB port? That is by default set at 3307. I need to wrote it in somewhere?
1609138932740.png


Thanks as usual!
 
Upvote 0

José J. Aguilar

Expert
Licensed User
The standar port is 3306 if I'm not wrong. Probably synology has changed it to coexist MariaDB 10 and 5
Add the port to the connection string:
B4X:
JdbcUrl=jdbc:mysql://localhost:3307/b4j_server?characterEncoding=utf8
 
Upvote 0

Elric

Active Member
Licensed User
EUREKA! 😎

Thanks to everybody!!!

So, "my step by step" instruction to run the ServerExample (https://www.b4x.com/android/forum/threads/webapp-web-apps-overview.39811/#content) on Synology NAS with MariaDB [please, correct me if there is something wrong]:
  1. download "mariadb-java-client-2.7.1.jar" library (from here) or a new stable version
  2. in the Main module call the "mariadb-java-client-2.7.1.jar" library:
    B4X:
    #Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: false
    ' ************************ #AdditionalJar: mysql-connector-java-5.1.27-bin ******************* this is the original string in the ServerExample
    #AdditionalJar: mariadb-java-client-2.7.1
    #AdditionalJar: sqlite-jdbc-3.7.2
    #End Region
  3. Create by phpMyAdmin the database "b4j_server" (or use another name)
  4. Change the "settings.txt" file
    JdbcUrl=jdbc:mysql://localhost/b4j_server?characterEncoding=utf8
    DriverClass=com.mysql.jdbc.Driver

    JdbcUrl=jdbc:mariadb://localhost:3307/b4j_server?characterEncoding=utf8
    DriverClass=org.mariadb.jdbc.Driver

    DBUser=root
    DBPassword=[password]
    RecaptchaPrivateKey=[key if is available]
    Port=51042

    the "3307" is the default port of MariaDB. It is possible to use as "DBUser" and "DBPassword" the same used to have access to phpMyAdmin. "b4j_server" is the name of database created at point no. 3. If you want to change the name of database at point no. 3,it is necessary change also here in "settings.txt" file
  5. Run the code in release mode
  6. Copy on web folder the .jar file, the "www" folder
  7. Create at same level of "www" folder on NAS, the folder "libs" and copy herein all the libraries listed by the info compile window, including "mariadb-java-client-2.7.1.jar" library
  8. open MariaDB window and enable TCP/IP connection
  9. open the port "51042" (or the other port choose in "settings.txt" file) on router to give remote access
  10. Then, the working code in "Panel Control -> Task Scheduler -> Create -> Triggered Task > User-defined script":
    B4X:
    cd /volume1/web/ServerExample
    nohup /var/packages/Java8/target/j2sdk-image/bin/java -jar /volume1/web/ServerExample/ServerExample.jar > /volume1/web/ServerExample/nohup.out
  11. in "Panel Control -> Task Scheduler" select the task and "Run"
I hope may be useful.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
No. You need to create an empty database with the name "b4J_server". The example doesn't create one for you.
 
Upvote 0
Top