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

Status
Not open for further replies.

dibesw

Active Member
Licensed User
Longtime User
HI,
I should write a JPEG file into my RDC access database:

This is the creation of the image (that works):
B4X:
Sub FIRMA
    Bitmap1.Initialize3(Canvas.Bitmap)
    Out = File.OpenOutput(File.DirRootExternal, "image.jpeg", False)
    Bitmap1.WriteToStream(Out, 100, "JPEG")
End Sub
This is code that I thing but does not work:
B4X:
Sub repl_image
    Dim cmd As DBCommand
    cmd.Name = "repl_pazient"
    Dim buffer() As Byte
    Out.WriteBytes(buffer, 0, buffer.length)
    cmd.Parameters=Array As Object(Out, 44)
    Out.Close
    reqManager.ExecuteCommand(cmd, "esci")
End Sub
I should write JPEG image into a OLE OBJECT field (sign) and config.properties is:
B4X:
sql.repl_pazient=update paziente set sign = ? where code_pazient = ?
When I call repl_image sub, I have and error in the server side:



I don't know how do to write a OLE into field.
THANKS!
 
Last edited:

dibesw

Active Member
Licensed User
Longtime User
OK, I SOLVED IT!

The correct code is:

B4X:
Sub repl_immagine
    Dim In As InputStream
    Dim cmd As DBCommand
    cmd.Name = "repl_pazient"
    In = File.OpenInput(File.DirRootExternal, "sign.jpeg")
    Dim Out As OutputStream
    Out.InitializeToBytesArray(1000)
    File.Copy2(In, Out) '<---- This does the actual copying
    Dim data() As Byte
    data = Out.ToBytesArray
    cmd.Parameters=Array As Object(data, 44)
    Out.Close
    reqManager.ExecuteCommand(cmd, "esci")
End Sub
 

dibesw

Active Member
Licensed User
Longtime User
HI,
my problem is:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    CreatePreferenceScreen
    reqManager.Initialize(Me, "http://" & manager.GetString("server") & ":17178")
......
......
End Sub
Sub Button2a_Click
    GetAnamnesi
End Sub
Sub GetAnamnesi
    Dim cmd As DBCommand
    ProgressDialogShow("Attendere...")
    cmd.Initialize
    cmd.Name = "select_anamnesi"
    reqManager.ExecuteQuery(cmd, 0, "selana")
End Sub

First time (and only fist time) that I run the program, the server message is:



after all works well.
Why?
Since the message is ConnectionTimeout perhaps maybe I should increase Timeout?
Thanks.
 

dibesw

Active Member
Licensed User
Longtime User
first time that I run the program, time query is too long



B4X:
3p0.maxStatements=150
c3p0.maxIdleTime=1800
c3p0.idleConnectionTestPeriod=600
c3p0.checkoutTimeout=40000

I set c3p0.checkoutTimeout=40000 and now works well
Thanks Erel!
 

dibesw

Active Member
Licensed User
Longtime User
Again for timeout problem:

Every time I run program, system write a directory into my database directory:



every directory is about 244MB.
after I have used it many times, these directory are many
Perhaps every time system write these directory takes time and so this is the cause of the timeout?



My table are composed of a few records.
there is a way to not write these directories?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
This tutorial covers a new framework named Remote Database Connector (RDC). The purpose of RDC is to make it simple to develop Android applications that interact with remote database servers.

DriverClass=com.mysql.jdbc.Driver
JdbcUrl=mysql://127.0.0.1:3306/wbf2
User=xxxx
Password=xxxx
ServerPort=17178
#If Debug is true then this file will be reloaded on every query.
#This is useful if you need to modify the queries.
Debug=true

results in

RemoteServer is running (Mon Feb 03 18:00:59 CET 2014)
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.

when i try to open the url http://127.0.0.1:17178/?method=test in a browser

Can someone help to get the right direction to the solution to get the test running please?
 

derez

Expert
Licensed User
Longtime User
Try to put user=root and no password
Also this line in the example is
JdbcUrl=jdbc:mysql://localhost/test?characterEncoding=utf8
, maybe your :3306 is a problem (I'm guessing...).
 

DonManfred

Expert
Licensed User
Longtime User
On MySQL-Admin the user Root HAS an password.
3306 is the default port of MySQL.

But i tried your suggestion. root with no pw and jdbcurl like in your post. Always the same error. In the commandwindow i read something about "No suiteable driver"...
In folder jdbc_driver is one file: mysql-connector-java-5.1.29-bin.jar

Is that not the right file for MySQL?

 

Erel

B4X founder
Staff member
Licensed User
Longtime User
@dibesw the issues you see with the files and slowdown are caused by the jdbc driver. Can't you switch to a more powerful database (SQLite for example)?

@DonManfred I've just tested it with the latest driver from oracle and it works properly. I've downloaded the server zip file and didn't modify anything. Just copied mysql-connector-java-5.1.29-bin.jar to the jdbc_driver folder.
 

dibesw

Active Member
Licensed User
Longtime User
This is bad news.
I'm working with access database for many years and my customers have all access database.
I have no other options?
 

DonManfred

Expert
Licensed User
Longtime User

Ok, i´ll do a new test with a fresh installation of server-files... Will tell the results later
 

hardo

New Member
Licensed User
Longtime User
Hello,
I'm playing with the RDC and access to MySQL. It works fine.
My question:
Is there a way to work with a SELECT statement, which is total built in my front-end application?
The file config.properties could only contains a line like sql.select_xxx=*
Thanks.
 

hardo

New Member
Licensed User
Longtime User
I tried the following command in the config.properties of the RDC-server:
SELECT ?,? FROM, <mytable>
As parameters I wrote
ARRAY as Object ("Name", "City")
Name and City are field names from <mytable>. The program processes the command
without an error message, but the output lines all show only the text "Name City."
It will not output the contents of the fields.

It would increase the flexibility of the application if the above SELECT statement would work "normal".
By the way: SELECT and injection attack?

Regards Hardo.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…