import java.awt.Panel;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import java.sql.DriverManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class first {

    JButton b1= new JButton("save"),b2=new JButton("delete");
    JFrame frame1 = new JFrame("Ghar Hisab");
    Panel panel = new Panel();
    JTextField text1 = new JTextField(20);
    JTextField text2 = new JTextField(20);

    JLabel label1= new JLabel("FIRST NAME");
    JLabel label2= new JLabel("LAST NAME");
    int people;
    add l = new add();
    delete d = new delete();
            public void frame(){
                panel.add(label1);
                panel.add(text1);
                panel.add(label2); panel.add(text2); panel.add(b1); panel.add(b2);

                frame1.getContentPane().add(panel);
                frame1.setSize(800,800);
                frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame1.setVisible(true);
            //  people=Integer.parseInt(JOptionPane.showInputDialog("Enter the number of people")); 
                }

            public void name(){

                    b1.addActionListener(l);
                    b2.addActionListener(d);



            }   


        private class add implements ActionListener {



        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/people","root","desire");
            Statement stat= (Statement) con.createStatement();
            String s1=text1.getText();
            String s2=text2.getText();
            stat.executeUpdate("insert into name(first,last)values('"+s1+"','"+s2+"')");
            text1.setText(null);
            text2.setText(null);


            }

            catch(Exception e1){
                System.out.println(e1);
            }
        }




        }

        private class delete implements ActionListener{

            @Override
            public void actionPerformed(ActionEvent event) {
                // TODO Auto-generated method stub
                try{
                    Class.forName("com.mysql.jdbc.driver");
                    Connection con1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/people","root","desire");
                    Statement stat= (Statement) con1.createStatement();
                    String s1=text1.getText();
                    String s2=text2.getText();
                    stat.executeUpdate("DELETE FROM 'people'.'name' WHERE 'name'.'first' ='"+s1+"' AND 'name'.'last'='"+s2+"'LIMIT=1");
                    text1.setText(null);
                    text2.setText(null);



                }

                catch(Exception e2){ 
                    System.out.println("this is the xception "+ e2);
                }


            }

        }

}
share|improve this question

80% accept rate
Need more information, Such as verbal description of what has happened and a log cat – Owl Aug 9 '11 at 5:49
@krio - It's swing, there is no logcat... – Binyamin Sharet Aug 9 '11 at 5:50
Have you tried using the -cp option? – shinkou Aug 9 '11 at 5:50
@MByD, Too much Android, My bad – Owl Aug 9 '11 at 5:52
1  
@krio - hehe... happens to all of us :) – Binyamin Sharet Aug 9 '11 at 5:52
feedback

2 Answers

up vote 1 down vote accepted

You need to include the jdbc jar in the project and add it to the path.

share|improve this answer
have included the .jar file... the connection is properly working in case of private class add. but in case of private class delete it fails – Apurva Mayank Aug 9 '11 at 6:44
feedback

Make sure that jdbc .jar file is in your classpath.

share|improve this answer
have included the .jar file... the connection is properly working in case of private class add. – Apurva Mayank Aug 9 '11 at 6:43
the connection is working with the add class... but not with delete class – Apurva Mayank Aug 9 '11 at 6:49
Capitalize the D on driver within the delete class: "com.mysql.jdbc.Driver" – js3v Aug 9 '11 at 13:17
thanks .. it worked,,,, but now it says that syntax is incorrect ... can u tell me the correct syntax – Apurva Mayank Aug 10 '11 at 6:48
hmmm can you paste the actual error? Also, it doesn't look like you are using the loaded class anywhere. Shouldn't you cast it to an object? Class driver = Class.forName("com.mysql.jdbc.Driver") .. I haven't ever used the forName() method in an application so tell me if I am up the wrong tree here.. – js3v Aug 10 '11 at 13:57
show 1 more comment
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.