Android Question Unable to connect to MySQL using jRDC2 on VPS

Setlodi

Member
Hi there
I hope someone can help me. I have followed Erel's tutorial on configuring B4A and B4J jRDc2 for connecting to a remote MySQL database. This is what I did:

On jRDC B4J
Edited config.properties
DriverClass=com.mysql.jdbc.Driver
JdbcUrl=jdbc:mysql://My-VPS-IP-Address/exampleDB?characterEncoding=utf8
User=root
Password=********

#Java server port
ServerPort=17178

Also:
B4X:
#AdditionalJar: mysql-connector-java-5.1.47-bin

Compiled jRDC and built standalone package

1675667567255.png


On the VPS:
  1. Installed MySQL
  2. Created exampleDB test database
  3. Created user with root access and granted all privileges
  4. Edited mysqld.cnf to allow all IP's to connect - changed from 127.0.0.1 to 0.0.0.0
  5. Opened ports 3306 and 17178 on the firewall
  6. Confirmed that both 3306 and 17178 ports are listening
  7. Copied compiled jRDC file to VPS in the folder where my exampleDB is located
  8. Ran nohup /usr/lib/jvm/java-11-openjdk-amd64/bin/java -jar /var/lib/mysql/jrdc.jar & > nohup.out & successfully
1675672711248.png

On B4A
B4X:
Private const rdcLink As String = "http://160.119.254.12:17178/rdc"

The problem is when I run http://160.119.254.12:17178/test, I get the following error:

RemoteServer is running (02/06/2023 08:36:18)
Error fetching connection.

Please help!!
 

OliverA

Expert
Licensed User
Longtime User
1) If jRDC2 is running on the same server as your MySQL install, DO NOT open up MySQL to the public. That's is one of the main features of jRDC2 - not exposing the DB server to the public.

2) For testing purposes, don't run jRDC2 with nohup. This way you get visual feedback as to what jRDC2 is complaining about. Otherwise, look at the nohup.out file and see what jRDC2 is complaining about. You may need to stop jRDC2 in order for the stout/stderr to be completely flushed to nohup.out
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi:

JdbcUrl=jdbc:mysql://My-VPS-IP-Address/exampleDB?characterEncoding=utf8
You're running the jRDC2 server (.jar file) to your server, so, mysql and the jRDC2 are running on the same machine. You should change My-VPS-IP-Adress to localhost, and CLOSE the 3306 port¡¡¡¡

In your B4A app, is where you should use your VPS address to connect to the B4J server through 17178 port.

You should too create a non-root user and assign it just permissions on your database for security reasons. (but this is not a problem for your tests)

By the way, running http://160.119.254.12:17178/test I get

RemoteServer is running (02/06/2023 12:44:52)
Connection successful.
 
Upvote 0

Setlodi

Member
Hi:


You're running the jRDC2 server (.jar file) to your server, so, mysql and the jRDC2 are running on the same machine. You should change My-VPS-IP-Adress to localhost, and CLOSE the 3306 port¡¡¡¡

In your B4A app, is where you should use your VPS address to connect to the B4J server through 17178 port.

You should too create a non-root user and assign it just permissions on your database for security reasons. (but this is not a problem for your tests)

By the way, running http://160.119.254.12:17178/test I get

RemoteServer is running (02/06/2023 12:44:52)
Connection successful.
Hi Jose

Yes I managed to get it working while waiting for the help. I understand what you and OliverA are saying about no opening MySQL to exernal users as the jRDC server is hosted locally in the same server. I will close it.
 
Upvote 0

Setlodi

Member
Now that the connection is working, I'm now getting an HTTP ERROR 500.


In B4A jRDC mocule:
Private const rdcLink As String = "http://160.119.254.12:17178/rdc"

See the logs below:

Logger connected to: HUAWEI EML-L09
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: Server Error, Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</title>
</head>
<body><h2>HTTP ERROR 500 java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</h2>
<table>
<tr><th>URI:</th><td>/rdc</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</td></tr>
<tr><th>SERVLET:</th><td>anywheresoftware.b4j.object.JServlet-40a4337a</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>
ERROR: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</title>
</head>
<body><h2>HTTP ERROR 500 java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</h2>
<table>
<tr><th>URI:</th><td>/rdc</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</td></tr>
<tr><th>SERVLET:</th><td>anywheresoftware.b4j.object.JServlet-40a4337a</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The SQL command you have set up in the config.properties file does not contain a parameter (a ?), yet you are passing on a parameter to the query.

Note: Unless you have a modified version of jRDC2, any changes to the config.properties file should be followed by recreating the .jar file and re-uploading/publishing it to the server.
 
Upvote 0
Top