很高興認識大家!我想從簡單的下面的代碼一欄獲得價值:Java SQL如何從列中獲取值?
String statement = "select rated,vote_count from iptv_media_source where channel_id= '"
+ channelId + "'";
float rated = 0;
int vote_count =0;
try {
rs =Main.db.getCon().createStatement().executeQuery(statement);
rated = rating.getFloat("rated");
vote_count = rating.getInt("vote_count");
vote_count++; rated++;
statement = "UPDATE iptv_media_source SET rated = '"+rated+"' , vote_count = '"+vote_count+"' WHERE channel_id= '" + channelId + "'";
Main.db.getCon().createStatement().executeUpdate(statement);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UPDATE語句運行良好,但是這兩條線:
rated = rating.getFloat("rated");
vote_count = rating.getInt("vote_count");
了一些問題。謝謝你的回覆!
這2條線遇到了什麼樣的問題?任何錯誤? – cherouvim
@cherouvim:最可能的編譯器錯誤,因爲'rating'是無處宣告的。 –