Android Tutorial Remote Database Connector (RDC) - Connect to any remote DB

Status
Not open for further replies.

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I am realy newbie in Java dan Basic programming syntax. Just trying this tutorial, installing server with Firebird database. Server seem running ok.

When running the program on a device, I got an error :

An Error has occured in sub:main_jobdone(java line:350)
java.lang.NullPointerException

Here are my config.properties :
=======================
DriverClass=org.firebirdsql.jdbc.FBDriver
JdbcUrl=jdbc:firebirdsql://localhost/homy_int_dba
User=admin
Password=123
ServerPort=17178
Debug=true
sql.select_fngd=SELECT name FROM M_MNTH a where mnth <= ?

DDL for M_MNTH :
================
CREATE TABLE M_MNTH
(
MNTH Smallint,
NAME Varchar(20)
);

And here are sample codes from Basic4Android
B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     'reqManager.Initialize(Me, "http://192.168.0.125:17178") -> local connection
     reqManager.Initialize(Me, "http://192.168.1.168:17178")
   End If
End Sub
Sub Activity_Click
  GetAnimal("5")
End Sub
Sub GetAnimal(Name As String)
  Dim cmd As DBCommand
  cmd.Initialize
  cmd.Name = "select_fngd"
  cmd.Parameters = Array As Object(Name)
  reqManager.ExecuteQuery(cmd, 0, Null)
End Sub
Sub JobDone(Job As HttpJob)
  If Job.Success = False Then
    Log("Error: " & Job.ErrorMessage)
  Else
    If Job.JobName = "DBRequest" Then
      Dim result As DBResult = reqManager.HandleJob(Job)
      For Each records() As Object In result.Rows
        Dim name As String = records(0) 'or records(result.Columns.Get("name"))
        Log(name)
        Msgbox(name,"Result")
      Next
    End If
  End If
  Job.Release
End Sub

On Local connection (with ip address 192.168.0.125:17178), it worked ok, but on VPN connection (ip address http://192.168.1.168:17178), nothing happen.

On VPN, program running ok, but when I clicked the screen, there is no message box.
Any hints?

Thanks.
 

incendio

Well-Known Member
Licensed User
Longtime User
Please run it in the debug mode and post the full error message.

Please ignored this error message :
"An Error has occured in sub:main_jobdone(java line:350)
java.lang.NullPointerException"

I have found the solution. What I need is how to make this connection works via VPN.

Here are the latest problem.

When I run in debug mode with cable connected to my device

Run to VPN, got error :
==============
** Service (httputils2service) Create **
** Service (httputils2service) Start **

Error: org.apache.http.conn.ConnectTimeoutException: Connect to /192.168.1.168:17178 timed out


Run to localhost with cable connected and via WIFI is ok.
 
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
Always start with the browser test request. The VPN connection should be configured in your phone. It is not really related to the client or server code.

I have configured VPN correctly in my tablet.

Finally, found the problem! It was the server that blocked port 17178.
After opening this port, program runs ok.

Just a basic question, in the example source code, there is a procedure to execute the query, the code is like this :
B4X:
Sub GetAnimal(Name As String)
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "select_fngd"
    cmd.Parameters = Array As Object(Name)
    reqManager.ExecuteQuery(cmd, 0, Null)
End Sub

Those code only receive 1 parameter as String. How do I write procedure to send multiple parameters?

My query in config file is like this :
sql.select_fngd=SELECT name FROM M_MNTH where mnth <= ? and name like ?
 

incendio

Well-Known Member
Licensed User
Longtime User
B4X:
cmd.Parameters = Array As Object("value1", "value2", "value3")
Ok, thanks for you answer.

A few more questions please :
1) when issued command like this :
B4X:
reqManager.Initialize(Me, "http://192.168.0.100:17178")
is there a return value to know that the connection is success?

2) during app runs, is there a function to know that connection still alive?
 

crawler

Member
Licensed User
Longtime User
Hi,

I get the error: "java.sql.SQLException: Invalid object name 'animals'."
I'm assuming the table 'animals' should be created in my MS SQL Server database by the java server's config.properties, but it doesn't get created.

http://127.0.0.1:17178/?method=test gives "RemoteServer is running (Wed Apr 23 12:18:30 EDT 2014) Connection successful.

I changed "reqManager.Initialize(Me, "http://192.168.0.100:17178")" to "http://192.168.42.158:17178" (my IPv4 address).

I'm allowing port 17178 through the firewall (inbound and outbound). I even tried turning the firewall off completely.

My SQL Server host requires the following connection: "Data Source=tcp:sql2k802.discountasp.net;Initial Catalog=SQL2008_749345_cgs;User ID=SQL2008_749345_cgs_user;Password=******;"

My config.properties file reads:
B4X:
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://sql2k802.discountasp.net/SQL2008_749345_cgs
User=SQL2008_749345_cgs_user
Password=******
ServerPort=17178
Debug=true
#commands
sql.create_table=CREATE TABLE animals (\
    id INT NOT NULL AUTO_INCREMENT,\
    name CHAR(30) NOT NULL,\
    image BLOB,\
    PRIMARY KEY (id))
sql.insert_animal=INSERT INTO animals VALUES (null, ?,?)
sql.select_animal=SELECT name, image FROM animals WHERE name = ?

I also tried:
JdbcUrl=jdbc:jtds:sqlserver://sql2k802.discountasp.net/SQL2008_749345_cgs;user=SQL2008_749345_cgs_user;password=******
And: JdbcUrl=jdbc:jtds:sqlserver://sql2k802.discountasp.net;catalog=SQL2008_749345_cgs;user=SQL2008_749345_cgs_user;password=******

Any idea what the problem is?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…