Results 1 to 2 of 2
  1. #1
    sami is offline Member
    Join Date
    Aug 2007
    Rep Power

    Default jdbc/ swing code problem


    Following is my code to retrive data from my ms-access table NAME to display the employee name and his id.

    But iam getting the error as

    can not resolve the symbol varaible addbutton
    in the line (e.getSource == addbutton)

    also can not resolve symbol
    variable rs ( which is my Resultset that i have created in my code).

    can any body help in solving my problem to retrieve and display the values from the table to the textfields.

    Thanks in advance.

    code starts:

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

    public class sample1 extends JFrame implements ActionListener
    public sample1()
    super("Sample application");

    // JPanel p = new JPanel();

    JLabel empid = new JLabel("Employee id");

    JLabel empnamelabel = new JLabel("Employee name");

    JTextField id = new JTextField(20);

    JTextField empname = new JTextField(20);

    JButton addbutton = new JButton("Add");

    Container c = getContentPane();

    // c.add(p);


    addbutton.addActionListener( new ActionListener);
    add( addbutton );

    //load the JDBC-ODBC bridge driver

    try {


    catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");

    // Get the connection

    Connection conn = DriverManager.getConnection("jdbc:odbc:empdsn");

    // create a statement object, resultset object and prepared statement to pass sql queries.

    Statement st = conn.createStatement();

    st.executeQuery("Select * from NAME");

    ResultSet rs = st.getResultSet();



    public static void main(String args[])

    sample1 sam = new sample1(sam);

    new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit( 0 );


    public void actionPerformed(ActionEvent e)
    if(e.getSource()==addbutton) {
    catch(Exception ee) {}



  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    England, Bath
    Rep Power


    From a very quick look it would appear your first major problem is in the creation of addButton:
    Java Code:
    addbutton.addActionListener([COLOR="DarkRed"] new ActionListener[/COLOR]);
    add( addbutton );
    The ActionListener is an interface and therefore you need to either provide a class which implements the interface in it's place or provide the implementation that you want for the ActionListener in place :
    Java Code:
    addbutton.addActionListener( new ActionListener(){
    	public void actionPerformed(ActionEvent arg0) {
    		//TODO Replace this with your actual implementation
    		System.out.println("You have clicked add");
    add( addbutton );
    That will get you past the first hurdle but you have some other very serious issues with your code.

    I would suggest you grab yourself a basic java book and work through that.

Similar Threads

  1. Jdbc problem
    By abhiN in forum JDBC
    Replies: 1
    Last Post: 03-21-2008, 06:10 AM
  2. EventHandling code for Swing application
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-07-2007, 01:06 PM
  3. code for making a java swing program a demo verson
    By fakhruddin in forum AWT / Swing
    Replies: 1
    Last Post: 11-27-2007, 09:54 PM
  4. JDBC problem
    By Swamipsn in forum New To Java
    Replies: 1
    Last Post: 08-13-2007, 06:05 PM
  5. JDBC problem
    By peiceonly in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-03-2007, 01:42 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