Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. package belajar.jdbc;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. public class MainApplication {
  9.  
  10. public static void main(String[] args) {
  11. try {
  12. Connection koneksi = DriverManager
  13. .getConnection("jdbc:mysql://localhost:3306/jdbc_mysql", "root", "admin");
  14.  
  15. String sql = "DELETE FROM mahasiswa WHERE nim = ?";
  16. PreparedStatement ps = koneksi.prepareStatement(sql);
  17. System.out.println("sebelum set value: " + ps.toString());
  18. ps.setString(1, "10511150");
  19. System.out.println("setelah set value: " + ps.toString());
  20. ps.executeUpdate();
  21.  
  22. ps.close();
  23. koneksi.close();
  24. } catch (SQLException ex) {
  25. System.err.println("Database tidak ditemukan!");
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement