Android Question [resolt] Error mysql [SD_ResultSet]

ivanomonti

Expert
Licensed User
Longtime User
i have an error on mysql using the same SD_SQL library, I post the complete app code, I have no compile errors

code in B4XMainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private CustomListView_record_Aswar_true As CustomListView
    Private ProgressBar1 As B4XView
End Sub

Public Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frame1")
End Sub

Private Sub LoadRecord
    Dim query As String
    query = "SELECT * FROM ms_gpt.tb01 where ms_gpt_01_07='true' order by ms_gpt_01_06 desc;"
    LoadRecordTrueMysql(query)
End Sub

Sub LoadRecordTrueMysql(query As String) As Boolean
    
    Dim sd As sd_mysql
    sd.Initialize
    
    CustomListView_record_Aswar_true.Clear
    
    Dim rs As SD_ResultSet = sd.ExecQuery(query)
    
    If rs.IsInitialized=False Or rs = Null Then
        sd.Close
        Return False
    End If
    
    Dim ls As List
    ls.Initialize
    
    For i=0 To rs.ColumnCount-1
        ls.Add(rs.GetColumnName(i))
    Next
    
    Do While rs.NextRow
        Dim record As String
        For i=0 To ls.Size-1
            record =  rs.GetString2(0) & "/" &  rs.GetString2(1) & "/" &  rs.GetString2(2) & CRLF & CRLF & rs.GetString2(3) & CRLF & CRLF & rs.GetString2(4) & CRLF & CRLF & rs.GetString2(5)
        Next
        CustomListView_record_Aswar_true.AddTextItem(record,record)
    Loop
    
    rs.Close
    sd.Close
    
    ProgressBar1.Visible=False
    
    Return True
    
End Sub

Classe sd_mysql:
Sub Class_Globals
    Dim MYSQL As SD_SQL
    Private MyLocation As String = "127.0.0.1:3306"
    Private MyScheme As String = "xxxxxxx"
    Private MyUsername As String = "xxxxxxxxxxx"
    Private MyPassword As String = "xxxxxxxxxxxxxxxxxxxxxxxx"
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    
End Sub

Private Sub InitializeMySql
    MYSQL.Initialize(Me,"MYSQL", "com.mysql.jdbc.Driver", $"jdbc:mysql://${MyLocation}/${MyScheme}?useSSL=false"$,  MyUsername, MyPassword)
End Sub

public Sub ExecNonQuery(query As String)
    If MYSQL.IsInitialized = False Then
        InitializeMySql
    End If
    Try
        If MYSQL.ExecNonQuery(query) = False Then
            MYSQL.Close
        End If
    Catch
        Log(LastException)
    End Try
End Sub

public Sub ExecQuery(Query As String) As SD_ResultSet
    If MYSQL.IsInitialized = False Then
        InitializeMySql
    End If
    Return MYSQL.ExecQuery(Query)
End Sub

Sub Close
    MYSQL.Close
End Sub



error:
Logger connesso a:  samsung SM-A105FN

Not connected: 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.
Query Error: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.PreparedStatement java.sql.Connection.prepareStatement(java.lang.String)' on a null object reference

Error occurred on line: 49 (SD_ResultSet)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:259)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at MIASmart.socialAI.sd_resultset._getcolumncount(sd_resultset.java:120)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at MIASmart.socialAI.b4xmainpage._b4xpage_created(b4xmainpage.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
    at MIASmart.socialAI.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1070)
    at MIASmart.socialAI.b4xpagesmanager._showpage(b4xpagesmanager.java:427)
    at MIASmart.socialAI.b4xpagesmanager._addpage(b4xpagesmanager.java:247)
    at MIASmart.socialAI.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:261)
    at MIASmart.socialAI.b4xpagesmanager._initialize(b4xpagesmanager.java:167)
    at MIASmart.socialAI.main._activity_create(main.java:418)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at MIASmart.socialAI.main.afterFirstLayout(main.java:105)
    at MIASmart.socialAI.main.access$000(main.java:17)
    at MIASmart.socialAI.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8625)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
Service started in the background. Trying to start again in foreground mode.
*** Service (starter) Create ***
** Service (starter) Start **
Service started in foreground mode.
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
** Activity (main) Resume **
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…