본문
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteTest {
// select 만 ResultSet이 필요,
private Connection con;
private Statement stmt;
public DeleteTest(String id){
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "joker7379");
String sql = "delete from new_table where id='" + id + "'" ; // 변수로 처리
stmt = con.createStatement();
int i = stmt.executeUpdate(sql); // 처리된 레코드의 갯수를 리턴
System.out.println("처리된 레코드의 갯수 : " + i);
stmt.close();
con.close();
} catch (SQLException e) {
System.out.println("일반예외 : " + e);
} catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
new DeleteTest("aaa");
}
}