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:

keirS

Well-Known Member
Licensed User
Longtime User
If you must access MySQL directly you could try my MySQL library. It's asynchronous so doesn't run on the main thread and so will work with higher API levels. If you are writing an app for release on the Play Store though you should follow Erel's advice as it doesn't support SSL or X.509 so is not secure.
 

leonardo pino

Member
Licensed User
Longtime User
Hi, I have a Problem, after instalation, com.mysql.jdbc.exceptions.jdbc4.MysqlNonTransientConnectionException:Could not create connection to database server, I use this code:
mh1.Initialize("www.page.com.co:3306","db_registro","db_user1","password")
Thanks,
 

DonManfred

Expert
Licensed User
Longtime User

keirS

Well-Known Member
Licensed User
Longtime User
Unless you want to pay Oracle a fee for a commercial licence you should avoid using any library that uses Connector/J the "official" MySQL JDBC driver because:

Oracle Website said:
Q3: As a commercial OEM, ISV or VAR, when should I purchase a commercial license for MySQL software?
A: OEMs, ISVs and VARs that want the benefits of embedding commercial binaries of MySQL software in their commercial applications but do not want to be subject to the GPL and do not want to release the source code for their proprietary applications should purchase a commercial license from Oracle. Purchasing a commercial license means that the GPL does not apply, and a commercial license includes the assurances that distributors typically find in commercial distribution agreements.[/quote[

Taken from Here.

If you are writing free software and are willing to apply the GPL then you are fine. But if you are monetizing your application in any way and want to use Connector/J in your app then talk to Oracle. It's not cheap (I was quoted around $9000 USD a couple of years ago).
 

M.LAZ

Active Member
Licensed User
Longtime User
hi mosix,,,
could u add this charset parameter to ur connection string
mh1.Initialize("ip.mysql.server[:port]","db_name","db_user","db_password")
add new parameter:

mh1.Initialize("ip.mysql.server[:port]","db_name","db_user","db_password","UTF-8") to support multilingual charset ,,, UTF-8 or
utf8mb4_general_ci

Erel said that we must not use direct credetials data in our apps ,,, but my usage in my app is not an important data

this will help alot.. thank u so much....
 
Top