Professional Documents
Culture Documents
Advance Java SLE
Advance Java SLE
Add Customer:
Update Customer:
Clear data from the text box:
Exit Button:
Program Execution will stop after clicking on ‘Yes’ in the Exit input dialog box.
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Customer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
*
* @author SABAHAT KHAN
*/
public class Customer extends javax.swing.JFrame {
/**
* Creates new form Customer
*/
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs= null;
DefaultTableModel model = new DefaultTableModel();
public Customer() {
initComponents();
conn = Customer.ConnectDb();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 51, 51));
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
return null;
}
while(rs.next()){
String id = rs.getString("Cid");
String Name = rs.getString("Name");
String Contact = rs.getString("Contact");
String Address = rs.getString("Address");
String Pincode = rs.getString("Pincode");
tblModel.addRow(tbData);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
try
{
String sql = "INSERT INTO Customer(Cid,Name,Contact,Address,Pincode)
VALUES (?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1,jtxtid.getText());
pst.setString(2,jtxtname.getText());
pst.setString(3,jtxtcontact.getText());
pst.setString(4,jtxtaddress.getText());
pst.setString(5,jtxtpincode.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "System Update Completed");
rs.close();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
//Update_table();
}
rs=pst.executeQuery();
if(rs.next()){
String add1=rs.getString("Cid");
jtxtid.setText(add1);
String add2=rs.getString("Name");
jtxtname.setText(add2);
String add3=rs.getString("Contact");
jtxtcontact.setText(add3);
String add4=rs.getString("Address");
jtxtaddress.setText(add4);
String add5=rs.getString("Pincode");
jtxtpincode.setText(add5);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Customer.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Customer.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Customer.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Customer.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
Thank You!