I am having the Invaild Cursor State when I run the bellow code. The code is runing fine in all cases except when I want to find record which is not in the dB:- I am posting this code for the second time.....
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class FindRecord implements ActionListener
{
private DataInputPanel fields;
private JTextArea output;
private Connection connection;
public FindRecord( Connection c, DataInputPanel f, JTextArea o )
{
connection = c;
fields = f;
output = o;
}
public void actionPerformed( ActionEvent e )
{
try
{
if ( !fields.TelNum.getText().equals( "" ))
{
Statement statement =connection.createStatement();
String query = "SELECT * FROM dedEmps WHERE Tel = '" + fields.TelNum.getText() +"'";
output.append( "\nSending query: " + connection.nativeSQL( query ) + "\n" );
ResultSet rs = statement.executeQuery( query );
display( rs );
output.append( "\nQuery successful\n" );
}
else
fields.TelNum.setText( "Enter Telephone Number here then press Find" );
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
output.append( sqlex.toString() );
}
}
public void display( ResultSet rs )
{
try
{
rs.next();
String recordNumber = rs.getString(1);
if( recordNumber != null )
{
fields.EmpNum.setText(recordNumber);
fields.FName.setText( rs.getString(2));
fields.DeptName.setText( rs.getString(3));
fields.FloorNum.setText( rs.getString(4));
fields.TelNum.setText(rs.getString(5));
}
else
{output.append( "\nNo record found\n" );}
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
output.append( sqlex.toString() );
}
}
}