Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package peminjaman.drm.impl;
  7. import peminjaman.drm.entiti.entitipetugasrekammedis;
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import javax.swing.JOptionPane;
  18. import java.sql.*;
  19.  
  20. /**
  21. *
  22. * @author Rena
  23. */
  24. public class petugasrekammedisimpl {
  25. Connection con=null;
  26. Statement st=null;
  27. ResultSet rs=null;
  28. String sql=null;
  29. public petugasrekammedisimpl(){
  30. try{
  31. Class.forName("com.mysql.jdbc.Driver");
  32. con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_peminjamandrm","root","");
  33. st=con.createStatement();
  34. }catch(Exception a){
  35. JOptionPane.showMessageDialog(null, "Koneksi Database Gagal, Terjadi kesalahaan Pada : \n"+a);
  36. }
  37. }
  38.  
  39. public List cari(String cari){
  40. //List logBarang = new ArrayList();
  41. List<entitipetugasrekammedis> list = new ArrayList<>();
  42. sql="select * from t_login where nip like '%"+cari+"%' or nama like '%"+cari+"%'";
  43. try{
  44. rs=st.executeQuery(sql);
  45.  
  46. while(rs.next()){
  47. entitipetugasrekammedis eb=new entitipetugasrekammedis();
  48. eb.setnip(rs.getString("nip"));
  49. eb.setnama(rs.getString("nama"));
  50. eb.setbagian(rs.getString("bagian"));
  51. eb.setusername(rs.getString("username"));
  52. eb.setpassword(rs.getString("password"));
  53. eb.settypeuser(rs.getString("type_user"));
  54. eb.settgldaftar(rs.getString("tgl_daftar"));
  55. list.add(eb);
  56. }
  57. } catch(SQLException a){
  58. JOptionPane.showMessageDialog(null, "Terjadi kesalahaan tampil, pada :\n"+a);
  59. }
  60. return list;
  61. }
  62.  
  63. public List cariLogin(String user,String pass){
  64. // List logLogin = new ArrayList();
  65. List<entitipetugasrekammedis> list = new ArrayList<>();
  66. int result;
  67. sql="select username,password,type_user from t_login where username='"+user+"' and password='"+pass+"'";
  68. try{
  69. rs=st.executeQuery(sql);
  70.  
  71. while(rs.next()){
  72. entitipetugasrekammedis ep=new entitipetugasrekammedis();
  73. ep.setusername(rs.getString("username"));
  74. ep.setpassword(rs.getString("password"));
  75. ep.settypeuser(rs.getString("type_user"));
  76. list.add(ep);
  77. }
  78. } catch(SQLException a){
  79. JOptionPane.showMessageDialog(null, "Terjadi kesalahaan login, pada :\n"+a);
  80. }
  81. return list;
  82. }
  83. public List tampil(){
  84. //List logLogin = new ArrayList();
  85. List<entitipetugasrekammedis> list = new ArrayList<>();
  86. int result;
  87. sql="select * from t_login";
  88. try{
  89. rs=st.executeQuery(sql);
  90.  
  91. while(rs.next()){
  92. entitipetugasrekammedis ep=new entitipetugasrekammedis();
  93. ep.setnip(rs.getString("nip"));
  94. ep.setnama(rs.getString("nama"));
  95. ep.setusername(rs.getString("username"));
  96. ep.setpassword(rs.getString("password"));
  97. ep.setbagian(rs.getString("bagian"));
  98. ep.settypeuser(rs.getString("type_user"));
  99. ep.settgldaftar(rs.getString("tgl_daftar"));
  100. list.add(ep);
  101. }
  102. } catch(SQLException a){
  103. JOptionPane.showMessageDialog(null, "Terjadi kesalahaan login, pada :\n"+a);
  104. }
  105. return list;
  106. }
  107.  
  108.  
  109. public int tambah(entitipetugasrekammedis e){
  110. sql="insert into t_login values('"+e.getnip()+"','"+e.getnama()
  111. +"','"+e.getbagian()+"','"+e.getusername()+"','"+e.getpassword()+"','"+e.gettypeuser()+"','"+e.gettgldaftar().toString()+"')";
  112. int hasil=0;
  113. try{
  114. hasil=st.executeUpdate(sql);
  115. } catch(SQLException a){
  116. Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
  117. }
  118. return hasil;
  119. }
  120.  
  121.  
  122.  
  123.  
  124. public int delete(entitipetugasrekammedis e){
  125. sql="delete from t_login where nip='"+e.getnip()+"'";
  126. int hasil=0;
  127. try{
  128. hasil=st.executeUpdate(sql);
  129. } catch(SQLException a){
  130. Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
  131. }
  132. return hasil;
  133. }
  134.  
  135. public int edit(entitipetugasrekammedis e){
  136. sql="update t_login set password='"+e.getpassword() +"' where nip='"+e.getnip()+"'";
  137. int hasil=0;
  138. try{
  139. hasil=st.executeUpdate(sql);
  140. } catch(SQLException a){
  141. Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
  142. }
  143. return hasil;
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement