Android Question B4J implementation of RDC (Remote Database Connector)

jeffkwells

Member
Licensed User
OliverA has got me as far as running JRDC successfully (I think). At least the log says it's running. But the Animals table specified in the Config file wasn't created in the MySql database so I've manually created it. But when I run the client in debug mode on my Samsung device and step through the code, it doesn't return any results at all , though no error messages.

I'm not understanding how my device can connect to MYSQL on my pc just by using IP address 127.0.0.1. How will this work if my device is away from home? Help!
 

OliverA

Expert
Licensed User
Longtime User
device can connect to MYSQL on my pc just by using IP address 127.0.0.1
Your device should use the IP address of the machine that is hosting JRDC2 for the JRDC2 connection, not 127.0.0.1. If you are away from home, then you have to set up your router for forwarding and you either need a static IP address or dynamic DNS for the internet facing part of your router.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
What code on the client side are you using to access the data on the server? If the client is communicating with the server you should be seeing log entries on the server.
 
Upvote 0

jeffkwells

Member
Licensed User
Here is the actual Client code (changed from .b4a to allow upload) and also the Jrdc Config.properties file.

Thanks
 

Attachments

  • RemoteServerClient.txt
    2.3 KB · Views: 178
  • config.txt
    1 KB · Views: 197
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Here is the actual Client code

In B4A, with your project loaded, do a Tools->Clean Project. Then do a File->Export As Zip and upload the zip file.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User

Attachments

  • RDC2Client.zip
    9.7 KB · Views: 167
Upvote 0

jeffkwells

Member
Licensed User
Well, I installed what I could find. The documentation is by no means clear. I've tried to run your revised code. Which line should I use?

1. Private const rdcLink As String = "http://92.30.85.165:17178/rdc"

or

2. Private const rdcLink As String = "http://192.168.0.100:17178/rdc"

I've tried both - they give the same log of:

Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
Attempting to create table
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ERROR: org.apache.http.conn.ConnectTimeoutException: Connect to .. timed out
ERROR: org.apache.http.conn.ConnectTimeoutException: Connect to .. timed out

Thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sounds like you need to update your httputils and http library with the much newer okhttputils and okhttp library

You are using which version of android.jar in Tools -> Configure paths?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

jeffkwells

Member
Licensed User
Now I'm really confused. Could you give me a really simple set of instructions (ie 1.2.3) as to which files I install and where. I assume libraries go in

C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries\
 
Upvote 0

jeffkwells

Member
Licensed User
Thanks Manfred

I've installed that but still get the following error log. And the same error if I change the line of code to

Private const rdcLink As String = "http://92.30.85.165:17178/rdc" ''My IP address)

ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to /192.168.0.100 (port 17178) after 30000ms, Response:
ERROR: java.net.SocketTimeoutException: failed to connect to /192.168.0.100 (port 17178) after 30000ms
** Activity (main) Pause, UserClosed = true **
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Both your phone/android device and computer that is running JRDC2 need to be on the same network (WiFi/Wired/Combination thereof). JRDC2 needs to be up and running. Use the IP address of your computer that is running JRDC2. If need be, double check the computers IP address and make sure it has not changed.
 
Upvote 0

jeffkwells

Member
Licensed User
Thanks Oliver At last we're getting somewhere. I was using my public ip address rather than the IPv4. I think I'm reaching the MYSql database now. The log shows:

** Activity (main) Create, isFirst = true **
Attempting to create table
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Tag: null, Columns: 1, Rows: 1
AffectedRows (N/A)
0
ResponseError. Reason: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)., Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<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</h2>
<p>Problem accessing /rdc. Reason:
<pre> java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
ERROR: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<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</h2>
<p>Problem accessing /rdc. Reason:
<pre> java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You need to change the select statement in the config.properties file to
B4X:
sql.select_animal=SELECT name, image, id FROM animals WHERE id = ?
 
Upvote 0

jeffkwells

Member
Licensed User
That did it. Many thanks Oliver and Manfred. You have all been most helpful but the documentation needs attention - needs to be more idiot proof!

best

Jeff Wells
Retired - after writing many thousands of lines of VB and VBA code over 30years, believe it or not! Trying to get to grips with stuff that only really got going after I retired.
 
Upvote 0
Top