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

Status
Not open for further replies.

Pravin Shah

Member
Licensed User
Longtime User
Yes, the 'test' database is in localhost. I am testing this connection on my local machine. I tried both urls
127.0.0.1:17178/?method=test and localhost:17178/?method=test
but no success, same error message.

I have attached the error log from JDBC server, it may be of some help to resolve the issue.

Appreciate your help, thanks.
 

Attachments

  • timeout error.txt
    5.2 KB · Views: 283

Pravin Shah

Member
Licensed User
Longtime User
Just to update, I am able to resolve the issue. There were issues with user privileges, I have created new user and assign all the privileges. After that I have tested connection with new user credentials and the connection was successful.

I will try with MS SQL server connection now.
 

timbald

Member
Licensed User
Longtime User
Extremely helpful, thank you. Got this working on Raspberry Pi.

 

Brookalino

Member
Licensed User
Longtime User
Hi Erel,


I am not able to connect to my localhost database using RDC server.

I have tried everything from the previous posts and its beginning to drive me a little crazy!



I have extracted the contents of RDC-Client.zip and RDC-Server.zip to the appropriate directory

I copied the driver to the correct jdbc_driver folder. (sqljdbc41.jar)


I have changed the config.properties file : (creating a ‘atest’ database in my local SQL)

I have made sure the ALLIP in the SQL Server Configuration Manager are set to 1433.



4. After that I run the RunRLC.bat file and each time I get that the ‘Address is already in use’ error.
Edit: I have checked that nothing is running in the background




I have changed the 127.0.0.1 to localhost with the same outcome and have tried to change the port number but also get the above?


5. After that I tried running the following url 127.0.0.1:1433/?method=test to test database connection


But it gave the following error.



Note : I am using SQL Server 2012


This is driving me crazy so if you have any ideas I would appreciate the help.
 
Last edited:

keirS

Well-Known Member
Licensed User
Longtime User
You are telling RDC to listen on the same port as your SQL server is listening on! Your connection string ip should be 127.0.0.1:1443
Default server port for jetty is 8080.
 

GuerillaProgrammer

Member
Licensed User
Longtime User
I'm a little confused. Why can B4A not directly use the jdbc to connect to a remote MS SQL db installation.

I don't want to use configuration files for a web server that passes my requests via http rather than making a direct connection.

This is EXACTLY the kind of unnecessary unix/java mentality hyper-complexity that I'm looking to B4A as an escape from. What is the basis for the requirement for this kind of kludgish workaround?

Do you have any intention of implementing the jdbc directly any time soon?

Please tell me that I've misunderstood what this article says, or that B4A has implemented direct usage of the jdbc to SQL connection since August.



Erel said:
Android cannot directly connect to the database server.


Having included the "net.sourceforge.jtds.jdbc.Driver" The following code connects Android to an MS SQL DB directly.
'===================================================================
String connString = "jdbc:jtds:sqlserver://ecp-clientmgr.cycyg6emdsi3.us-east-1.rds.amazonaws.com;" +
"Initial Catalog=DB_NAME;" +
"useSSL=true;" +
"encrypt=true;" +
"TrustServerCertificate=true;" +
"Integrated Security=False;" +
"user=DB_USER;" +
"password=YOUR_PASSWORD_HERE;";

conn = DriverManager.getConnection(connString);

Return conn;
'===================================================================

There is some work that one must do with an SSL certificate which I will be glad to research and share if it will help, but I have already used this code to connect an android emulator to the Amazon hosted DB and it works perfectly.

My question is: Is the limitation in the B4A application, or has it simply been too hard to make the above approach work? If the former, then I can't help and cannot use B4A(makes me very sad), but if the latter please let me know and I'll be glad to share the methodology.

Humbly, GP
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Anything that you can do in Java can be done with B4A. If the jdbc driver is supported by Android then you can use it in B4A (with a wrapper).

In most cases it is not recommended to connect directly to the database from the mobile app for various reasons including security.

Use the forum search to find relevant libraries: https://www.b4x.com/android/forum/pages/results/?query=mssql&page=1&prefix=1
 

GuerillaProgrammer

Member
Licensed User
Longtime User
Anything that you can do in Java can be done with B4A. If the jdbc driver is supported by Android then you can use it in B4A (with a wrapper).

What kind of wrapper?

In most cases it is not recommended to connect directly to the database from the mobile app for various reasons including security.
I understand the risks. We've already architected the security, and I'd just like to be able to make the connection so that I can get back to developing.


I'm a little confused about how to include libraries in B4A.
1). Is there an include or imports statement?
2). The following code (Dim conn As Connection) fails because B4A doesn't see the java.sql package which contains the definition of Connection. How do I include java.sql in my B4A app?
3). Can you briefly explain how to create the xml files for the libraries to be included and the purpose for them.(On Edit: I watched your video "Basic4android Tutorial - Creating a library" and I think I get this, although I haven't yet tried it.)

I want to thank you for such prompt replies. Most support I've experienced has been on the order of days rather than hours.
 
Last edited:

NMiguel

Member
Licensed User
Longtime User
Hello.
Sorry the newby question:

How can I copy the results in the sub JobDone to an array so i can access it in other subs.
I need to do several different select queries and handle the results in different subs.

I hope it's not a duplicate question. I searched this thread and didn't find anything similar.

Thanks in advance.
 

NMiguel

Member
Licensed User
Longtime User
Thanks for the fast reply Erel.

I have tried and doesn't work.

Here is the Code:
B4X:
Sub Process_Globals
    Dim reqManager As DBRequestManager
    Private gr As DBResult
End Sub

Sub Globals
    Dim Ver As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        reqManager.Initialize(Me, "http://192.168.0.199:17178")
    End If

    Activity.LoadLayout("Main")
End Sub

Sub Ver_Click
    GetDescricao("5602482013384")

        For Each Records() As Object In gr.Rows
            Dim CodP As String = Records(gr.Columns.Get("Cod"))
              Log(CodP)
              Dim Descr As String = Records(gr.Columns.Get("Desc"))
              Log(Descr)
        Next
End Sub

Sub GetDescricao(Name As String)
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "select_produto"
    cmd.Parameters = Array As Object(Name)
    reqManager.ExecuteQuery(cmd, 0, Null)
End Sub

Sub JobDone(Job As HttpJob)
    Dim Result As DBResult
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
    Else
        If Job.JobName = "DBRequest" Then
            Result = reqManager.HandleJob(Job)
            'reqManager.PrintTable(Result)
            gr = Result
        End If
    End If
    Job.Release
End Sub

Ir guives a java error:
B4X:
LogCat connected to: 37303AF8D17600EC
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 36 (main)
java.lang.NullPointerException
    at b4a.example.main._ver_click(main.java:427)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:77)
    at android.view.View.performClick(View.java:4247)
    at android.view.View$PerformClick.run(View.java:17728)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5289)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
    at dalvik.system.NativeStart.main(Native Method)
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = true **
 

MrKim

Well-Known Member
Licensed User
Longtime User
Out of curiosity, what is the purpose of Job.JobName and the code:
B4X:
If Job.JobName = "DBRequest" Then
IF the JobName is ALWAYS DBRequest? This seems spurious to me since Job.Success determines if we were successful.

Thanks
 

MrKim

Well-Known Member
Licensed User
Longtime User
The jobdone sub is part of httputils. You may use it in your activity too. The same sub will be called and you have to decide whether the data coming from a normal httputils call or from dbrequestmanager
Got it, thanks. have not used httputils. I am assuming JobName is the Name parameter when you initialize an HttpJob?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…