
Apa yang harus di Pahami Pertama Kali.

Mempelajari Fungsi Fungsi Tool Dasar


Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.
Niat adalah ukuran dalam menilai benarnya suatu perbuatan, oleh karenanya, ketika niatnya benar, maka perbuatan itu benar, dan jika niatnya buruk, maka perbuatan itu buruk. ~ Imam An Nawaw
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.
Penyesalan akan hari kemaren, dan ketakutan akan hari esok adalah dua pencuri yang mengambil kebahagiaan saat ini. Regrets over yesterday and the fear of tomorrow are twin thieves that rob us of the moment.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.




CREATE TABLE IF NOT EXISTS `mahasiswa` (`nim` varchar(12) NOT NULL,`nama` varchar(40) NOT NULL,`alamat` varchar(200) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class Database2 extends JFrame
{
Connection con=null;
JLabel jLabel1 = new JLabel();
JTextField txtnama = new JTextField();
JLabel jLabel2 = new JLabel();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea txtalamat = new JTextArea();
JLabel jLabel3 = new JLabel();
JButton bthapus = new JButton();
JButton btcari = new JButton();
JButton btupdate = new JButton();
JTextField txtnim = new JTextField();
JLabel jLabel4 = new JLabel();
JButton btsimpan = new JButton();Database2()
{
setSize(320,280);
setLocation(100,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}void Koneksi()
{
try
{
String connectionURL = “jdbc:mysql://localhost/coba”;
String username = “root”;
String password = “root”;
Class.forName(“com.mysql.jdbc.Driver”);
con= DriverManager.getConnection(connectionURL, username , password );
System.err.println(“Sukses Koneksi”);
}
catch(Exception ex)
{
System.err.println(“Tidak Berhasil Koneksi”);
System.exit(1);
}
}
void simpan()
{
try
{
Statement statement = con.createStatement();
String sql=”insert into mahasiswa values(‘”+txtnim.getText()+”‘,’”+txtnama.getText()+”‘,’”+txtalamat.getText()+”‘);”;
statement.executeUpdate(sql);
statement.close();
JOptionPane.showMessageDialog(null,”Berhasil disimpan”);}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,”nim data sudah ada”);
System.err.print(ex);
}
}
public void cari()
{
try
{
Statement stat = con.createStatement();
String sql=”SELECT * FROM mahasiswa Where nim like’”+txtnim.getText()+”‘”;
ResultSet isi = stat.executeQuery(sql);if(isi.next())
{
txtnama.setText(isi.getString(1));
txtalamat.setText(isi.getString(2));
}
else
{
JOptionPane.showMessageDialog(null,”mahasiswa dengan nim tersebut tidak ada..!”);}stat.close();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,”Error :”+ex);
}
}
void update()
{
try
{
Statement stm=con.createStatement();
String sql=”update mahasiswa set nama=’”+txtnama.getText()+”‘, alamat=’”+txtalamat.getText()+”‘where nim=’”+txtnim.getText()+”‘”;stm.executeUpdate(sql);
stm.close();
JOptionPane.showMessageDialog(null,”Berhasil diedit”);}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,”Error :”+ex);
}
}
public void hapus()
{
try
{
Statement statement = con.createStatement();
String sql=”delete from mahasiswa “+ ” where nim=’”+txtnim.getText()+”‘”;
statement.executeUpdate(sql);
statement.close();
JOptionPane.showMessageDialog(null,”Data telah di Hapus”);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,”Error :”+ex);
}
}
void aksi()
{
btsimpan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
simpan();
}
});
btupdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
update();
}
});
bthapus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
hapus();
}
});
btcari.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cari();
}
});
}
private void initComponents() {getContentPane().setLayout(null);jLabel1.setText(“Contoh Aplikasi Database Sederhana”);
getContentPane().add(jLabel1);
jLabel1.setBounds(20, 10, 200, 14);
getContentPane().add(txtnama);
txtnama.setBounds(90, 70, 170, 20);jLabel2.setText(“Alamat”);
getContentPane().add(jLabel2);
jLabel2.setBounds(20, 100, 34, 14);txtalamat.setColumns(20);
txtalamat.setRows(5);
jScrollPane1.setViewportView(txtalamat);getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(90, 96, 166, 70);jLabel3.setText(“Nama”);
getContentPane().add(jLabel3);
jLabel3.setBounds(20, 70, 27, 14);bthapus.setText(“Delete”);getContentPane().add(bthapus);
bthapus.setBounds(180, 180, 73, 23);btcari.setText(“Cari”);getContentPane().add(btcari);
btcari.setBounds(200, 40, 51, 23);btupdate.setText(“Update”);getContentPane().add(btupdate);
btupdate.setBounds(90, 180, 73, 23);
getContentPane().add(txtnim);
txtnim.setBounds(90, 40, 100, 20);jLabel4.setText(“Nim”);
getContentPane().add(jLabel4);
jLabel4.setBounds(20, 40, 17, 14);btsimpan.setText(“Simpan”);getContentPane().add(btsimpan);
btsimpan.setBounds(10, 180, 67, 23);setVisible(true);
}public static void main(String args[])
{Database2 db2=new Database2();
db2.initComponents();
db2.Koneksi();
db2.aksi();
}
}