Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package peminjaman.drm.impl;
- import peminjaman.drm.entiti.entitipetugasrekammedis;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import java.sql.*;
- /**
- *
- * @author Rena
- */
- public class petugasrekammedisimpl {
- Connection con=null;
- Statement st=null;
- ResultSet rs=null;
- String sql=null;
- public petugasrekammedisimpl(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_peminjamandrm","root","");
- st=con.createStatement();
- }catch(Exception a){
- JOptionPane.showMessageDialog(null, "Koneksi Database Gagal, Terjadi kesalahaan Pada : \n"+a);
- }
- }
- public List cari(String cari){
- //List logBarang = new ArrayList();
- List<entitipetugasrekammedis> list = new ArrayList<>();
- sql="select * from t_login where nip like '%"+cari+"%' or nama like '%"+cari+"%'";
- try{
- rs=st.executeQuery(sql);
- while(rs.next()){
- entitipetugasrekammedis eb=new entitipetugasrekammedis();
- eb.setnip(rs.getString("nip"));
- eb.setnama(rs.getString("nama"));
- eb.setbagian(rs.getString("bagian"));
- eb.setusername(rs.getString("username"));
- eb.setpassword(rs.getString("password"));
- eb.settypeuser(rs.getString("type_user"));
- eb.settgldaftar(rs.getString("tgl_daftar"));
- list.add(eb);
- }
- } catch(SQLException a){
- JOptionPane.showMessageDialog(null, "Terjadi kesalahaan tampil, pada :\n"+a);
- }
- return list;
- }
- public List cariLogin(String user,String pass){
- // List logLogin = new ArrayList();
- List<entitipetugasrekammedis> list = new ArrayList<>();
- int result;
- sql="select username,password,type_user from t_login where username='"+user+"' and password='"+pass+"'";
- try{
- rs=st.executeQuery(sql);
- while(rs.next()){
- entitipetugasrekammedis ep=new entitipetugasrekammedis();
- ep.setusername(rs.getString("username"));
- ep.setpassword(rs.getString("password"));
- ep.settypeuser(rs.getString("type_user"));
- list.add(ep);
- }
- } catch(SQLException a){
- JOptionPane.showMessageDialog(null, "Terjadi kesalahaan login, pada :\n"+a);
- }
- return list;
- }
- public List tampil(){
- //List logLogin = new ArrayList();
- List<entitipetugasrekammedis> list = new ArrayList<>();
- int result;
- sql="select * from t_login";
- try{
- rs=st.executeQuery(sql);
- while(rs.next()){
- entitipetugasrekammedis ep=new entitipetugasrekammedis();
- ep.setnip(rs.getString("nip"));
- ep.setnama(rs.getString("nama"));
- ep.setusername(rs.getString("username"));
- ep.setpassword(rs.getString("password"));
- ep.setbagian(rs.getString("bagian"));
- ep.settypeuser(rs.getString("type_user"));
- ep.settgldaftar(rs.getString("tgl_daftar"));
- list.add(ep);
- }
- } catch(SQLException a){
- JOptionPane.showMessageDialog(null, "Terjadi kesalahaan login, pada :\n"+a);
- }
- return list;
- }
- public int tambah(entitipetugasrekammedis e){
- sql="insert into t_login values('"+e.getnip()+"','"+e.getnama()
- +"','"+e.getbagian()+"','"+e.getusername()+"','"+e.getpassword()+"','"+e.gettypeuser()+"','"+e.gettgldaftar().toString()+"')";
- int hasil=0;
- try{
- hasil=st.executeUpdate(sql);
- } catch(SQLException a){
- Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
- }
- return hasil;
- }
- public int delete(entitipetugasrekammedis e){
- sql="delete from t_login where nip='"+e.getnip()+"'";
- int hasil=0;
- try{
- hasil=st.executeUpdate(sql);
- } catch(SQLException a){
- Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
- }
- return hasil;
- }
- public int edit(entitipetugasrekammedis e){
- sql="update t_login set password='"+e.getpassword() +"' where nip='"+e.getnip()+"'";
- int hasil=0;
- try{
- hasil=st.executeUpdate(sql);
- } catch(SQLException a){
- Logger.getLogger(petugasrekammedisimpl.class.getName()).log(Level.SEVERE,null,a);
- }
- return hasil;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement