Home » » Java

Java

import java.sql.*;
import java.io.*;
import javax.swing.*;

public class datamhs{
    public static void main (String [] koneksi) throws Exception
    {
        String strA;
        BufferedReader brA = new BufferedReader (new InputStreamReader(System.in));

      
        outerLoop:
            for( int i=0; i<2; i++ ){       
                String m1,m2,m3,m4,m5,m6,m7,m8;
                m1="TAMPILKAN SEMUA DATA";               
                m2="INPUT DATA";
                m3="UBAH NAMA";
                m4="UBAH KELAS";               
                m5="UBAH ALAMAT";               
                m6="HAPUS DATA";               
                m7="KELUAR PROGRAM";               
                m8="HAPUS SEMUA DATA";               
                System.out.println("==============================================");                    
                System.out.println("\t  PILIHAN PROSES ");
                System.out.println("==============================================");       
                System.out.println("= 1 : "+m1);
                System.out.println("= 2 : "+m2);
                System.out.println("= 3 : "+m3);               
                System.out.println("= 4 : "+m4);
                System.out.println("= 5 : "+m5);
                System.out.println("= 6 : "+m6);
                System.out.println("= 7 : "+m7);               
                System.out.println();               
                System.out.println("= 8 : "+m8);                               
                System.out.println("==============================================");                    
                System.out.println();
                System.out.print("= Menu: ");           
                int e = Integer.parseInt(brA.readLine());
                System.out.println("");                                  
             
                if (e==1)
                {
                    //Menampilkan semua data
                    System.out.println("==============================================");                    
                    System.out.println("= = = 1. "+m1+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("jdbc:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                   
                    ResultSet rs = st.executeQuery("select * from tmaster;");
                    System.out.println("   NPM\t\tNama\t\tKelas\tAlamat"); 
                    while (rs.next())
                    {
                        System.out.println(rs.getString("npm")+"\t"+rs.getString("nama")+"\t\t"+rs.getString("kls")+"\t"+rs.getString("alamat"));
                    }
                    System.out.println("==============================================");                    
                    System.out.println();                                       
                    st.close();
                    conn.close();
                }               
               
               
                else if (e==2)
                {
                    // Proses Input
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();                   
                    System.out.println("==============================================");                                        
                    System.out.println("= = = 2. "+m2+" = = = ");
                    System.out.println("==============================================");                    
                    System.out.print("NPM\t: ");
                    String npm =(brA.readLine());
                    System.out.print("Nama\t: ");
                    String nm =(brA.readLine());
                    System.out.print("Kelas\t: ");
                    String kls =(brA.readLine());
                    System.out.print("Alamat\t: ");
                    String almt =(brA.readLine());           
                    System.out.print("");                     
           
                    st.executeUpdate("insert into tmaster (npm,nama,kls,alamat) values('"+npm+"','"+nm+"','"+kls+"','"+almt+"');");
                    st.close();
                    conn.close();   
                }
               
                else if (e==3)
                {
                    //Ubah nama
                    System.out.println("==============================================");                    
                    System.out.println("= = = 3. "+m2+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                   
                    System.out.print("NPM\t: ");
                    String npm =(brA.readLine());            
                    System.out.print("Nama\t: ");
                    String nm =(brA.readLine());                               
                   
                    st.executeUpdate("update tmaster set nama = ('"+nm+"') where (npm) = '"+npm+"';");    
                    System.out.println("==============================================");                                        
                    System.out.println("Nama telah dirubah menjadi "+nm+" .");                                                        
                    System.out.println("==============================================");                    
                    System.out.println();
                    st.close();
                    conn.close();
                }                  
               
                else if (e==4)
                {
                    //Ubah kelas
                    System.out.println("==============================================");                    
                    System.out.println("= = = 4. "+m4+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                   
                    System.out.print("NPM\t: ");
                    String npm =(brA.readLine());           
                    System.out.print("Kelas\t: ");
                    String kls =(brA.readLine());                               
                   
                    st.executeUpdate("update tmaster set kls = ('"+kls+"') where (npm) = '"+npm+"';");                   
                    System.out.println("==============================================");                                        
                    System.out.println("Kelas telah dirubah menjadi "+kls+" .");                                                        
                    System.out.println("==============================================");                    
                    System.out.println();                                       
                    st.close();
                    conn.close();
                }   
               
                else if (e==5)
                {
                    //Ubah alamat                                    
                    System.out.println("==============================================");                    
                    System.out.println("= = = 5. "+m5+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                   
                    System.out.print("NPM\t: ");
                    String npm =(brA.readLine());                              
                    System.out.print("Alamat\t: ");
                    String almt =(brA.readLine()); 
                   
                    st.executeUpdate("update tmaster set alamat = ('"+almt+"') where (npm) = '"+npm+"';");                   
                    System.out.println("==============================================");                                        
                    System.out.println("Alamat telah dirubah menjadi "+almt+" .");                                                        
                    System.out.println("==============================================");                    

                    System.out.println();                                       
                    st.close();
                    conn.close();
                }  
               
                else if (e==6)
                {
                    //hapus data
                    System.out.println("==============================================");                    
                    System.out.println("= = = 6. "+m6+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                   
                    System.out.print("NPM\t: ");
                    String npm =(brA.readLine());   
                   
                    st.executeUpdate("delete from tmaster where (npm)  = ('"+npm+"');");                   
                    System.out.println("Data NPM "+npm+" telah dihapus");                   
                    System.out.println();                                       
                    st.close();
                    conn.close();
                }   
               
                else if (e==7)
                {
                    //keluar program                   
                    System.out.println("==============================================");                    
                    System.out.println("= = 7. "+m7+" = = =");
                    System.out.println("==============================================");                    
                    System.out.println("Terima kasih sudah menggunakan program ini.");
                    System.out.println("==============================================");                                        
                    System.exit(0);
                }
               
                else if (e==8)
                {
                    //kosongkan data database                
                    System.out.println("==============================================");                    
                    System.out.println("= = = 8. "+m8+" = = = ");
                    System.out.println("==============================================");                    
                    Class.forName("org.sqlite.JDBC");
                    Connection conn = DriverManager.getConnection("JDBC:sqlite:mhs.db");
                    Statement st = conn.createStatement();
                              
                    st.executeUpdate("delete from tmaster where (npm)>0");   
                    System.out.println("==============================================");                                        
                    System.out.println("Database telah dikosongkan");                   
                    System.out.println("==============================================");                                        
                    System.out.println();                                       
                    st.close();
                    conn.close();
                    }
                                            
                else
                {
                    System.out.println("==============================================");                                        
                    System.out.println("Maaf pilihan 'MENU' Anda salah!");
                    System.out.println("==============================================");                                        
                    System.out.println();                   
                }
               
            }
                System.out.println();
                JOptionPane.showMessageDialog(null,"Anda telah melakukan proses terlalu banyak, restart program Anda.");       
       
    }
}

0 komentar:

Posting Komentar

Comments

Kontak Jodoh

Featured

free counters

Arsip Blog

Followers