Skip to main content

Java Program to delete record using JFrame and Prepaired Statement

Java Program to delete record using JFrame and Prepaired Statement


Here is table Design 

Create table demo using two column as id  and Dname , id is primary key 


Program source code 


+import javax.swing.*;  
import java.awt.event.*;  
import java.sql.*;

public class FrameDelete extends JFrame implements ActionListener{  
    JTextField tf1,tf2,tf3;  
    JButton b1,b2;  
JLabel l1,l2;

Connection con;    PreparedStatement psmt;   int result;
//declaration of control 
  FrameDelete(){  
        JFrame f= new JFrame("InsertDemo");  
//
l1=new JLabel("Enter RollNo");
l1.setBounds(150,10,150,50);
        tf1=new JTextField();  
        tf1.setBounds(150,50,150,20);  
tf3=new JTextField();  
        tf3.setBounds(150,150,150,20);
tf3.setEditable(false);   
        b1=new JButton("Delete");  
        b1.setBounds(150,200,100,50);  
        b2=new JButton("Clear");  
        b2.setBounds(250,200,100,50); 
        b1.addActionListener(this);  // event handing power 
        b2.addActionListener(this);  
f.add(l1); 
        f.add(tf1);f.add(tf3);f.add(b1);f.add(b2);  
        f.setSize(500,300);  
        f.setLayout(null);  
        f.setVisible(true);  
f.setDefaultCloseOperation(EXIT_ON_CLOSE);

    }         
    public void actionPerformed(ActionEvent e) {  
       String s1=tf1.getText(); 
            int id =Integer.parseInt(s1);  
  
       //String nm=tf2.getText();  
   
        
      
        if(e.getSource()==b1){  
  try{
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  // loding Driver
  
con=DriverManager.getConnection("jdbc:odbc:demodb");
 
  psmt=con.prepareStatement("delete from demo where id=?");
  
            psmt.setInt(1,id);
 
int result=psmt.executeUpdate();
  tf3.setText("record Deleted");  
  
  con.close();
  }
  catch(Exception e1)
  {
  tf3.setText("Error" +e1);
  
  }
            
        }else if(e.getSource()==b2){  
           tf1.setText(" ");
  //tf2.setText(" ");
    tf3.setText("record cleared");
        }  
        
    }  
public static void main(String[] args) {  
    new FrameDelete();  
} }  


You Can Find Related post 





Java Program to delete record using JFrame and Prepaired Statement


Java Program to insert record using JFrame and Prepaired Statement

Java Program to update record using JFrame and Prepaired Statement


Java Program to Display  record using JFrame and Prepaired Statement


Labels

Show more

Popular posts from this blog

jbutton Click Event example Advance Java

Jbutton Click Event example Advance Java  Change frame Color On Button click Advance Java  import javax.swing.*; import java.awt.*; import java.awt.event.*;      class FrameDemo extends JFrame implements ActionListener {       JButton btn; Container c;          FrameDemo() {               c=this.getContentPane();        JButton btn= new JButton("Click"); btn.setBounds(100,50,100,50);         c.add(btn);         c.setLayout(null);        btn.addActionListener(this); }                    public void actionPerformed(ActionEvent a) {                     c.setBackground(Color.RED); } }        // cre...

java project using CMD Source Code Download

java project using CMD Source Code Download import java.sql.*; import java.*; import java.io.*; class whileInfinite { public static void main(String s[]) {  try{ while(true) { System.out.println("Select Your Choice :"); System.out.println("________________________________________"); System.out.println("1. Insert record :"); System.out.println("2. disply all records :"); System.out.println("3. display Specific record :"); System.out.println("4. update record:"); System.out.println("5. delete Record:"); System.out.println("6. Exit:"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));           System.out.println("Enter your choice"); int choice = Integer.parseInt(reader.readLine()); System.out.println("yo entered"+ choice); switch(choice) { case 1:whileInfinite obj=new whileInfin...

Nested Classes sample program

Nested Classes In Java, just like methods, variables of a class too can have another class as its member. Writing a class within another is allowed in Java. The class written within is called the nested class , and the class that holds the inner class is called the outer class . class Outer {  private class Inner  {    void dispaly()    {        System.out.println("this is inner class");       }   }  void call()  {    Inner obj=new Inner();    obj.dispaly();  } } class InnerDemo { public static void main(String s[]) {  Outer ob=new Outer();  ob.call(); } } Example solve watch video for understanding  // inner class By Prakash Sonar class outer {  private class Inner  {    void display()   {      System.out.println...