Android Question mysql

apti

Member
I am new to B4A but not to programming. I have been looking for how to connect to a mysql database from the app I write.

There is no code at this point because I am starting. I have looked into this but can't find quite what I need, or maybe can't understand it.

1 The mysql database is hosted on a linux server.
2 No changes can be made to the server, this includes adding software and scripts.
3 I need to connect to a mysql database using the username and password and IP address.
4 This will be simple queries and writing to database only.

Can somebody point a newbie into the right direction for this?
 

aeric

Expert
Licensed User
Longtime User
Welcome to the forum.

Before going further, please read

Use the forum search. There are a lot of similar threads.

2 No changes can be made to the server, this includes adding software and scripts.
Why?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

aeric

Expert
Licensed User
Longtime User
The 3 most common solutions in this forum are explain in the following threads:
1. JdbcSQL
2. jRDC2
3. PHP

I don't use above solutions. I created my own Web API Client+Server.

The latest and more complex template with user login is also available if you want to explore more.

Except for #1 JdbcSQL which use direct connection to the database server without adding scripts or middleware app, other solutions require additional installations.

It seems solution #1 is the simplest but there are reasons why it is not recommended.
 
Upvote 0

apti

Member
Welcome to the forum.

Before going further, please read

Use the forum search. There are a lot of similar threads.


Why?
it does not matter why. why does not change anything because you still can't add to it.
also, thanks for the link telling me to go search, I didn't post without doing searches first and found nothing that met the requirements.
 
Upvote 0

apti

Member
The recommended solution is to use JRDC2 as suggested in #3.
You need to run it on your Server/VPS. You maybe need a own Server or VPS for this though.
thank you I will look into that one. SInce it is the only one that allows direct connection.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I repeat if you didn't get it.

Only JdbcSQL provides direct connection in B4A and B4J.

jRDC2 is a middleware server that you need to install on the server (or another server that use JdbcSQL or having direction connection to the database server if it does exist).
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
also, thanks for the link telling me to go search, I didn't post without doing searches first and found nothing that met the requirements.
Please, don't be sarcastic, everyone here is trying to help. You can try different search words. You can try the first library listed

1727245813586.png

SInce it is the only one that allows direct connection.
As Aeric have said, jRDC2 doesn't allow direct connection.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
2 No changes can be made to the server, this includes adding software and scripts.
this is a great problem

if you can't install any script/program in the server, you need to ask at server administrator if there are some API (or other) for to connect to database
Sorry, I don't see any other solution
 
Upvote 0

apti

Member
well, looks like I found the mysql stuff but I can't get it to work. I need some good working examples please.

the sql database is on a non standard port so first thing is would I have to do it this way? 192.168.11.55:3366

but when I do this it fails, the example provided by jdbcsql really well, is lacking. The example also fails. The query seems to be the point of failure.



Dim QQ As String="SELECT cName FROM Customers WHERE Custid ='SCL'"
Log("Just in")

Wait For (Connect) Complete (Success As Boolean)
If Success Then
Try
Dim sf As Object = mysql.ExecQueryAsync("mysql", QQ, Array(300))
Log("starting "&QQ)
Wait For (sf) mysql_QueryComplete (Success As Boolean, Crsr As JdbcResultSet) <-------------- this is where it fails but this is unchanged from example

If Success Then
Log ("success Connect")
Do While Crsr.NextRow
X.MsgboxAsync(Crsr.getstring("cName"),"Testes")
Loop
Crsr.Close
Else
Log("failed")
End If
Catch
Success = False
Log(LastException)
End Try
CloseConnection
End If
Log("finished sub")
Return Success
this is a great problem

if you can't install any script/program in the server, you need to ask at server administrator if there are some API (or other) for to connect to database
Sorry, I don't see any other solution
let me put this to rest.

NOTHING CAN OR WILL BE INSTALLED ON SERVER

The system is off limits. It is a production system and if it goes down for any reason, remote system control goes down, point of sale systems go down, Security systems go down, Web site inquiry system goes down. so please just know that rule #2 is solid and in place because I deemed "DO NOT TOUCH THIS COMPUTER" and that includes me. This is a critical system and not one to screw around with. Nor to divert more resources for unnecessary scripting. Please stop asking to ignore that rule.

For those other ones confused I meant using jdbcSQL is what I am using. sorry for confusion there. I just need to get connection to mysql. in VS I wrote my own wrapper to provide easy access to mysql, in Linux Gambas I did the same thing. Now I have to do it in Android but still have to get connected to write the wrapper.
This is where I hit walls and large learning curves but so far this is the only thing eluding me.

