B4A Library MySQL Library with jdbc

Hello everyone,

This is my second library very similiar to MSSQL.


There are only three functions.

1) setDatabase("Server IPNUMBER (not name)","databasename","username","password")
2) Query("select * from tablename") --> return rows as a LIST
3) TableList --> return table names rows as a LIST.

You can also write create, update or delete queries.
You must copy MYSQL.jar, MYSQL.xml files to your addititonal library folder.

You should download jdbc driver from Mysql site:
Download jdbc driver

After you must copy mysql-connector-java-5.1.22-bin.jar file to your additional library folder.

You must add Manifest
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_NETWORK_S TATE")​

Maybe you need to allow access to MySQL;

mysql> grant all privileges on *.* to root@'%' with grant option;
you can change username root to another one.


Using

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim a As MYSQL
   Dim L As List
   Dim hsv As HorizontalScrollView   
   Dim svRows As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)

   'write your own parameters
   'a.setDatabase("server ipnumber (not name)","databasename","username","password")  'Cancel this line
   'you can write named server
   a.setDatabase("server ipnumber or url","databasename","username","password")

   ' select query
   '    L=a.Query("select * from tb_Test")
   ' or get table list for database
      L = a.TableList  'you can get all tables for default database

   ' CUD: Create, Update, Delete
   ' or UPDATE query
   '   Dim r as Int        ' return affected rows count
   '   r = a.ExecuteNonQuery("update tablename set fieldname='xxxx' where keyname='xx'; ")    
   
   If L.IsInitialized=False Then
      Msgbox("Records Not Found","Warning")
      Return
   End If
   
   Dim row As List,cols As Int   ,rows As Int
   rows = L.Size   
   row = L.Get(0)  'Header row
   cols = row.Size

   hsv.Initialize(cols*150dip,0)
   Activity.AddView(hsv,0,0,100%x,100%y)

   svRows.Initialize(rows*30dip)
   hsv.Panel.AddView(svRows,0,30dip,cols*150dip,100%y-30dip)
   
   'CREATE HEADER LABELS
   For j=0 To cols-1
      hsv.Panel.AddView(LabelCreate(row.Get(j),Colors.DarkGray,Colors.White) _
                   ,j*150dip   _
                   ,0         _
                   ,149dip   _
                   ,29dip)
   Next
   
   'CREATE RECORD LABELS
   For i=1 To L.Size-1
      row = L.Get(i)
      For j=0 To cols-1
         svRows.Panel.AddView( LabelCreate(row.Get(j),Colors.LightGray,Colors.Black) _
                         ,j*150dip      _
                         ,i*30dip-30dip _
                         ,149dip        _
                         ,29dip)
      Next
   Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub LabelCreate(str As String,backcolor As Int,textcolor As Int) As Label
   Dim t As Label
   t.Initialize(0)
   t.text=" " & str
   t.color=backcolor
   t.textcolor=textcolor
   t.Gravity = Gravity.CENTER_VERTICAL
   Return t
End Sub
I wish to be useful.

Note:
Be carefully working with databases, responsibility for problems caused by this library is yours.

This library userfull 'in firm' applications.
Because MySQL IPNumber should be accessible through the network.

I'm canceling this red-colored description. You can connect if Mysql server accessible anywhere.
 

Attachments

  • mysql_Library_1.0.zip
    4.6 KB · Views: 1,287
  • MYSQL_Library_1.01.zip
    4.7 KB · Views: 2,028
Last edited:

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Here
 

Attachments

  • MySql.zip
    13.1 KB · Views: 393

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Ok, I'm stupid :oops::oops:.

Thanks!
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Thanks.
Right now, I have only to change the string "a.SetDatabase" with my params, the line L = a.Query("") and I should retrieve some records?
 

Croïd

Active Member
Licensed User
Longtime User
Please hasanaydin52

I need to change my manifest with

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="22"/> ( Work only mode Debug)


but library works (Mode Release & Debug) only if my manifest is on

B4X:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>

how I can work around the error ?
 

Attachments

  • errorM.png
    errorM.png
    19.7 KB · Views: 227

Ricardo Gonzalez Gaete

Member
Licensed User
Longtime User
for MYSQL library, I need to find text matches within the customer name, this well use it well, l same vb6 or net.

I query returns no records, no result

L = a.Query ( "SELECT CLIE_PROV, RUT_CLPR FROM WHERE BD_CLPR CLIE_PROV = '%" & xClie & "%")

If anyone can help me appreciate
 

Nagy Lajos

New Member
Licensed User
B4X:
Sub sLekerdez(csql As String) As Int
    Dim mcc As List
    Dim mi As Boolean = False
    Main.mqret=0
    mcc.Initialize
    mcc=Main.sdb.Query(csql)
    Msgbox(mcc.IsInitialized,"L0")
    If mcc.Size>1 Then
        mresult3=mcc.Get(1)
    End If
    mi=mresult3.IsInitialized
    If mi Then
        Main.mqret=mcc.Size
    End If
    Return Main.mqret
End Sub
This is my code. The mcc is not initialized for release, but running correct in debug mode. Please help me!
 
Top