Cara menghapus class Koneksi java

     Membuat class java untuk menghapus koneksi java ke mysql, berikut adalah script untuk menghapus koneksi.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Delete {
    public static void main(String[] args) throws SQLException {
        String delete = "delete from mahasiswa where nim=?";
        Connection connection = null;
   PreparedStatement ps = null;
        try {
            connection = Koneksi.getKoneksi();
            ps = connection.prepareStatement(delete);
            ps.setString(1, "110011009");
            ps.executeUpdate();
            System.out.println("Delete Berhasil");
        } catch (SQLException e) {
            System.out.println("Error : " + e.getMessage());
        } finally {
            if (ps != null) {
                ps.close();
            }
        }
    }


Script Delete.java

No comments:

Post a Comment