i |
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
PEMROGRAMAN JAVA
SISTEM PARKIR
Di SusunOleh:
Nama :Santosa Pamungkas
NIM:12121009
Kelas : 21/Pagi
Program Studi Sistem Informasi
FakultasTeknologi Informasi
UniversitasMercuBuana Yogyakarta
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
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
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
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
sesuai
kebutuhan.
5
BAB II
DATABASE
A.RancanganTabel
Tabel masuk
field
Tipe data
panjang
Id_motor
int
8
Nomor_karcis
int
10
Tabel keluar
field
Tipe data
panjang
Id_motor
int
8
Nomor_karcis
int
10
7
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){
8
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.*;9
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
10
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); }
11
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()); }
12
} } ); // 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.*;13
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();
14
}
}
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);
15
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(); }
16
}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){
17
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+"'";
18
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() {
19
// 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()); } } } );
20
// 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(); }
21
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();
22
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) {
23
koneksi dnd= new koneksi(); dnd.getConnection(); }
24
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();
} });
25
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//santosopamungkas@gmail.com","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(); }