PEMROGRAMAN JAVA SISTEM PARKIR
Di SusunOleh: Nama :Santosa Pamungkas NIM:12121009 Kelas : 21/Pagi
Program Studi Sistem Informasi FakultasTeknologi Informasi UniversitasMercuBuana Yogyakarta TahunAjaran 2015/2016
i|Laporan Perancangan Berbasis Java
DAFTAR ISI
DAFTAR ISI ............................................................................................................................................ ii BAB I ...................................................................................................................................................... iv PENDAHULUAN .............................................................................................................................. iv A.LatarBelakang ............................................................................................................................. iv B.AlasanPemilihanmasalah ............................................................................................................. iv BAB II ........................................................................................................................................................ 5 DATABASE ........................................................................................................................................ 5 A.RancanganTabel ............................................................................................................................ 5 B.Relasi Database ............................................................................................................................. 5 BAB III ....................................................................................................................................................... 7 JDBC...................................................................................................................................................... 7 A.Tabel parkir masuk........................................................................................................................ 7 B.Tabel parkir keluar .................................................................................................................... 14 Koneksi .......................................................................................................................................... 22 BAB IV .................................................................................................................................................. 24 PARKIR MENU ................................................................................................................................ 24 INTEGRASI MENU .......................................................................................................................... 26 Data parkir masuk .......................................................................................................................... 26 Data parkir keluar ........................................................................................................................... 27 BAB V.................................................................................................................................................... 29 Penutup............................................................................................................................................... 29 Kesimpulan .................................................................................................................................... 29 Kesulitan ........................................................................................................................................ 29
ii | L a p o r a n P e r a n c a n g a n B e r b a s i s J a v a
iii | L a p o r a n P e r a n c a n g a n B e r b a s i s J a v a
BAB I PENDAHULUAN A.LatarBelakang Java Database Connectivity (JDBC) adalah sebuah Application Programming Interface (API) pendukung bahasa pemrograman Java yang mendefinisikan bagaimana sebuah klien dapat mengakses sebuah database. JDBC menyediakan metode-metode untuk query dan update data dalam database. JDBC disertakan dalam bentuk driver dan driver ini bersifat Close Source. Koneksi JDBC mendukung proses pembuatan dan eksekusi statement. Statement-statement ini dapat berupa statement yang dapat di-update seperti SQL CREATE, INSERT, UPDATE, dan DELETE atau dapat juga berupa statement yang membutuhkan query seperti SELECT, dll. Statement-statement update seperti INSERT, UPDATE, dan DELETE tersebut memberikan nilai kembalian berupa informasi berapa jumlah baris di database yang telah diperbaharui. Hasil baris ini digunakan untuk mengetahui nilai yang terdapat dalam rangkaian hasil. Sedangkan nilai dari tiap-tiap kolom dalam sebuah baris diperoleh dari pendefinisian nama kolom ataupun nomor kolom yang bersangkutan. Hasil baris juga memiliki metadata yang menjelaskan nama dari masing masing kolom yang mereka bawa dan tipe mereka.
B.AlasanPemilihanmasalah Berdasarkan latar belakang yang telah dikemukakan, penulis merumuskan beberapa alasan pemilihan masalah yang antara lain: Karena proses seiring berkembangnya zaman sistem sistem yang memadai pemakai sangat dibutuhkan membuat pemakai mudah mengaksesnya, hemat waktu dan juga praktis dengan hal ini tentunya dibutuhkan aplikasi yang dapat mengelola proses keluar masuk kendaraan dengan
baik
sehingga
dapat
mengefisiensikan
pekerjaan
iv | L a p o r a n P e r a n c a n g a n B e r b a s i s J a v a
sesuai
kebutuhan.
BAB II DATABASE A.RancanganTabel
Tabel masuk field
Tipe data
panjang
Id_motor
int
8
Nomor_karcis
int
10
field
Tabel keluar Tipe data
panjang
Id_motor
int
8
Nomor_karcis
int
10
B.Relasi Database
5
6
BAB III JDBC A.Tabel parkir masuk
Masuk_Input import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*; class masuk_input extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nomor_karcis"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonSAVE=new JButton("SAVE"); JButton buttonEXIT=new JButton("EXIT");
masuk_input() { setTitle("Data motor"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } void GUI() { // Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
getContentPane().add(buttonSAVE);buttonSAVE.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){
7
if (JOptionPane.showConfirmDialog( null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // button save buttonSAVE.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String id_motor,nomor_karcis; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText(); // input ke database koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "INSERT INTO masuk VALUES('"+id_motor+"','"+nomor_karcis+"');"; int s = stmt.executeUpdate(sql); if (s == 1) { JOptionPane.showMessageDialog(null, "data motor berhasil disimpan"); } } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { masuk_input inputan=new masuk_input(); inputan.GUI(); inputan.Perintah(); } }
Edit_masuk import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*;
8
class masuk_input extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nomor_karcis"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonSAVE=new JButton("SAVE"); JButton buttonEXIT=new JButton("EXIT");
masuk_input() { setTitle("Data motor"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } void GUI() { // Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
getContentPane().add(buttonSAVE);buttonSAVE.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (JOptionPane.showConfirmDialog( null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // button save buttonSAVE.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String id_motor,nomor_karcis; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText(); // input ke database koneksi open = new koneksi();
9
Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "INSERT INTO masuk VALUES('"+id_motor+"','"+nomor_karcis+"');"; int s = stmt.executeUpdate(sql); if (s == 1) { JOptionPane.showMessageDialog(null, "data motor berhasil disimpan"); } } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { masuk_input inputan=new masuk_input(); inputan.GUI(); inputan.Perintah(); } }
Delete masuk import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*; class delete_masuk extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nama_barang"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonDelete=new JButton("Delete"); JButton buttonEXIT=new JButton("EXIT"); JButton buttonSEARCH=new JButton("SEARCH"); delete_masuk() { setTitle("Data masuk"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); }
10
void GUI() { // Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
getContentPane().add(buttonDelete);buttonDelete.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); getContentPane().add(buttonSEARCH);buttonSEARCH.setBounds(270,20,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (JOptionPane.showConfirmDialog( null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // BUTTON search buttonSEARCH.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String search; String id_motor, nomor_karcis; koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { search=textid_motor.getText(); Statement stmt=mysql.createStatement(); String sql= "SELECT * FROM masuk WHERE id_motor like '"+search+"'"; ResultSet s=stmt.executeQuery(sql); if(s.next()) { textid_motor.setText(s.getString(1)); textnomor_karcis.setText(s.getString(2));
} else { JOptionPane.showMessageDialog(null, "Data masuk tidak ada "); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); }
11
} } ); // button Delete buttonDelete.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String id_motor, nomor_karcis; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText();
// DELETE ke database koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "DELETE FROM masuk WHERE id_motor='"+id_motor+"'"; int s = stmt.executeUpdate(sql); if (s == 1) { JOptionPane.showMessageDialog(null, "data masuk berhasil dihapus");
} } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { delete_masuk inputan=new delete_masuk(); inputan.GUI(); inputan.Perintah(); } }
View masuk import java.awt.*; import java.sql.*; import javax.swing.*;
12
import javax.swing.table.*;
class view_masuk extends JPanel { String[] header = {"id_motor","nomor_karcis"}; JTable table = new JTable(); JScrollPane ScrollTable = new JScrollPane(); private Object[][] dataTable = null; view_masuk() { koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "SELECT * FROM barang "; ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData meta = rs.getMetaData(); int kolom = meta.getColumnCount(); int baris = 0; while(rs.next()) { baris = rs.getRow(); } dataTable = new Object[baris][kolom]; int x= 0; rs.beforeFirst(); while(rs.next()) { dataTable[x][0] = rs.getString("id_motor"); dataTable[x][1] = rs.getString("nomor_karcis"); x++; } ScrollTable.setViewportView(table); table.setModel(new DefaultTableModel(dataTable, header)); add(ScrollTable,BorderLayout.NORTH); stmt.close(); rs.close(); } catch (Exception ex) { JOptionPane.showMessageDialog (null, "data masuk error"); } } void GUI() { JFrame frame = new JFrame("data masuk"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); view_masuk content = new view_masuk (); content.setOpaque(true); frame.setContentPane(content); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String []args) { view_masuk inputan=new view_masuk(); inputan.GUI();
13
}
}
B.Tabel parkir keluar Keluar_input import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*; class keluar_input extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nomor_karcis"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonSAVE=new JButton("SAVE"); JButton buttonEXIT=new JButton("EXIT");
keluar_input() { setTitle("Data motor"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } void GUI() { // Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
14
getContentPane().add(buttonSAVE);buttonSAVE.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (JOptionPane.showConfirmDialog( null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // button save buttonSAVE.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String id_motor,nomor_karcis; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText(); // input ke database koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "INSERT INTO keluar VALUES('"+id_motor+"','"+nomor_karcis+"');"; int s = stmt.executeUpdate(sql); if (s == 1) { JOptionPane.showMessageDialog(null, "data motor berhasil disimpan"); } } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { keluar_input inputan=new keluar_input(); inputan.GUI(); inputan.Perintah(); }
15
}
Edit_keluar import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*; class edit_keluar extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nomor_karcis"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonUPDATE=new JButton("UPDATE"); JButton buttonEXIT=new JButton("EXIT"); JButton buttonSEARCH=new JButton("SEARCH"); edit_keluar() { setTitle("Data keluar"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } void GUI() { // Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
getContentPane().add(buttonUPDATE);buttonUPDATE.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); getContentPane().add(buttonSEARCH);buttonSEARCH.setBounds(270,20,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (JOptionPane.showConfirmDialog(
16
null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // BUTTON search buttonSEARCH.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String search; String id_motor, nomor_karcis; koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { search=textid_motor.getText(); Statement stmt=mysql.createStatement(); String sql= "SELECT * FROM masuk WHERE id_motor like '"+search+"'"; ResultSet s=stmt.executeQuery(sql); if(s.next()) { textid_motor.setText(s.getString(1)); textnomor_karcis.setText(s.getString(2));
} else { JOptionPane.showMessageDialog(null, "Data motor tidak ada "); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } } ); // button UPDATE buttonUPDATE.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e){ String id_motor,nomor_karcis,bulan; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText(); // input ke database koneksi open = new koneksi(); Connection mysql = open.getConnection(); try {
Statement stmt = mysql.createStatement(); String sql = "UPDATE masuk SET nomor_karcis='"+nomor_karcis +"'WHERE id_motor='"+id_motor+"'"; int s = stmt.executeUpdate(sql);
17
if (s == 1) { JOptionPane.showMessageDialog(null, "data data berhasil diUPDATE"); } } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { edit_keluar inputan=new edit_keluar(); inputan.GUI(); inputan.Perintah(); } }
Delete_keluar import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.sql.*; class delete_keluar extends JFrame { // Deklarasi Label JLabel labelid_motor=new JLabel("id_motor"); JTextField textid_motor=new JTextField(30); JLabel labelnomor_karcis=new JLabel("nomor_karcis"); JTextField textnomor_karcis=new JTextField(30);
JButton buttonUPDATE=new JButton("UPDATE"); JButton buttonEXIT=new JButton("EXIT"); JButton buttonSEARCH=new JButton("SEARCH"); delete_keluar() { setTitle("Data masuk"); setLocation(30,40); setSize(450,720); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } void GUI() {
18
// Label getContentPane().setLayout(null); getContentPane().add(labelid_motor);labelid_motor.setBounds(20,20,130,20); getContentPane().add(textid_motor);textid_motor.setBounds(130,20,130,20); getContentPane().add(labelnomor_karcis);labelnomor_karcis.setBounds(20,40,130,20); getContentPane().add(textnomor_karcis);textnomor_karcis.setBounds(130,40,130,20);
getContentPane().add(buttonUPDATE);buttonUPDATE.setBounds(20,110,100,20); getContentPane().add(buttonEXIT);buttonEXIT.setBounds(120,110,130,20); getContentPane().add(buttonSEARCH);buttonSEARCH.setBounds(270,20,130,20); setVisible(true); } void Perintah() { // button exit buttonEXIT.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (JOptionPane.showConfirmDialog( null,"apakah anda benar benar akan keluar?","Konfirmasi", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION) { System.exit(0); } } }); // BUTTON search buttonSEARCH.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String search; String id_motor, nomor_karcis; koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { search=textid_motor.getText(); Statement stmt=mysql.createStatement(); String sql= "SELECT * FROM masuk WHERE id_motor like '"+search+"'"; ResultSet s=stmt.executeQuery(sql); if(s.next()) { textid_motor.setText(s.getString(1)); textnomor_karcis.setText(s.getString(2));
} else { JOptionPane.showMessageDialog(null, "Data motor tidak ada "); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } } );
19
// button UPDATE buttonUPDATE.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e){ String id_motor,nomor_karcis,bulan; id_motor = textid_motor.getText(); nomor_karcis= textnomor_karcis.getText(); // input ke database koneksi open = new koneksi(); Connection mysql = open.getConnection(); try {
Statement stmt = mysql.createStatement(); String sql = "UPDATE masuk SET nomor_karcis='"+nomor_karcis +"'WHERE id_motor='"+id_motor+"'"; int s = stmt.executeUpdate(sql); if (s == 1) { JOptionPane.showMessageDialog(null, "data data berhasil diUPDATE"); } } catch (Exception ex) { JOptionPane.showMessageDialog (null, ex.getMessage()); } } }); } public static void main(String []args) { delete_keluar inputan=new delete_keluar(); inputan.GUI(); inputan.Perintah(); } }
20
View_keluar import java.awt.*; import java.sql.*; import javax.swing.*; import javax.swing.table.*;
class view_keluar extends JPanel { String[] header = {"id_motor","nomor_karcis"}; JTable table = new JTable(); JScrollPane ScrollTable = new JScrollPane(); private Object[][] dataTable = null; view_keluar() { koneksi open = new koneksi(); Connection mysql = open.getConnection(); try { Statement stmt = mysql.createStatement(); String sql = "SELECT * FROM keluar "; ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData meta = rs.getMetaData(); int kolom = meta.getColumnCount(); int baris = 0; while(rs.next()) { baris = rs.getRow(); } dataTable = new Object[baris][kolom]; int x= 0; rs.beforeFirst(); while(rs.next()) { dataTable[x][0] = rs.getString("id_motor"); dataTable[x][1] = rs.getString("nomor_karcis"); x++; } ScrollTable.setViewportView(table); table.setModel(new DefaultTableModel(dataTable, header)); add(ScrollTable,BorderLayout.NORTH); stmt.close(); rs.close(); } catch (Exception ex) { JOptionPane.showMessageDialog (null, "data masuk error"); } } void GUI() { JFrame frame = new JFrame("data masuk"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); view_masuk content = new view_masuk (); content.setOpaque(true); frame.setContentPane(content); frame.pack();
21
frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String []args) { view_masuk inputan=new view_masuk(); inputan.GUI(); }
}
Koneksi
import java.sql.*; class koneksi { String url,usr,pwd,dbn; public koneksi() { dbn="parkir"; url="jdbc:mysql://localhost/"+dbn; usr="root"; pwd=""; } public Connection getConnection() { Connection con=null; try { Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection(url,usr,pwd); System.out.println("OK: Driver Ditemukan"); } catch ( ClassNotFoundException e) { System.out.println("Error: Driver tidak ditemukan\n" +e+"\n"); System.exit(0); } catch (SQLException e) { System.out.println("Error:tidak bisa koneksi kedatabase\n" +e+"\n"); System.exit(0); } return con; } public static void main(String[] args) {
22
koneksi dnd= new koneksi(); dnd.getConnection(); } }
23
BAB IV PARKIR MENU import javax.swing.*; import java.awt.event.*; class parkirmenu extends JFrame{ JMenuBar menubar=new JMenuBar(); JMenu file=new JMenu("File"); JMenuItem exit=new JMenuItem("exit"); JMenu masuk=new JMenu("Data masuk"); JMenuItem input_masuk=new JMenuItem("input_masuk"); JMenuItem update_masuk=new JMenuItem("update_masuk"); JMenuItem deletemasuk=new JMenuItem("deletemasuk"); JMenuItem viewmasuk=new JMenuItem("viewmasuk"); JMenu keluar=new JMenu("keluar"); JMenuItem input=new JMenuItem("input"); JMenuItem update=new JMenuItem("update"); JMenuItem delete=new JMenuItem("delete"); JMenuItem view=new JMenuItem("view"); JMenu about=new JMenu("About"); JMenuItem about_Me=new JMenuItem("About Me"); parkirmenu(){ setTitle("project pemrograman javaku"); setLocation(500,200); setSize(400,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void GUI(){ setJMenuBar(menubar); menubar.add(file); file.add(exit); menubar.add(masuk); masuk.add(input_masuk); masuk.add(update_masuk); masuk.add(deletemasuk); masuk.add(viewmasuk); menubar.add(keluar); keluar.add(input); keluar.add(update); keluar.add(delete); keluar.add(view); menubar.add(about); about.add(about_Me); setVisible(true); } void orders(){ exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); input_masuk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ masuk_input InputData = new masuk_input(); InputData.GUI(); } });
24
update_masuk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ edit_masuk InputData = new edit_masuk(); InputData.GUI(); } }); deletemasuk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ delete_masuk InputData = new delete_masuk(); InputData.GUI(); } }); viewmasuk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ view_masuk InputData = new view_masuk(); InputData.GUI(); } }); about_Me.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(null,"12121009_santosa_pamungkas//
[email protected]","About",JOptionPane.INF ORMATION_MESSAGE); } }); } public static void main(String[] args){ System.out.println("NAMA : santosa pamungkas"); System.out.println("NIM : 12121009"); System.out.println("PRODI : sistem informasi"); parkirmenu x=new parkirmenu(); x.GUI(); x.orders(); } }
25
INTEGRASI MENU Data parkir masuk Input kendaraan yang masuk
Update kendaraan yang masuk
Delete kendaraan yang masuk
26
View kendaraan yang masuk
Data parkir keluar Input kendaraan yang keluar
Update kendaraan yang keluar
27
Delete kendaraan yang keluar
View kendaraan yang keluar
28
BAB V Penutup Kesimpulan Fasilitas JDBC untuk melakukan koneksi ke sumber data menggunakan ODBC (Open DataBase Connectivity) driver. Melakukan koneksi ke database melibatkan dua langkah: Meload driver dan membuat koneksi itu sendiri. Cara meload driver sangat mudah, pertama letakkan file jar database driver ke dalam classpath.sementara membuat koneksi ke database menggunakan database driver yang sudah diload. Untuk mengelola driver-driver yang diload oleh aplikasi, JDBC Test Suite akan melakukan serangkaian tes untuk menentukan driver mana yang akan digunakan. Parameter yang digunakan untuk menentukan driver yang sesuai adalah URL.Jika salah satu dari driver yang diload berhasil digunakan untuk melakukan koneksi dengan URL tersebut, maka koneksi ke database berhasil dilaksanakan.Setelah sukses melakukan koneksi ke database, kita dapat mengambil data dari database menggunakan perintah query ataupun melakukan perubahan terhadap database. Kesulitan Kesulitan saya adalah untuk menampilkan view kendaraaan, baik yang keluar maupun yang masuk.
29