B4J Question Mysql SELECT

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I am having a problem getting a Mysql SELECT statement for a single record to work so any help will be gratefully accepted.

On the Mysql command line, If I use "SELECT * FROM dbTable WHERE id = "150"; I get the correct record and information.

In B4J cursor = sql.ExecQuery2("SELECT * FROM dbTable WHERE id = ?",Array as String("150"))

txtBox1.text = cursor.GetString2(0) gives me an Error in a Try/Catch/End Try

ERROR: java.sql.SQLExecption: Before start of result set

What is the correct way to get a single record and extract the column data?

Thanks
 

Daestrum

Expert
Licensed User
Longtime User
maybe you need the quotes around the value as its a string

cursor = sql.ExecQuery2("SELECT * FROM dbTable WHERE id = ?",Array as String("'150'"))
or
cursor = sql.ExecQuery2("SELECT * FROM dbTable WHERE id = '?'",Array as String("150"))
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
It's better to use DBUtils code module by Erel...
It has many useful functions to do the job done!
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thank you for your replies.

I got it to work using the following code, putting the table name in dbTable and the recordNo in dbRec.

B4X:
cursor = Sql.ExecQuery("SELECT * FROM "&dbTable&" WHERE id = "&dbRec&"")
       
        Do While cursor.NextRow
            'update the screen text fields
        Loop
 
Upvote 0
Top