wood burning stoves 2.0*
The moose likes JDBC and the fly likes Invaild Cursor State Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invaild Cursor State" Watch "Invaild Cursor State" New topic
Author

Invaild Cursor State

Amna Ibrahim
Greenhorn

Joined: Oct 13, 2003
Posts: 3
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() );
}
}
}
Samuel C. Michaelis
Greenhorn

Joined: Oct 17, 2003
Posts: 4
Hello Amna,
look at this code-sample, and imagine rs being an empty ResultSet

(1) rs.next() returns false, because there's no next recordset
(2) now, your driver throws an Exception ,because there is no recordset available at this point
So me'd write following code

Hope, I could help you,
best regards,
Samuel
Amna Ibrahim
Greenhorn

Joined: Oct 13, 2003
Posts: 3
Thankx for your help....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invaild Cursor State
 
Similar Threads
mysql problems in netbeans
searching database
Size of ResultSet...
Invalid Coursor Name...
JTable type yes/no