如何将mysql数据库中的值存储到变量中?

5jdjgkvh  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(412)

这个问题可能很简单,但我´我不太清楚,怎么做。我想将sql语句的返回值存储在一个变量中。

int i;
String name = "Testuser";

首先,我创建了我的var。现在,我想把这个值存储在我的数据库(命名数据)中一个名为“money”的字段中,并将键“testuser”保存到我的变量i中。

3okqufwl

3okqufwl1#

现在您已经有了语句的示例,您可以这样做

int i;
ResultSet resultat = null;
   resultat = statement.executeQuery("SELECT money FROM data WHERE id=1;");//for example the value of the field money in the row who has id=1
   if(resultat.next()){ // you check if the query returned a value
 i=resultat.getInt("money"); // the name of the column
}

相关问题