Из приведенного ниже метода executeUpdate() я хочу обновить данные в таблице db2. Прежде чем делать это, я хочу проверить, имеет ли C_Conf и D_Conf значения «Да» означает, что мне нужно заменить на «Y», а если значение «НЕТ» означает, что мне нужно заменить на «N». где я могу проверить это и добавить к запросу обновления.Проверка состояния Перед загрузкой в таблицу
В executeUpdate() я просто закодировал значение как «N» для C_Conf и D_Conf. здесь я хочу проверить, является ли значение «Да» означает, что мне нужно заменить «Y» или «НЕТ» означает, что мне нужно заменить на «N». Как проверить и где в коде? Пожалуйста, помогите
public class DbTask {
Connection connection;
Statement statement, statement1;
public boolean executeQuery(String dbQuery){
boolean result = false;
connection = DatabaseConnection.getCon();
try {
statement = connection.createStatement();
result = statement.execute(dbQuery);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public boolean cleanTable(String schema, String tableName) {
boolean result = false;
connection = DatabaseConnection.getCon();
try {
statement = connection.createStatement();
// can be implemented later for deleteing the table data
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
общественности недействительным executeUpdate() {
String selectQuery = "select
S_NUMBER,CON,D_CON,R_CON,VAL_CON
from
OTG.S_SAMPLE_VAL"
+" WHERE R_TS = (SELECT MAX(R_TS) FROM
OTG.S_SAMPLE_VAL)";
Statement statement;
try {
connection = DatabaseConnection.getCon();
statement = connection.createStatement();
statement1 = connection.createStatement();
ResultSet rs = statement.executeQuery(selectQuery);
while(rs.next()){
StringBuffer updateQuery = new StringBuffer();
updateQuery.append("update OTG.R_VAL set ");
updateQuery.append("C_Conf='");
updateQuery.append("N', ");
// updateQuery.append(rs.getString(2) + "', ");
updateQuery.append("D_Conf='");
// updateQuery.append(rs.getString(3) + "', ");
updateQuery.append("N', ");
updateQuery.append("REVE=");
updateQuery.append(rs.getString(4) + ", ");
updateQuery.append("VAL='");
updateQuery.append(rs.getString(5) + "' ");
updateQuery.append("where S_NO ='" + rs.getString(1) + "'");
System.out.println(updateQuery.toString());
statement1.executeUpdate(updateQuery.toString());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Изучите подготовленные операторы: http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html –