SlideShare une entreprise Scribd logo
1  sur  15
-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;
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);
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("

");
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);

");
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 {
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));
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"));
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("");
} 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();
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();
}
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");
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"))
{
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)
{
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
-------------------------------------------------------------------------------------------------------------------------------------------------------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');

Contenu connexe

Similaire à CRUD(IN_UP_DEL) IN JAVA

All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
Presentation aalpert v6а+++
Presentation aalpert v6а+++Presentation aalpert v6а+++
Presentation aalpert v6а+++
Natalia Gorak
 

Similaire à CRUD(IN_UP_DEL) IN JAVA (20)

Building Maintainable Applications in Apex
Building Maintainable Applications in ApexBuilding Maintainable Applications in Apex
Building Maintainable Applications in Apex
 
Ip project
Ip projectIp project
Ip project
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
Android examples
Android examplesAndroid examples
Android examples
 
Redux "Bad" Practices - A List of 13 Bad Practices and How to Avoid Them
Redux "Bad" Practices - A List of 13 Bad Practices and How to Avoid ThemRedux "Bad" Practices - A List of 13 Bad Practices and How to Avoid Them
Redux "Bad" Practices - A List of 13 Bad Practices and How to Avoid Them
 
Xenogenetics
XenogeneticsXenogenetics
Xenogenetics
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
 
Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Presentation aalpert v6а+++
Presentation aalpert v6а+++Presentation aalpert v6а+++
Presentation aalpert v6а+++
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Java and xml
Java and xmlJava and xml
Java and xml
 
Vcs23
Vcs23Vcs23
Vcs23
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

CRUD(IN_UP_DEL) IN JAVA

  • 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. 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. 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(" ");
  • 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. 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. 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. 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. } 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. 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. } 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");
  • 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. 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. -------------------------------------------------------------------------------------------------------------------------------------------------------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');