简体   繁体   中英

Trying to get data from an odb databes in Java

        ResultSet rs = sql.executeQuery
        ("SELECT HP FROM PKMN WHERE (ID == basicnumber)"); 

That is the code I want to use, but I have a mistake I do not see...

Explanation:

I am accessing my .odb Database from Java . I want a user to Input an ID (saved in int basicnumber ), add it to the query and get the value from the column hp , specific to the ID . This value has to be saved in an int hp and NOT prompted.

how do I get there?

First, you need to concatenate your basicnumber to the query:

ResultSet rs = sql.executeQuery
    ("SELECT HP FROM PKMN WHERE ID = " + basicnumber);

then you can retrieve the result and store it into a variable:

int hp = rs.getInt(1); 

See the ResultSet API to explore more ways to retrieve values from the resultset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM