Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2007, 02:53 AM
Member
 
Join Date: Aug 2007
Posts: 1
sami is on a distinguished road
jdbc/ swing code problem
jdbc/swing
============

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


c.add(addbutton);
c.add(empnamelabel);
c.add(empname);
c.add(id);
c.add(empid);



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




//load the JDBC-ODBC bridge driver


try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

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


// Get the connection

Connection conn = DriverManager.getConnection("jdbcdbc: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();


pack();
setVisible(true);

}


public static void main(String args[])
{

sample1 sam = new sample1(sam);


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

}



public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addbutton) {
try
{
while(rs.next())
{
id.setText(rs.getString(1));
empname.setText(rs.getString(2));
}
}
catch(Exception ee) {}

}
}


}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-13-2007, 03:26 PM
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
From a very quick look it would appear your first major problem is in the creation of addButton:
Code:
addbutton.addActionListener( new ActionListener); 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 :
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.
Shane.
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jdbc problem abhiN Database 1 03-21-2008 06:10 AM
EventHandling code for Swing application Java Tip Java Tips 0 12-07-2007 01:06 PM
code for making a java swing program a demo verson fakhruddin AWT / Swing 1 11-27-2007 09:54 PM
JDBC problem Swamipsn New To Java 1 08-13-2007 07:05 PM
JDBC problem peiceonly Threads and Synchronization 2 08-03-2007 02:42 PM


All times are GMT +3. The time now is 02:57 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org