B4A Library Yet Another MySQL Library But With Stored Procedure Support and Cursors

There has been a bit discussion lately about stored procedures both on the B4A and B4J bits of the forum so I thought I would post a library which supports stored procedures with IN,OUT and INOUT parameters and also supports procedures which return multiple result sets.

The sample code below uses the sample database from www.MySQLTutorial.org. You need to download the MySQL Connector/J JDBC driver mysql-connector-java-5.1.34-bin.jar from the MySQL Website and put it in your additional libraries folder and download the zip file at the bottom of the page and place the .jar and .xml files and put them in your additional libraries folder

Sample Code
B4X:
Sub Process_Globals

    Dim MYSQLIP = "172.25.0.44" As String
    Dim MYSQLDBNAME = "classicmodels"  As String
    Dim MYSQLPORT = "3306"  As String
    Dim MYSQLUSER = "******"  As String
    Dim MySQLPASS = "*****"  As String
    Dim MySQLConnection As MySQLConnector
    Dim MYSQLProcedure As CallProc

End Sub

Sub Globals

End Sub


Sub Activity_Create(FirstTime As Boolean)
     If FirstTime Then
            MySQLConnection.Initialize(MYSQLIP,MYSQLDBNAME,MYSQLUSER, MySQLPASS,MYSQLPORT)
    End If

    'return query as cursor
    MySQLConnection.ExecQuery("query","select * from products")
    'Batch updates into a transaction
    MySQLConnection.AddNonQueryToBatch("UPDATE products SET quantityInStock = 123 where productCode = 'S12_1099'")
    MySQLConnection.AddNonQueryToBatch("UPDATE products SET buyPrice = 60 where productCode = 'S700_3167'")
    MySQLConnection.ExecuteNonQueryBatch("updateproducts")
    'Will Cause an Error
    MySQLConnection.ExecQuery("query","select * from products")
    'Singl update
    MySQLConnection.ExecNonQuery("updateSingle","UPDATE products SET MSRP = 82 where productCode = 'S700_3167'")

    'Delcare Called Procedure
    Dim MYSQLProcedure As CallProc

    'Set the procedure to call
    MYSQLProcedure.ProcedureCall = "call getorder(?, ?)"
    'Register Input Parameters
    MYSQLProcedure.AddInputParameter(1,MYSQLProcedure.SQLINTEGER,"10100")
    MYSQLProcedure.AddInputParameter(2,MYSQLProcedure.SQLINTEGER,"1")
    'Register Output Parameters
    MYSQLProcedure.AddOutputParameter(2,MYSQLProcedure.SQLINTEGER)
    'Add Call back subs
    '0 is always for the parameter sub
    MYSQLProcedure.AddCallSub(0,"params")
    '1 for the first result set returned
    MYSQLProcedure.AddCallSub(1,"orderheader")
    '2 for the second result set returned
    MYSQLProcedure.AddCallSub(2,"orderlines")
    'Run the procedure
    'proctest is the sub for general error capture reporting
    MySQLConnection.ExecProcedure("proctest",MYSQLProcedure)



End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub query_complete(c As MySQLCursor)
    'CursorToLog(c)

End Sub


Sub query_error(trace  As String )
     Log(trace)
End Sub


Sub updateProducts_complete(UpdateCount As Int)
    Log(UpdateCount)

End Sub

Sub updateProducts_error(trace As String)
    Log(trace)

End Sub

Sub params_parameters(m As Map)
   If m.ContainsKey(2) Then
      Log("Out Parameter 2 =" & m.Get(2))
   End If


End Sub
Sub orderheader_complete(c As MySQLCursor )
  CursorToLog(c)

End Sub

Sub orderlines_complete(c As MySQLCursor )
     CursorToLog(c)
End Sub
Sub proctest_error(trace As String)
  Log(trace)
End Sub

Sub CursorToLog(c As MySQLCursor)

