0
顧客がデータベースから削除されると、データベースから実際に顧客を削除するのではなく、ステータスをオフラインに設定する必要があります。私のデータベースでは、ステータスを0(非アクティブ)または1(アクティブ)に設定するためにtinyint(1)を使用しています。さて、これをコーディングするにはどうすればいいですか?javaを使用してmysqlデータベースのtinyint(1)データ型を変更する
// Delete a customer on the database by setting his status to inactive
public void deleteCust(int id) throws DBException {
// connect (and close connection)
try (Connection conn = ConnectionManager.getConnection();) {
// PreparedStatement
try (PreparedStatement stmt = conn.prepareStatement(
"update customer set active = ? where id = ?");) {
stmt.settinyint(1, 0);
stmt.setInt(2, id);
stmt.execute();
} catch (SQLException sqlEx) {
throw new DBException("SQL-exception in deleteCust - statement"+ sqlEx);
}
} catch (SQLException sqlEx) {
throw new DBException(
"SQL-exception in deleteCust - connection"+ sqlEx);
}
}
私は、ローカルホスト上のUSBウェブサーバを経由してSQLデータベースを使用しています。私のコードの残りの部分が不完全で、テストすることができないので、これが現在動作しているかどうかは分かりませんが、続行する前に確認する必要があります。ありがとうございます
をありがとう!私はこれを試してみます – user3117628
あなたの歓迎、これらの例[java2s.com](http://www.java2s.com/Code/Java/Database-SQL-JDBC/UpdateRecordsUsingPreparedStatement.htm)と[tutorialspoint.com] (http://www.tutorialspoint.com/jdbc/preparestatatent-object-example.htm)も参照してください。 –