-Payal Umraliya
DESCLAIMER : THIS CODE IS SIMPLE JAVA CODE WITH APPLET
package ACTUALDATA;
import java.awt.*;
import java....
retaildetail r;
Vector cnames;
String[] rwdt;
public retaildetail()
{
//all labels
fnt=new Font("COMIC SANS SERIF",Font.BO...
fx=new JTextField(15);
pc=new JTextField(15);
pg=new JTextField(15);
ms=new JTextField(15);
noc=new JTextField(15);
incm=n...
add(jl3);
add(name);
add(nm);
add(resiadd);
add(radd);
add(contct);
add(cnt);
add(businessadd);
add(badd);
add(bcontct);
a...
JLabel jl2 = new JLabel("================================================================");
add(jl2);
add(in);
add(up);
a...
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost/try", "root", "checkmate"...
pc.setText(rs.getString(7));
pg.setText(rs.getString(8));
ms.setText(rs.getString(9));
noc.setText(rs.getString(10));
incm...
incm.setText(rs.getString("annualincome"));
photo.setText(rs.getString("photos"));
}
catch(SQLException se)
{
System.out.p...
} catch (Exception e) {
System.out.println("some problems occured in either searching or viewing or navigation or resettin...
JOptionPane.showMessageDialog(jf,"1 ROW INSERTED");
System.out.println("Data insereted");
viewcheckmatedata();
}
else if(s...
}
else if(str.equals("DELETE"))
{
String na = JOptionPane.showInputDialog("enter the name for delete");
nm.setText(na);
Sy...
nm.setText(rs.getString(1));
radd.setText(rs.getString(2));
cnt.setText(rs.getString(3));
badd.setText(rs.getString(4));
b...
rs.next();
settingdata();

}
else if(str.equals("PREV"))
{
rs.previous();
settingdata();
}
else if(str.equals("LAST"))
{
r...
System.out.println("sqlexception check your sqlstatement see detail n " + e);
}
catch(NullPointerException ne)
{
System.ou...
--------------------------------------------------------------------------------------------------------------------------...
Upcoming SlideShare
Loading in...5
×

CRUD(IN_UP_DEL) IN JAVA

315

Published on

HERE YOU CAN GET THE COMPLETE IDEA ABOUT CRUD OPERATION WITH JAVA APPLET..BEGINNERS CAN GET THE IDEA FROM HERE

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
315
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CRUD(IN_UP_DEL) IN JAVA

  1. 1. -Payal Umraliya DESCLAIMER : THIS CODE IS SIMPLE JAVA CODE WITH APPLET package ACTUALDATA; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import javax.swing.JOptionPane; import java.util.*; /** * * @author PAYAL */ public class retaildetail extends JPanel implements ActionListener { JLabel logo,name,resiadd,contct,businessadd,bcontct,faxno,mob,status,children,income,pic,pgr; JButton in,up,del,exit,f,n,l,p,srch,clr; JTextField nm,radd,cnt,badd,photo,bcnt,fx,pc,pg,ms,noc,incm; JTextArea radd1,badd1; String t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,na; Connection cn; Statement s; PreparedStatement insrt,dlt,serch,fst,nxt,prv,lst,ext,rst; Font fnt; JFrame jf; //JTable jt; ResultSet rs;
  2. 2. retaildetail r; Vector cnames; String[] rwdt; public retaildetail() { //all labels fnt=new Font("COMIC SANS SERIF",Font.BOLD,18); logo=new JLabel("CHECKMATE RETAILERS (YEAR 2014)"); name=new JLabel(" NAME : "); resiadd=new JLabel(" RESI. ADDRESS :"); contct=new JLabel(" CONTACT :"); businessadd=new JLabel("BUSI.ADDRESS :"); bcontct=new JLabel(" BUSI. CONTACT :"); faxno=new JLabel(" FAX NO :"); mob=new JLabel(" MOBILE :"); pgr=new JLabel(" PAGER :"); status=new JLabel("MARITALSTATUS :"); children=new JLabel("NO.OFCHILDREN :"); income=new JLabel("ANNUALINCOME :"); pic=new JLabel(" PHOTOGRAPH :"); //all textfields nm,radd,cnt,badd,photo,bcnt,fx,pc,pg,ms,noc,incm; nm=new JTextField(15); radd=new JTextField(15); cnt=new JTextField(15); badd=new JTextField(15); bcnt=new JTextField(15);
  3. 3. fx=new JTextField(15); pc=new JTextField(15); pg=new JTextField(15); ms=new JTextField(15); noc=new JTextField(15); incm=new JTextField(15); photo=new JTextField(15); // all btns in,up,del,exit,f,n,l,p,srch; in=new JButton("INSERT"); up=new JButton("UPDATE"); del=new JButton("DELETE"); exit=new JButton("EXIT"); f=new JButton("FIRST"); n=new JButton("NEXT"); l=new JButton("LAST"); p=new JButton("PREV"); srch=new JButton("CLICK TO SEARCH CUSTOMER"); clr=new JButton("RESET"); // adding all logo,name,resiadd,contct,businessadd,bcontct,faxno,mob,children,income,pic; //nm,radd,cnt,badd,photo,bcnt,fx,pc,pg,ms,noc,incm; //in,up,del,exit,f,n,l,p,srch; JLabel jl = new JLabel("================================================================"); add(logo); add(jl); add(srch); JLabel jl3 = new JLabel(" ");
  4. 4. add(jl3); add(name); add(nm); add(resiadd); add(radd); add(contct); add(cnt); add(businessadd); add(badd); add(bcontct); add(bcnt); add(faxno); add(fx); add(mob); add(pc); add(pgr); add(pg); add(status); add(ms); add(children); add(noc); add(income); add(incm); add(pic); add(photo);//add(jt); JLabel jl4 = new JLabel(" add(jl4); ");
  5. 5. JLabel jl2 = new JLabel("================================================================"); add(jl2); add(in); add(up); add(del); add(f); add(n); add(p); add(l); add(clr); add(exit); //end of adding in.addActionListener(this); up.addActionListener(this); del.addActionListener(this); srch.addActionListener(this); f.addActionListener(this); n.addActionListener(this); l.addActionListener(this); p.addActionListener(this); exit.addActionListener(this); clr.addActionListener(this); } //nm,radd,cnt,badd,photo,bcnt,fx,pc,pg,ms,noc,incm; public void connection() { try {
  6. 6. Class.forName("com.mysql.jdbc.Driver"); cn = DriverManager.getConnection("jdbc:mysql://localhost/try", "root", "checkmate"); s = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); System.out.println("connected"); JOptionPane.showMessageDialog(jf,"!!!...WELCOME CHECKMATE(96)... !!!n ...YOUR DATABASE CONNECTION IS ESTABLISHED....n ...YOU CAN ABLE NAVIGATE AND MANAGE ALL DATA OF YOUR CUSTOMERS NOW..."); viewcheckmatedata(); } catch (SQLException e) { System.out.println("sorry!!! some problems are occured in connectionn see details " + e); } catch (ClassNotFoundException ce) { System.out.println("class not found see detailsn " + ce); } catch (Exception e) { System.out.println("some problems are found see detailsn " + e); } } void viewcheckmatedata() { try { rs=s.executeQuery("select * from cust"); rs.next(); nm.setText(rs.getString(1)); radd.setText(rs.getString(2)); cnt.setText(rs.getString(3)); badd.setText(rs.getString(4)); bcnt.setText(rs.getString(5)); fx.setText(rs.getString(6));
  7. 7. pc.setText(rs.getString(7)); pg.setText(rs.getString(8)); ms.setText(rs.getString(9)); noc.setText(rs.getString(10)); incm.setText(rs.getString(11)); photo.setText(rs.getString(12)); } catch(Exception e) { System.out.println("some problems are found see detailsn " + e); } } void settingdata() { try { nm.setText(rs.getString("name")); radd.setText(rs.getString("address")); cnt.setText(rs.getString("contact")); badd.setText(rs.getString("businessAddress")); bcnt.setText(rs.getString("businessContact")); fx.setText(rs.getString("fax")); pc.setText(rs.getString("mobile")); pg.setText(rs.getString("pager")); ms.setText(rs.getString("maritalstatus")); noc.setText(rs.getString("children"));
  8. 8. incm.setText(rs.getString("annualincome")); photo.setText(rs.getString("photos")); } catch(SQLException se) { System.out.println("some problems occured "+ se); } catch(Exception e) { System.out.println("some problems occured in either searching or viewingn " + e); } } void resetdata() { try { nm.setText(""); radd.setText(""); cnt.setText(""); badd.setText(""); bcnt.setText(""); fx.setText(""); pc.setText(""); pg.setText(""); ms.setText(""); noc.setText(""); incm.setText(""); photo.setText("");
  9. 9. } catch (Exception e) { System.out.println("some problems occured in either searching or viewing or navigation or resettingn " + e); } } public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); try { if(str.equals("INSERT")) { String insql="insert into cust values(?,?,?,?,?,?,?,?,?,?,?,?)"; insrt=cn.prepareStatement(insql); insrt.setString(1,nm.getText());// insrt.setString(2,radd.getText());// insrt.setInt(3,Integer.parseInt(cnt.getText())); insrt.setString(4,badd.getText());// insrt.setInt(5,Integer.parseInt(bcnt.getText())); insrt.setInt(6,Integer.parseInt(fx.getText())); insrt.setInt(7,Integer.parseInt(pc.getText())); insrt.setString(8,pg.getText());// insrt.setString(9,ms.getText()); insrt.setInt(10,Integer.parseInt(noc.getText())); insrt.setInt(11,Integer.parseInt(incm.getText())); insrt.setString(12,photo.getText());// insrt.executeUpdate();
  10. 10. JOptionPane.showMessageDialog(jf,"1 ROW INSERTED"); System.out.println("Data insereted"); viewcheckmatedata(); } else if(str.equals("UPDATE")) { String na = JOptionPane.showInputDialog("plz enter name which u want to edit"); nm.setText(na); String insql="update cust set address=?,contact=?,businessAddress=?,businessContact=?,fax=?,mobile=?,pager=?,maritalstatus=?,children=?,an nualincome=?,photos=?where name=?"; insrt = cn.prepareStatement(insql); insrt.setString(1, radd.getText());// insrt.setInt(2, Integer.parseInt(cnt.getText())); insrt.setString(3, badd.getText());// insrt.setInt(4, Integer.parseInt(bcnt.getText())); insrt.setInt(5, Integer.parseInt(fx.getText())); insrt.setInt(6, Integer.parseInt(pc.getText())); insrt.setInt(7, Integer.parseInt(pg.getText()));// insrt.setString(8, ms.getText()); insrt.setInt(9, Integer.parseInt(noc.getText())); insrt.setInt(10, Integer.parseInt(incm.getText())); insrt.setString(11, photo.getText());// insrt.setString(12,nm.getText()); insrt.executeUpdate(); JOptionPane.showMessageDialog(jf,"1 ROW UPDATED"); System.out.println("DATA UPDATED"); viewcheckmatedata();
  11. 11. } else if(str.equals("DELETE")) { String na = JOptionPane.showInputDialog("enter the name for delete"); nm.setText(na); System.out.println("query reading"); String insql = "delete from cust where name=?"; dlt = cn.prepareStatement(insql); System.out.println("preparing"); dlt.setString(1,nm.getText()); System.out.println("deleting " + na); System.out.println("exeecutes update statement"); dlt.executeUpdate(); JOptionPane.showMessageDialog(jf, "1 ROW DELETED"); System.out.println("DATA DELETED"); viewcheckmatedata(); } else if(str.equals("CLICK TO SEARCH CUSTOMER"))//nm,radd,cnt,badd,photo,bcnt,fx,pc,pg,ms,noc,incm; { String na = JOptionPane.showInputDialog("enter the name for delete"); nm.setText(na); String insql="select * from cust where name=?"; serch=cn.prepareStatement(insql); serch.setString(1, nm.getText()); rs=serch.executeQuery(); rs.next(); JOptionPane.showMessageDialog(jf, "DATA FOUND");
  12. 12. nm.setText(rs.getString(1)); radd.setText(rs.getString(2)); cnt.setText(rs.getString(3)); badd.setText(rs.getString(4)); bcnt.setText(rs.getString(5)); fx.setText(rs.getString(6)); pc.setText(rs.getString(7)); pg.setText(rs.getString(8)); ms.setText(rs.getString(9)); noc.setText(rs.getString(10)); incm.setText(rs.getString(11)); photo.setText(rs.getString(12)); /* if(rs.getString(1)!=na) { JOptionPane.showMessageDialog(jf, "NO DATA FOUND AVAILABLE WITH THIS NAME TRY AGAIN "); // String na2 = JOptionPane.showInputDialog("enter the name for delete"); }*/ } else if(str.equals("FIRST")) { int cntr=1; cntr++; rs.first(); settingdata(); } else if(str.equals("NEXT")) {
  13. 13. rs.next(); settingdata(); } else if(str.equals("PREV")) { rs.previous(); settingdata(); } else if(str.equals("LAST")) { rs.last(); settingdata(); } else if (str.equals("RESET")) { resetdata(); } else { s.close(); cn.close(); System.exit(0); } } catch(SQLException e) {
  14. 14. System.out.println("sqlexception check your sqlstatement see detail n " + e); } catch(NullPointerException ne) { System.out.println("null object referenses are set see detail n " + ne); } catch(Exception e) { System.out.println("some problems are found see detailsn " + e); return; } } public static void main(String[] args) { // TODO code application logic here retaildetail r=new retaildetail(); r.connection(); JFrame jf=new JFrame("..........CheckMate(96)............"); jf.setContentPane(r); jf.setVisible(true); jf.setSize(300,600); jf.setResizable(false); } } END OF CODING
  15. 15. -------------------------------------------------------------------------------------------------------------------------------------------------------Database: -- Database: `checkmate` -- -------------------------------------------------------hello there my DATABASE name is :--------->checkmate CREATE TABLE IF NOT EXISTS `cust` ( `name` varchar(20) DEFAULT NULL, `address` varchar(200) DEFAULT NULL, `contact` int(20) DEFAULT NULL, `businessAddress` varchar(200) DEFAULT NULL, `businessContact` int(20) DEFAULT NULL, `fax` int(20) DEFAULT NULL, `mobile` int(20) DEFAULT NULL, `pager` int(20) DEFAULT NULL, `maritalstatus` varchar(20) DEFAULT NULL, `children` int(20) DEFAULT NULL, `annualincome` int(50) DEFAULT NULL, `photos` varchar(10000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- Dumping data for table `cust` INSERT INTO `cust` (`name`, `address`, `contact`, `businessAddress`, `businessContact`, `fax`, `mobile`, `pager`, `maritalstatus`, `children`, `annualincome`, `photos`) VALUES ('payal', '38sagar', 1234567890, 'hyderabad', 678905, 56, 1234567890, 1, 'merried', 2, 99000000, 'not available'), ('dhaval', '84shinagar', 1234567890, 'hyderabad', 678905, 56, 1234567890, 1, 'merried', 2, 99000000, 'not available'), ('parth', '3santos', 1234567890, 'hyderabad', 678905, 56, 1234567890, 1, 'merried', 2, 999000000, 'not available');

×