Ekonion Ekonion - 1 year ago 55
Java Question

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...


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

how do I get there?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download