Advertisement
Guest User

Untitled

a guest
May 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. private void JSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {
  2. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  3. String tglpinjam = dateFormat.format(txt_tglpinjam.getDate());
  4. String tglkmbl = dateFormat.format(txt_tglkbl.getDate());
  5.  
  6. if(txt_tglpinjam.getDate() == null)
  7. {
  8. JOptionPane.showMessageDialog(this, "tanggal pinjam tidak boleh Kosong!");
  9. }
  10. else if(cb_peminjam.equals(""))
  11. {
  12. JOptionPane.showMessageDialog(this, "peminjam tidak boleh Kosong!");
  13. }
  14. else if(cb_namabarang.equals(""))
  15. {
  16. JOptionPane.showMessageDialog(this, "nama barang tidak boleh Kosong!");
  17. }
  18. else if(txt_kodebarang.equals(""))
  19. {
  20. JOptionPane.showMessageDialog(this, "kode barang tidak boleh Kosong!");
  21. }
  22. //yang disini ham , ham ? msih msuk kan ?
  23. else if(txt_jlhpinjam.equals(""))
  24. {
  25. JOptionPane.showMessageDialog(this, "jumlah pinjam maksimal hanya 3!");
  26. }
  27. else if(txt_tglkbl.getDate() == null)
  28. {
  29. JOptionPane.showMessageDialog(this, "tanggal kembali tidak boleh Kosong!");
  30. }
  31. else{
  32. try{
  33. String sql = "insert into peminjamans"
  34. +"(tanggal_pinjam, peminjam, nama_barang, jumlah, tanggal_kembali,kode_barang )"
  35. +"value(?,?,?,?,?,?)";
  36. con = DriverManager.getConnection("jdbc:mysql://localhost/rentalkamera","root","");
  37. pst = con.prepareStatement(sql);
  38. pst.setString(1, tglpinjam);
  39. pst.setString(2, (String) cb_peminjam.getSelectedItem());
  40. pst.setString(3, (String) cb_namabarang.getSelectedItem());
  41. pst.setString(4, txt_jlhpinjam.getText());
  42. pst.setString(5, tglkmbl);
  43. pst.setString(6, txt_kodebarang.getText());
  44.  
  45.  
  46. pst.executeUpdate();
  47. JOptionPane.showMessageDialog(null, "Data Peminjaman Berhasil Disimpan");
  48. }
  49. catch(SQLException | HeadlessException ex){
  50. JOptionPane.showMessageDialog(this, ex.getMessage());
  51. }
  52. }
  53.  
  54. tampilkanpeminjaman();
  55. bersihkan();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement