Android Question JdbcResultSet java.lang.RuntimeException: Object should first be initialized.

gacar

Active Member
I want read single value from table but i am getting "java.lang.RuntimeException: Object should first be initialized" error.
B4X:
    SQL.InitializeAsync("SQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/TestProject"$, DBUsername, DBPassword)
    Dim rs As JdbcResultSet =  SQL.execquery("select * FROM USERS WHERE UserId=1")
    Log(rs.getstring2(0))

How can get e.g 5.row 3.column value?
 

gacar

Active Member
Thank you Erel, i changed code like as below then working now.

Before
B4X:
Public Sub SQLConnect
    SQL.InitializeAsync("SQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/TestProject"$, DBUsername, DBPassword)
   
     Dim rs As JdbcResultSet =  SQL.execquery("select * FROM Bolge where bolge_id=1")
     Do While rs.nextrow
        Log(rs.getstring2(1) )
        If LabelIstanbul.IsInitialized Then
            LabelIstanbul.Text = rs.getstring2(1)
        End If    
    Loop
    rs.Close
End Sub

After
I put SQL_Ready sub to page
B4X:
Public Sub SQLConnect
    SQL.InitializeAsync("SQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/TestProject"$, DBUsername, DBPassword)
End Sub

Sub SQL_Ready (Success As Boolean)
    If Success Then
        Dim rs As JdbcResultSet =  SQL.execquery("select * FROM  Bolge where bolge_id=1")
        Do While rs.nextrow
            LabelIstanbul.Text = rs.getstring2(1)
        Loop
        rs.Close
    Else
        Log(LastException)
        Return
    End If
End Sub
 
Upvote 0
Top