簡體   English   中英

如何將 MySQL 數據庫中的值存儲到變量中?

[英]How do I store a value from MySQL Database into variable?

這個問題可能很簡單,但我不確定如何做到這一點。 我想將我的 SQL 語句的返回值存儲在一個變量中。

int i;
String name = "Testuser";

首先我創建我的 var。 現在我想將保存在我的數據庫(名為 Data)中的值存儲在一個名為“money”的字段中,並將鍵“Testuser”存儲到我的變量 i 中。

現在您已經有了語句實例,您可以執行類似的操作

   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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM