B4J Question SQL Connector connection string

tufanv

Expert
Licensed User
Longtime User
Hello,

According to https://www.b4x.com/android/forum/threads/sql-tutorial.35185/ this tutorial I downloaded the connector
added additionaljar and now I am trying to connect to database (local mysql database , because b4j app will run on the same serfver with mysql )

To connect tutorail says :

sql1.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test?characterEncoding=utf8")

my database name is admin_ahmet and username is admin_ahmet password is xxx

I tried :

B4X:
  Dim username,password As String
    username="admin_ahmet"
    password="xxx"
'    timerayarla
    sql1.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/admin_ahmet" &";user=" & username & ";password=" & password)

this returns me:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Where is my mistake ?

Thanks
 

tufanv

Expert
Licensed User
Longtime User
1. You should use Initialize2 and pass the username and password as parameters.
2. If it is a server solution then you should use ConnectionPool.

Are you testing it on the same computer that hosts the db server?
1) I tried it that way same error
2) you are right, I am testing it on my own pc instead of server, it would be hard to test on the vps , but I should use this method because finally the app will work on the vps not on my computer , is there an easier way to test with this method ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
you are right, I am testing it on my own pc instead of server, it would be hard to test on the vps , but I should use this method because finally the app will work on the vps not on my computer , is there an easier way to test with this method ?
It will never work if the url is not correct. You can put the server ip address instead of localhost. Make sure that the server firewall allows incoming connections on the relevant port.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
See this stackoverflow answer for items to check for this error message. Since both client and server are on the same machine I'm leaning towards MySQL not up and running or a port issue.
 
Upvote 0
Top