logo bloglogo blog
Selamat Datang Di Blog Hanif
Terima kasih atas kunjungan Anda di blog Hanif ,
semoga apa yang saya share di sini bisa bermanfaat dan memberikan motivasi pada kita semua
untuk terus berkarya dan berbuat sesuatu yang bisa berguna untuk orang banyak.

CODING JAVA EDIT / SCRIPT JAVA EDIT



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

public class frame1 extends javax.swing.JFrame {
public Connection kon;
public String sql="";
public Statement stat;
public ResultSet rs;

    /** Creates new form frame1 */
    public frame1() {
        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() {

        txtkode = new javax.swing.JTextField();
        txtnama = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("jButton2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(150, 150, 150)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtnama, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtkode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtkode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addContainerGap(197, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                      

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
    try {
            Class.forName("com.mysql.jdbc.Driver");
            kon=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbjava", "root", "");
            sql="select * from barang where kode='"+txtkode.getText()+"'";
            stat=kon.createStatement();
            rs=stat.executeQuery(sql);
            while(rs.next())
            {
                txtnama.setText(rs.getString("nama"));
               
                javax.swing.JOptionPane.showMessageDialog(null, "Data Ditemukan");
            }
        } catch (Exception e) {}      
}                                      

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
    try {
            Class.forName("com.mysql.jdbc.Driver");
            kon=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbjava", "root", "");
            sql="update barang set nama='"+txtnama.getText()+"' where kode='"+txtkode.getText()+"'";
            stat=kon.createStatement();
            stat.execute(sql);
            txtkode.setText("");
            txtnama.setText("");
           
            txtkode.requestFocus();
            javax.swing.JOptionPane.showMessageDialog(null, "Data Sudah Diedit");
        } catch (Exception e) {
        }

   
}                                      

Enter your email address to get update from Hanif.
Print PDF
Next
« Prev Post
Previous
Next Post »

Copyright © 2013. HANIF NURMAN - Created by Hanif