Results 1 to 3 of 3
  1. #1
    kwesiaryee is offline Member
    Join Date
    Apr 2008
    Rep Power

    Default database with mysql using the netbeans 6.0

    How can I create an actionlistener to insert, update and delete new data into mysql database using jbutton.

    Please help me, I am comfused


  2. #2
    lonelyShoes is offline Member
    Join Date
    May 2008
    Rep Power


    The logic behind this is as follows:
    1) The class you add the JButton to should implement ActionListener. For example:
    Java Code:
    public class MyPanel extends JPanel implements ActionListener
    2) When you create the JButton, you must add an ActionListener to it. You do this like so:
    Java Code:
    3)In your actionPerformed method, check to see if the ActionEvent was generated by the JButton:
    Java Code:
    public void actionPerformed(ActionEvent ae){
    if (ae.getSource().equals(myButton){
    //......your code here.....
    That is how you create a JButton, and get the ActionEvent data from it. What you would need to do in your particular case is create JButtons for Insert, Update, and Delete, and then implement the JDBC code for each situation inside your actionPerformed method. That handles the Swing side of the equation. Is that where you had difficulty, or is the JDBC code giving you problems?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

Similar Threads

  1. MySQL Database and Java
    By shaggymac in forum Advanced Java
    Replies: 1
    Last Post: 05-01-2008, 09:01 PM
  2. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 11:33 AM
  3. Help needed with updating mysql database
    By SilentCodingOne in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 11:23 PM
  4. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM
  5. MySql in NetBeans 5.0
    By javagal in forum NetBeans
    Replies: 6
    Last Post: 07-04-2007, 02:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts