Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("2") Activity.Title="NBS Morena Srl" attivo=0 png1.Initialize(LoadBitmap(File.DirAssets, "LogoBigMorena.png")) Logo.Background=png1 nrdev=p.GetSettings("android_id") macDisp.Text=nrdev modello = p.Manufacturer & " " & p.Model & " " & p.GetSimOperator Label1.Text = modello StartActivity(MariaDB) If attivo=0 Then ToastMessageShow("Device not allowed",True) Activity.Finish End If '
Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim MYSQLIP = "xxx.xxx.xxx.xxx" As String Dim MYSQLDBNAME = "xxxxxxxx" As String Dim MYSQLPORT = "0000" As String Dim MYSQLUSER = "xxx" As String Dim MySQLPASS = "xxxxxxx" As String Dim MySQLConnection As MariaDBConnector Dim vuoto,vuoto3,vuoto2,vuoto4 As Boolean Dim vettura As Int Dim annop As Int,ngiro As Int,nrdev3 As String,idvettura As Int Dim ora As String 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. 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") Activity.Color=Colors.Transparent If MySQLConnection.IsInitalized =False Then MySQLConnection.Initialize(MYSQLIP,MYSQLDBNAME,MYSQLUSER, MySQLPASS,MYSQLPORT) End If ' DateTime.DateFormat="yyyy" annop=DateTime.Date(DateTime.Now) DateTime.DateFormat="yyMMdd" ngiro=DateTime.Date(DateTime.Now) DateTime.DateFormat="yyyy-MM-dd" ' Log("data1 cerca " & DateTime.Date(DateTime.Now)) ' vuoto3=True nrdev3 = Main.nrdev MySQLConnection.ExecQuery("query3","select * from vetture where mcaddr='" & nrdev3 & "'" ) End Sub Sub Activity_Resume Log(" MariaDB resume") 'StartActivity(MariaDB2) End Sub Sub Activity_Pause (UserClosed As Boolean) Log(" MariaDB in pausa") 'StartActivity(Main) 'Activity.Finish End Sub Sub query3_complete(finished1 As Boolean) Dim ora As String Log("query3 complete " & finished1) If vuoto3=True Then MySQLConnection.ExecNonQuery("query2","insert into vetture (mcaddr,nomevettura) select '" & nrdev3 & "','" & "Camion " & nrdev3 & "'") End If Activity.Finish 'StartActivity(MariaDB2) End Sub Sub query3_update(product1 As Map) Log("query3 update " & product1.Get("idvettura")) Main.attivo=product1.Get("attivo") idvettura=product1.Get("idvettura") Main.Nrvett=idvettura vuoto3=False End Sub Sub query3_error(trace1 As String) Log("Errore query3: " & trace1) End Sub
Thank you Peter, sorry for my delay but was very busy, asap i'll test your suggestions and let you know.Hello @RenewMe
I've created an example for you that I hope others will also find useful and simple enough to figure out.
Btw you don't need to create query1, query2, query3 etc etc etc, just query will do. Here is a quick example (not tested in B4A but should work) that should get you started. Put the .jar file in your additional libraries folder and adjust the code to meet your needs.
I've attached MariaDB ConnectorJ V1.1.8 as that was the version number that popped into my head. I know that MariaDB ConnectorJ V1.1.8 works perfect with JdbcSQL, actually you can use up to and including MariaDB ConnectorJ V2.0.3 with absolutely no issues whatsoever in B4A. DO NOT USE MariaDB ConnectorJ 2.1.x and above in B4A as they cause B4A build errors. If you need to use 'useSSL' in your connection string, you can download MariaDB ConnectorJ V2.0.3 as B4A works perfect with ConnectorJ V2.0.3 and 'useSSL'.