B4J Question Problem with Resultset in Mssql

I have a problem with this code
Sub connectiontoSQL
sql.InitializeAsync("MSSQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/${DatabaseName}"$, DBUsername, DBPassword)
End Sub

Sub MSSQL_Ready (Success As Boolean)
Log(Success)
If Success Then
readFrompazireshCount
Else
Log("!OK")
End If

End Sub

Sub readFrompazireshCount As String
connectiontoSQL
Dim Cursor As ResultSet=sql.ExecQuery("select * from paziresh")
Dim lblcods As Int=1
Do While Cursor.NextRow
lblcods=Cursor.GetString2(0)
Loop
Cursor.Close
Close
Return lblcods
End Sub

Sub Close
sql.Close
End Sub​
show me this error ?What should I do?
Waiting for debugger to connect...
Program started.
Error occurred on line: 60 (CodeBase)
java.lang.RuntimeException: Object should first be initialized.
at anywheresoftware.b4j.objects.SQL.checkNull(SQL.java:136)
at anywheresoftware.b4j.objects.SQL.ExecQuery(SQL.java:352)
at b4j.example.codebase._readfrompazireshcount(codebase.java:77)
at b4j.example.information_ac._show(information_ac.java:176)
at b4j.example.mainform_ac._lblsabtename_mouseclicked(mainform_ac.java:558)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:109)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
lblCode.Text=readFrompazireshCount
 
Last edited:

aeric

Expert
Licensed User
Longtime User
B4X:
Wait For (ConnectiontoSQL) Complete (Success As Boolean)
If Success Then
    lblCode.Text = ReadFromPazireshCount
End If

Sub ConnectiontoSQL As ResumableSub
    SQL1.InitializeAsync("MSSQL", "net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/${DatabaseName}"$, DBUsername, DBPassword)
    Wait For MSSQL_Ready (Success As Boolean)
    Log(Success)
    If Success = False Then
        Log(LastException)
        Return False
    End If
    Return True
End Sub

Sub ReadFromPazireshCount As String
    Dim value As String
    Dim rs As ResultSet = SQL1.ExecQuery("SELECT * FROM paziresh")
    Do While rs.NextRow
        value = rs.GetString2(0)
    Loop
    rs.Close
    Return value
End Sub
 
Upvote 0
Top