For RowCounter = 0 To c.GetRowCount -1
    Log("")
    Log("Row: " & RowCounter)
    c.Position = RowCounter
    For ColumnCounter = 0 To c.GetColumnCount -1
   
        Log(c.GetColumnName(ColumnCounter) & ":" & c.GetString2(ColumnCounter))
   

    Next
Next



End Sub


Sub query_update(product As Map)
  If product.ContainsKey("productName") Then
          Log(product.get("productName"))
   End If


End Sub
Sub updatesingle_complete(updatecount As Int)
  Log(updatecount)
End Sub

I have added two stored procedures to the sample DB. The first is getorder.

B4X:
    CREATE` PROCEDURE `getorder`(IN ordernumber integer,INOUT acounter integer)
    BEGIN

    select * from orders where orders.ordernumber = ordernumber;
    select * from orderdetails where orderdetails.ordernumber = ordernumber order by orderLineNumber;
    set acounter = acounter + 1;

    END

This procedure is passed two parameters and returns one parameter and two result sets. Taking the sample code step by step:

B4X:
Dim MySQLConnection As MySQLConnector
Dim MYSQLProcedure As CallProc

Declare a connection object and a CallProc object used to configure a stored procedure.

B4X:
MYSQLProcedure.ProcedureCall = "call getorder(?, ?)"

Tell the Callproc object what stored procedure to call.

B4X:
'Register Input Parameters
MYSQLProcedure.AddInputParameter(1,MYSQLProcedure.SQLINTEGER,"10100")
MYSQLProcedure.AddInputParameter(2,MYSQLProcedure.SQLINTEGER,"1")

Tells the Callproc object the value of the input parameters.

The first parameter of AddInputParameter is the number of the parameter being passed. So 1 is ordernumber in the called procedure and 2 is acounter.

The second parameter of AddInputParameter is the SQL Type of the parameter. In this case both are integers.

The third parameter of AddInputParameter is the value of the parameter. Values are always passed as strings and conversion to the correct SQL Type is performed internally by the library.

B4X:
'Register Output Parameters
MYSQLProcedure.AddOutputParameter(2,MYSQLProcedure.SQLINTEGER)

Tells the CallProc object what output parameters are expected.

In the case of the getorder procedure the second parameter is an INOUT parameter so has to be registered as both an input parameter and an output parameter.

The first Parameter for AddOutputParameter is the number of the parameter being returned.

The second parameter is the SQL Type of the stored procedure parameter.

B4X:
'Add Call back subs
'0 is always for the parameter sub
MYSQLProcedure.AddCallSub(0,"params")
'1 for the first result set returned
MYSQLProcedure.AddCallSub(1,"orderheader")
  '2 for the second result set returned
MYSQLProcedure.AddCallSub(2,"orderlines")

AddCallSub is used to tell the library what sub stub to use for each result set. 0 is used to denote the sub stub for parameters.

In this example params_parameters is passed a Map of the returned parameter values.
orderheader_complete is used to pass the the cursor resulting from 'select * from orders where orders.ordernumber = ordernumber' query and orderlines_complete is used to return the cursor resulting form the 'select * from orderdetails where orderdetails.ordernumber = ordernumber order by orderLineNumber' query.



B4X:
'Run the procedure
'proctest is the sub for general error capture reporting
MySQLConnection.ExecProcedure("proctest",MYSQLProcedure)

Finally run the procedure. A general sub stub is used for error reporting. In this case "proctest_error".


Result sets are returned as memory backed Android cursors (MySQLCursor) so you should be careful about how big a result set is returned. SQL types are translated to the native SQLite types so boolean values are integers for example. DATE, TIMESTAMP and TIME types are returned as strings.

For the MAP returned for the stored procedure parameters the native B4A types are generally used for numbers with the the exception of the DECIMAL and NUMERIC types which are returned as strings.

There are bound to be bugs in this library as it's a stripped out subset of a much bigger library.



This library is free for non commercial use and for use within a commercial organization. Any use for distributing monetized apps be it by direct payment, advertising or anything else is strictly prohibited.



 

Attachments

  • MYSQLLIB.zip
    14.9 KB · Views: 506
  • MYSQLLIB fixed.zip
    15.5 KB · Views: 617
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
A MySQL lib with 100% support for Stored Procedures too.

Thank you for this lib.

Regards
Anser
 

ludogomez

Member
Licensed User
Longtime User
Hi,

I want to use your library, it works well with Android 4.4.2 but with Android 4.0.X it doesn't work :

I make "MySQLConnection.ExecQuery" for "SELECT" and I don't have response in query_complete.
But if I use "MySQLConnection.ExecQuery" it works with "UPDATE".

Can I have some help ?

I have this error if I remove the filter on the log tab :


Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x016a
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x017f
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0191
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x01a4
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x01b7
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x01ca
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x01dd
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x01f0
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0204
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0218
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x022c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run

VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x023c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x024c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x025c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x026c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x027c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x028c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x029c
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x02ac
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x02bc
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x02cc
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x02e0
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x02f4
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0304
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run

VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0314
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0324
Could not find method android.database.MatrixCursor$RowBuilder.add, referenced from method db.b4Amysql.e.run
VFY: unable to resolve virtual method 141: Landroid/database/MatrixCursor$RowBuilder;.add (Ljava/lang/String;Ljava/lang/Object;)Landroid/database/MatrixCursor$RowBuilder;
VFY: replacing opcode 0x6e at 0x0334



Thanks,

Best regards
 
Last edited:

keirS

Well-Known Member
Licensed User
Longtime User
OK it's fixed now. Re download the zip as I have replaced the original with the fixed version. I have tested it on 4.0 and 2.3.3 and it works on both.
 
Last edited:

FabioG

Active Member
Licensed User
Longtime User
Great Library!
But I did not understand how to get the result of a query, you can write a complete example?

Thanks very much!
 

keirS

Well-Known Member
Licensed User
Longtime User
Great Library!
But I did not understand how to get the result of a query, you can write a complete example?

Thanks very much!

It's in the example above.

B4X:
MySQLConnection.ExecQuery("query","select * from products")

This calls the query. The first parameter is the stub of the subs where the results or an error is returned.

B4X:
Sub query_complete(c As MySQLCursor)
    CursorToLog(c)
End Sub

This sub is called if the query is complete and returns a cursor containing the query results. It works pretty much like an SQLite cursor.

B4X:
Sub query_error(trace As String )
Log(trace)
End Sub


This sub is called if an error occurs.
 

FabioG

Active Member
Licensed User
Longtime User
It's in the example above.

B4X:
MySQLConnection.ExecQuery("query","select * from products")

This calls the query. The first parameter is the stub of the subs where the results or an error is returned.

B4X:
Sub query_complete(c As MySQLCursor)
    CursorToLog(c)
End Sub

This sub is called if the query is complete and returns a cursor containing the query results. It works pretty much like an SQLite cursor.

B4X:
Sub query_error(trace As String )
Log(trace)
End Sub


This sub is called if an error occurs.

Thanks very much!
 

ludogomez

Member
Licensed User
Longtime User
Hi,

I test your fix, It's better, but now when I make a SELECT, I have nothing in complete but I have this trace on error :

android.database.CursorIndexOutOfBoundsException: No more columns left.

at android.database.MatrixCursor$RowBuilder.add(MatrixCursor.java:206)
at db.b4Amysql.e.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

Thanks

best regards
 

keirS

Well-Known Member
Licensed User
Longtime User
Hi,

I test your fix, It's better, but now when I make a SELECT, I have nothing in complete but I have this trace on error :

android.database.CursorIndexOutOfBoundsException: No more columns left.

at android.database.MatrixCursor$RowBuilder.add(MatrixCursor.java:206)
at db.b4Amysql.e.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

Thanks

best regards

Is this from the sample DB or your own select?
 

ludogomez

Member
Licensed User
Longtime User
IT's from my database. Yesterday this "SELECT" work very well. And today, with android 4.4.2 or 4.0.4 I have the same behaviour.
 

ludogomez

Member
Licensed User
Longtime User
IT's from my database. Yesterday this "SELECT" work very well. And today, with android 4.4.2 or 4.0.4 I have the same behaviour.
Hi,

it work for one table : good.png
good.png


it don't work for another table : nogood.png

nogood.png


I don't understand why.

thanks

Best regards
 

ludogomez

Member
Licensed User
Longtime User
Hi,

I test with a simple project and it works with your another library mariadb.

Thanks,
Best regards

PS : if you find a solution, it will good, but if it isn't possible I change my project to use mariadb.
 
Last edited:

keirS

Well-Known Member
Licensed User
Longtime User
Hi,

I test with a simple project and it works with your another library mariadb.

Thanks,
Best regards

PS : if you find a solution, it will good, but if it isn't possible I change my project to use mariadb.

It should be fixed now. Download the MYSQL fixed.zip from the first post. The reason the one table worked and the other didn't is the TINYINT wasn't being mapped to the cursor properly.
 
Last edited:

FabioG

Active Member
Licensed User
Longtime User
everything works fine
but when I go out from the app
and after a while I open the app again
it does not work
I get this error

B4X:
Error: java.sql.SQLException: The url cannot be null


    at java.sql.DriverManager.getConnection(DriverManager.java:170)
    at java.sql.DriverManager.getConnection(DriverManager.java:213)
    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
Error: java.lang.NullPointerException


    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)

how can I fix this?

this is a part of my code

B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    SettingsLoad

    If FirstTime = True Then      
        MySql.Initialize(IP,"DomoRF433",UserName,PWD,Port)
    End If

    DBQueryAll

End Sub

Sub Activity_Resume
  
    If MySql.IsInitalized = False Then
        SettingsLoad
        MySql.Initialize(IP,"DomoRF433",UserName,PWD,Port)
        Log("Open DB")
    End If
   
    DBQueryAll
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

keirS

Well-Known Member
Licensed User
Longtime User
everything works fine
but when I go out from the app
and after a while I open the app again
it does not work
I get this error

<SNIP>
B4X:
Sub Activity_Resume
 
    If MySql.IsInitalized = False Then
        SettingsLoad
        MySql.Initialize(IP,"DomoRF433",UserName,PWD,Port)
        Log("Open DB")
    End If
  
    DBQueryAll
 
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Try this in your activity resume Activity resume. I assume MySql is declared in Process_Globals?

B4X:
Sub Activity_Resume
    SettingsLoad
    MySql. = Null
    Dim MySQL As MySQLConnector
    MySql.Initialize(IP,"DomoRF433",UserName,PWD,Port)
End Sub
 

FabioG

Active Member
Licensed User
Longtime User
same result :(

B4X:
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **

Error: java.sql.SQLException: The url cannot be null


    at java.sql.DriverManager.getConnection(DriverManager.java:170)
    at java.sql.DriverManager.getConnection(DriverManager.java:213)
    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
Error: java.lang.NullPointerException


    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
 

keirS

Well-Known Member
Licensed User
Longtime User
same result :(

B4X:
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **

Error: java.sql.SQLException: The url cannot be null


    at java.sql.DriverManager.getConnection(DriverManager.java:170)
    at java.sql.DriverManager.getConnection(DriverManager.java:213)
    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
Error: java.lang.NullPointerException


    at db.b4Amysql.e.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)

Ok well the URL is made up of "jdbc:mysql://" + IP + ":" + Port + "/" + dbName . So check all of these actually have values in them in the Activity Resume.
 

FabioG

Active Member
Licensed User
Longtime User
excuse me, I have found the problem
I moved "Dim MySql As MySQLConnector", from "Globals" in "Process_Globals"

Thanks!
 
Last edited:
Top