Android Question JdbcResultSet get value from specific cell

Hi. I'm using Jdbc as remote MySQL connector. Assume that I want to get the value of 4th row 2nd column (as below image), How to do it?

In SQL we have rowcount and position option. But in Jdbc, I don't know how to get the value from specific cell. Do I have to filter the data from SQL query like SELECT * FROM products WHERE product_name='"product name"' ?

PS; I used SQL query to filter data. but it gives error.

This is my code. I used Grid module from scsjc

B4X:
Sub grid_ItemClick (index As Int, Value As Object)
    Log("value:" & Value)
    Log("index:" & index )
    Dim Cursor As JdbcResultSet
    Cursor = connection.mysql.ExecQuery("SELECT * FROM products WHERE id='"&index&"'")
    Log(Cursor.GetString("product_name"))
End Sub

Error
Error occurred on line: 88 (menu)
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:781)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5239)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5162)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5201)
at anywheresoftware.b4j.objects.SQL$ResultSetWrapper.GetString(SQL.java:523)
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.menu._grid_itemclick(menu.java:873)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew3(Debug.java:288)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug3(Common.java:1061)
at b4a.example.grid._panel_click(grid.java:459)
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:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6659)
at android.view.View.performClickInternal(View.java:6631)
at android.view.View.access$3100(View.java:790)
at android.view.View$PerformClick.run(View.java:26187)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
 

Attachments

  • Capture.PNG
    Capture.PNG
    6.7 KB · Views: 124
Last edited:
I found the solution.
have to use,
B4X:
Do While Cursor.NextRow
    Log(Cursor.GetString("product_name"))
Loop

But if anyone know how to get value from specific cell without doing all this, Please let me know
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top