Android Question Count Rows in JdbcResultSet

Pantelis Loizou

Member
Licensed User
Longtime User
Hi gyus

Stupid question but i am stuck. how can i find how many rows returns the query? i want to proceed with the loop only if the result's row are greater to 0. otherwise display message such as NO RECORDS FOUND
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I don't think you can get a record count, but you can use NextRow to determine if there are records or not - so:
B4X:
Dim RS As ResultSet = sqlServer.ExecQuery("SELECT ...")
Do While RS.NextRow
   'process query results
Loop
RS.Close

If you really want a record count first, you could run a SELECT COUNT() query on an ExecQuerySingleResult & then run your main query, but unless you have a need for a record count it's a bit redundant.

- Colin.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim RS As ResultSet = sqlServer.ExecQuery("SELECT ...")
log(rs.RowCount)
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
B4X:
Dim RS As ResultSet = sqlServer.ExecQuery("SELECT ...")
log(rs.RowCount)

I haven't used the B4A version of the library, but the B4J implementation doesn't have a RowCount property.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Actually I just checked - the B4A implementation doesn't have a RowCount property either.

- Colin.
 
Upvote 0

Pantelis Loizou

Member
Licensed User
Longtime User
does anyone know why i get this error message on tablets. on a mobile device the app is working fine. when i test it to tablet device whatever i do i get the following error

main$ResumableSub_Connectionresume (java line: 1224)
java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at anywheresoftware.b4j.objects.SQL.Initialize2(SQL.java:56)
at anywheresoftware.b4j.objects.SQL.Initialize(SQL.java:45)
at b4a.Gladius.main$ResumableSub_Connection.resume(main.java:1224)
at b4a.Gladius.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv5(main.java:1148)
at b4a.Gladius.main._btnsync_click(main.java:1142)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4508)
at android.view.View$PerformClick.run(View.java:18675)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
If you run it in debug mode the IDE will take you to the line that is causing the crash. Is that the complete log? There doesn't seem to be any description of the actual error.

- Colin.
 
Upvote 0

Pantelis Loizou

Member
Licensed User
Longtime User
When i press button Sync i am trying to connect to remote database in order to read records and write them to sqlite. the error occurs when i am trying to initialize the sqlserver. on my mobile device (Android 8) is working properly. on my table device (Android 4.4) is not working.

Manifest file
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>

B4X:
Sub btnSync_Click
    If lblStation.Text="" Or lblStore.Text="" Then
        Msgbox("Please Congigure the Parameters", "Sync")
        Return    
    End If
 
    Connection
End Sub

Sub Connection()
    Try
        sqlServer.Close
        If SqlPort="" Then
            SqlPort="1433"
        End If
        If SqlInstance="" Then
            sqlServer.Initialize("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://" & SqlIpAddress & ":" & SqlPort & ";databaseName=" & SqlDatabase & ";user=" & SqlUserName & ";password=" & SqlPass & ";")
        Else
            sqlServer.Initialize("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://" & SqlIpAddress & ":" & SqlPort & ";databaseName=" & SqlDatabase & ";instance=" & SqlInstance & ";user=" & SqlUserName & ";password=" & SqlPass & ";")
        End If

        lblExpirationDate.Visible=False
        lblProgress.Visible=True
        progressSync.Visible=True
        progressSync.Progress=0
        Sleep(500)
 
        CreateTables
        syncDatabases
    Catch
        Log(LastException.Message)
        MsgboxAsync("Please check your Connection.", "Connection Error")
    End Try
End Sub
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
So which line is it crashing on & what is coming from Log(LastException.Message)?

- Colin.
 
Upvote 0

Pantelis Loizou

Member
Licensed User
Longtime User
is crashing when i am trying to initialize the remote database

B4X:
java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
    at java.sql.DriverManager.getConnection(DriverManager.java:179)
    at java.sql.DriverManager.getConnection(DriverManager.java:213)
    at anywheresoftware.b4j.objects.SQL.Initialize2(SQL.java:56)
    at anywheresoftware.b4j.objects.SQL.Initialize(SQL.java:45)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:783)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at b4a.Gladius.main._connection(main.java:2028)
    at b4a.Gladius.main._btnsync_click(main.java:2020)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4508)
    at android.view.View$PerformClick.run(View.java:18675)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5590)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: java.lang.Exception: array not expected...
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
java.lang.Exception: java.lang.Exception: array not expected...

Looks like one of the parameters you are passing is an array. Check the values of all your initialization variables.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Also - which sqlServer.Initialize call is it crashing on? If you run the app in debug mode instead of release mode, it will tell you which line of your code is causing the crash.

- Colin.
 
Last edited:
Upvote 0
Top