I thank those here for the help, I just hope I find success in this.
 
Upvote 0

apti

Member
Can you post the full error in Logs?
the log on the side of the screen used to crash with red writing but it didn't tell me anything. Now it is passing ok but still no data and failure trying to get data after a successful connection. If there is more log please teach me where so I can fix this. It is holding up 3 projects.

Logger connected to: HOOZO HZ0010
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
Just in
Connecting <---- this shows it succeeded in connection
starting SELECT cName FROM Customers WHERE Custid ='SCL'
failed <---- this is result immediately after when trying to do above statement. now not connected? not sure.
finished sub
Completed. Success: false
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
the log on the side of the screen used to crash with red writing but it didn't tell me anything. Now it is passing ok but still no data and failure trying to get data after a successful connection. If there is more log please teach me where so I can fix this. It is holding up 3 projects.

Logger connected to: HOOZO HZ0010
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
Just in
Connecting <---- this shows it succeeded in connection
starting SELECT cName FROM Customers WHERE Custid ='SCL'
failed <---- this is result immediately after when trying to do above statement. now not connected? not sure.
finished sub
Completed. Success: false
Seems like you just having a bad query. Maybe you provide wrong column name or table name. The SQL engine and logs should give you a hint.
Try to execute other SQL e.g SELECT * FROM Customers LIMIT 1
 
Upvote 0

QSerg

Member
NOTHING CAN OR WILL BE INSTALLED ON SERVER

You do not need to shout. If you do not have access to given server you always can use other server/PC that in return talks to server in question. I tried to connect to MS SQL and found it way too cumbersome so I finished up with creation of my own service that my 4BA program communicate to and this service in return communicate to SQL server. Working like a charm
 
Upvote 0

DarkoT

Active Member
Licensed User
I am new to B4A but not to programming. I have been looking for how to connect to a mysql database from the app I write.

There is no code at this point because I am starting. I have looked into this but can't find quite what I need, or maybe can't understand it.

1 The mysql database is hosted on a linux server.
2 No changes can be made to the server, this includes adding software and scripts.
3 I need to connect to a mysql database using the username and password and IP address.
4 This will be simple queries and writing to database only.

Can somebody point a newbie into the right direction for this?
Hi, first of all - great decision to join our community. As a newcomer myself - some time ago - I found the B4X platform to be an incredibly significant and high-quality shift to a new logic, so I highly recommend it...

Regarding your question, while it's not the most ideal solution (my "pro" collegues in this forum would definitely advise against it), for starters - especially if you're developing an application that will only be used within the network where your MySQL server is hosted - you can use direct DB access via the JDBC driver.

The process is quite simple, and if you'd like, I can send you an example... This means that you can send a query directly from an Android phone or tablet to the MySQL database without needing an API server or any other component...
However, this solution is not viable if you want to use the device outside of the existing network... So, if you need an example, I can prepare and send it to you - documented, so it's clear for you as a newcomer on how to use the system...
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
The JdbcSQL library links contains an example in first post
 
Upvote 0

apti

Member
Hi, first of all - great decision to join our community. As a newcomer myself - some time ago - I found the B4X platform to be an incredibly significant and high-quality shift to a new logic, so I highly recommend it...

Regarding your question, while it's not the most ideal solution (my "pro" collegues in this forum would definitely advise against it), for starters - especially if you're developing an application that will only be used within the network where your MySQL server is hosted - you can use direct DB access via the JDBC driver.

The process is quite simple, and if you'd like, I can send you an example... This means that you can send a query directly from an Android phone or tablet to the MySQL database without needing an API server or any other component...
However, this solution is not viable if you want to use the device outside of the existing network... So, if you need an example, I can prepare and send it to you - documented, so it's clear for you as a newcomer on how to use the system...
Thank you thank you. You seem to have exactly what I seek. I am banging my head into walls trying to get something for MySql. What has been lacking is a working example and if you have it please please let me see. I am used to banging head into wall on programming problems just usually I solve them faster but B4A is new to me.

It seems "dumb" that we would have to install something on the server to use MySql. One of the most popular database systems on the planet. It is rare that a person would have access to a server to install things to make android stuff work. Solutions should never include making changes to other people's stuff. I should conform not them. That is how I was taught.

Just to be sure, the database used for this and a few others is actually Mariadb which is still MySql but hope not too many differences.

How do I get to see your magic code?
 
Upvote 0
Top