Software
1.
WampServer Version 2.2 (MySQL Version 5.5.20)
2.
Netbeans IDE 6.8
3.
Firefox 9.0.1
Membuat Database
di MySQL
1.
Buat database dengan nama “java” (tanpa
tanda kutip)
2.
Buat tabel mahasiswa berikut:
Field Name
|
Data Type
|
Field Size
|
nomor
|
Varchar
|
2
|
nama
|
Varchar
|
30
|
3.
Simpan dengan nama mahasiswa
4.
Entri data berikut:
Nomor
|
Nama
|
01
|
Komar
|
02
|
Tasdik
|
03
|
Fatahillah
|
04
|
Cendekia Nagara
|
05
|
Komarudin Tasdik
|
Membuat
Form di Netbeans IDE 6.8
1.
1. Buat folder java di C:\ wamp\www\ (untuk menyimpan semua file java)
2.
Masuk ke NetBeans
3.
File – New Project
4.
Categories: Java; Projects: Java Application
5.
Next
6.
Project Name: JavaApplicationLat1;
7.
Project Location: C:\ wamp\www\Java\
8.
Hilangkan centang di Create Main Class
9.
Finish
10.
Di panel Projects, lihat tulisan JavaApplicationTambah
11.
Klik tanda + di Source Packages
12.
Klik kanan di <default package>
13.
New – Java Package
14.
Package Name: PackageTambah
15.
Finish
16.
Klik kanan PackageTambah di panel Projects
17.
New – Java Class
18.
Class Name: ClassMhsTambah
19.
Finish
20.
Di ClassMhsTambah, ketik script koneksi
berikut:
package PackageTambah;
import
com.mysql.jdbc.Driver;
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.SQLException;
/**
*
*
@author komtas
*/
public class ClassMhsTambah {
private
static Connection ClassMhsTambah;
public static Connection getConnection()
throws SQLException {
if (ClassMhsTambah == null) {
// panggil Driver MySQL
new Driver();
// buat koneksi
ClassMhsTambah =
DriverManager.getConnection("jdbc:mysql://localhost:3306/java",
"root", "");
}
return ClassMhsTambah;
}
public static void main(String args[]) {
try {
getConnection();
System.out.println("Koneksi
Berhasil");
} catch (SQLException ex) {
System.err.println("Koneksi
Gagal");
}
}
}
//SumberL
http://eecchhoo.wordpress.com/2008/07/05/jdbc-dan-mysql-dengan-netbeans-part-1/
21.
Klik kanan PackageTambah di panel Projects –
New JFrame Form
22.
Class Name: JFrameTambah
23.
Finish
24.
Klik tombol Source
25.
Ketik script berikut:
/*
* To
change this template, choose Tools | Templates
* and
open the template in the editor.
*/
/*
*
JFrameTambah.java
*
*
Created on Sep 30, 2012, 4:53:09 AM
*/
package PackageTambah;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
*
@author komtas
*/
public class JFrameTambah {
/**
Creates new form JFrameTambah */
public JFrameTambah() {
initComponents();
}
/**
This method is called from within the constructor to
*
initialize the form.
*
WARNING: Do NOT modify this code. The content of this method is
*
always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
<editor-fold defaultstate="collapsed" desc="Generated
Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 183, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 110, Short.MAX_VALUE)
);
pack();
}//
</editor-fold>
/**
*
@param args the command line arguments
*/
public static void main(String args[]) throws SQLException {
Statement statement = ClassMhsTambah.getConnection().createStatement();
statement.executeUpdate("insert
into mahasiswa " +"values (" +
"'09','CC'" +
");");
statement.close();
}
}
//
Variables declaration - do not modify
//
End of variables declaration
//SumberL
http://eecchhoo.wordpress.com/2008/07/05/jdbc-dan-mysql-dengan-netbeans-part-1/
26.
Simpan
27.
Jalankan program (Run – Run File)
28.
Lihat tabel Mahasiswa di MySQL sudah ada data
mahasiswa:
Nomor: 09
Nama: CC
29.
Sliahkan dicoba dengan nomor dan nama yang lain
30.
Selesai
***
Sumber:
eecchhoo.wordpress.com/2008/07/05/jdbc-dan-mysql-dengan-netbeans-part-1/ . Nama File: JDBC dan MySQL
dengan NetBeans part 1 « @PakarJava.htm
"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
|
Tips Skripsi Program Studi Sistem Informasi |
|
No comments:
Post a Comment