B4A Library MySQL Library

MySQL Library for Android

With this library you can now connect directly your Android apps to any mysql database server

Setup

- Download the attached library and copy all three files to the libraries folder.

Example

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim mh1 As MysqlHandler
   Dim rs1 As ResultSet

   Dim sv1 As ScrollView
   Dim lv1 As ListView
   Dim hsv1 As HorizontalScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   
   mh1.Initialize("ip.mysql.server[:port]","db_name","db_user","db_password")
   If mh1.isConnected = False Then
      Msgbox(mh1.SQLError, "Connection Error:")
      Return
   End If
   
   rs1 = mh1.Query("SELECT * FROM table_name")
   If rs1.IsInitialized = False Then
      Msgbox("ResultSet is empty" & CRLF & mh1.SQLError, "Warning")
      Return
   End If
   
   hsv1.Initialize(rs1.ColumnCount * 150dip,0)
   Activity.AddView(hsv1,0,0,100%x,100%y)
   
   sv1.Initialize(rs1.RowCount * 30dip)
   hsv1.Panel.AddView(sv1,0,0,rs1.ColumnCount*150dip,100%y)

   Dim l As Label
   
   For i=0 To rs1.RowCount - 1
      rs1.Position = i
      For j=0 To rs1.ColumnCount - 1
         l.Initialize("label" & j)
         l.Text = rs1.GetString(j)
         l.TextColor = Colors.Black
         l.Color = Colors.White
         sv1.Panel.AddView(l,j*150dip,i*30dip,149dip,29dip)
      Next
   Next
   mh1.Close
End Sub

MySQL_1.01.zip
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
There is already a lib by Hasanyadin52 for MySQL:
1 How different yours is from Hasan's lib?
2. It uses the same jar and xml files. Can the names be changed so not to overwrite his?
3. Will there be a conflict if I include both in the additional lib folder.
4. What are the commands examples for INSERT, DELETE, UPDATE, etc. other than SELECT.
5. Hasan' lib works well, but uses a lot of memry. Does yours use less?
Thank you for deciphering the differences for us.
 

mosix

Member
Hasan had looked the code that i've posted some year ago

Hello yawmbox,


I added MySQL Library.
I wrote looking at your java code.
MYSQL Library

I initially wrote on the forum with the username of another person, just yawmbox

I'm working on this library to add transactions and other essential functions, and to make it as similar as possible to the SQL library of Erel
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Thanks for the library,

I am unable to get a connection. i can get a connection using php though

The code i am using is this. i think mabe i do not understand the syntax
B4X:
mh1.Initialize("www.urladdress:2020","db_name","db_user","db_password")

The error i get is java.sql.SQLException: Must specify port after ':' in connection string

I have tried the following

B4X:
mh1.Initialize("xx.xxx.xxx.xx:3306","db_name","db_user","db_password")

still no good but in a dos box this gives me a connection

mysql -h xx.xxx.xxx.xx -u db_user -p db_password
 
Last edited:

MaxApps

Active Member
Licensed User
Longtime User
Similar problem here.
I get:
com.mysql.jdbc.exceptions.
: Communications link failure

Kind regards
Jakob
 

billyrudi

Active Member
Licensed User
Longtime User
hi to all
this library work i you put in android manifest sdk version to 8?
there is a way to have a version that work with sdk 14 ? regards
 

swamisantosh

Member
Licensed User
Longtime User
MySQL Library for Android

With this library you can now connect directly your Android apps to any mysql database server

Setup

- Download the attached library and copy all three files to the libraries folder.

Example

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim mh1 As MysqlHandler
   Dim rs1 As ResultSet

   Dim sv1 As ScrollView
   Dim lv1 As ListView
   Dim hsv1 As HorizontalScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
  
   mh1.Initialize("ip.mysql.server[:port]","db_name","db_user","db_password")
   If mh1.isConnected = False Then
      Msgbox(mh1.SQLError, "Connection Error:")
      Return
   End If
  
   rs1 = mh1.Query("SELECT * FROM table_name")
   If rs1.IsInitialized = False Then
      Msgbox("ResultSet is empty" & CRLF & mh1.SQLError, "Warning")
      Return
   End If
  
   hsv1.Initialize(rs1.ColumnCount * 150dip,0)
   Activity.AddView(hsv1,0,0,100%x,100%y)
  
   sv1.Initialize(rs1.RowCount * 30dip)
   hsv1.Panel.AddView(sv1,0,0,rs1.ColumnCount*150dip,100%y)

   Dim l As Label
  
   For i=0 To rs1.RowCount - 1
      rs1.Position = i
      For j=0 To rs1.ColumnCount - 1
         l.Initialize("label" & j)
         l.Text = rs1.GetString(j)
         l.TextColor = Colors.Black
         l.Color = Colors.White
         sv1.Panel.AddView(l,j*150dip,i*30dip,149dip,29dip)
      Next
   Next
   mh1.Close
End Sub

MySQL_1.01.zip
Hello Sir I'm unable to connect to mysql database
Error
SQLERROR :
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.
DB=null
URL=jdbc:mysql://SMS-PC:3306/scm_db,user=root,pass=root

if try to connect with URL 192.168.1.104:3306,

Kindly help me in this regard
 

yawmbox

Member
Licensed User
Longtime User
Hello Sir I'm unable to connect to mysql database
Error
SQLERROR :
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.
DB=null
URL=jdbc:mysql://SMS-PC:3306/scm_db,user=root,pass=root

if try to connect with URL 192.168.1.104:3306,

Kindly help me in this regard

Mosix forgot to say that you must configure your maifest with minsdk=8, otherwise the connection is not possible for reasons that we still have not managed to find.
 

librettista

Member
Licensed User
Longtime User
The insert and delete operations can be performed via the .exec method.

I've fully completed a small project that writes on a MySQL table, but only works in "debug" mode. When in release, this error is displayed:
"com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server"

Same program in debug mode reads and writes to database with no problem. Any hint ?
 

shaxboz

Member
Licensed User
Longtime User
Hi! I cannot connect with this library.
I get error "access denied to [email protected]"
213.208.72.56 - is not my db ip address, it is my local ip address. It want to connect to my ADSL modem :)
 

luismora

New Member
Licensed User
Longtime User
In debugging works fine, but no final version.
what I did is change manifest project and it worked. Because it does not really work out. Any idea?

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
to
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4"/>
 
Top