- 論壇徽章:
- 0
|
package com.Myself.database.calculate;
//查詢數(shù)據(jù)庫中某表的metrix,arg為表名,然后給+1重新賦值
//然后把新的metrix重新插入到數(shù)據(jù)庫
import java.sql.*;
import com.Myself.database.define.ConnectDatabase;
public class CountMetrix {
//查詢出數(shù)據(jù)庫中metrix值并+1
public static int countMetrix(String tableName,int id) throws SQLException{
try{
Connection conn = ConnectDatabase.getConnection();
String sqlQuery = "select metrix from " + tableName+"where id="+id;;
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(sqlQuery);
while(rst.next()){
int metrix=rst.getInt(1)+1;
}
}
catch (Exception e){
e.printStackTrace();
}
return metrix;
}
//把新的metrix插入到數(shù)據(jù)庫,要返回是否插入成功
public static int UpdateMetrix(String tableName,int id) throws SQLException{
try{
int isSuccess;
Connection conn = ConnectDatabase.getConnection();
String sqlUpdate = "update "+tableName+"set metrix="+CountMetrix.countMetrix(tableName,id)+"where id="+id;
Statement stmt = conn.createStatement();
isSuccess= stmt.executeUpdate(sqlUpdate);
}
catch (Exception e){
e.printStackTrace();
}
return isSuccess; }
}
上邊的紅色都會導(dǎo)致出錯."cannot resolve symbol",請教應(yīng)該怎么返回。新手,謝謝您的閱讀 |
|