what is "SQLException: Operation not allowed after ResultSet closed"

i compile my program is no problem but when i run it it come out the error "SQLException: Operation not allowed after ResultSet closed"

what the error actually is?

here is my code:

import java.net.*;

import java.util.*;

import java.io.*;

import java.sql.*;

import java.util.Date;

import java.text.SimpleDateFormat;

publicclass attend{

public attend(String stud_id){

SimpleDateFormat sdf=new SimpleDateFormat("EEEE");

SimpleDateFormat sdf2=new SimpleDateFormat("hh:mm:ss");

Date c=new Date();

String day=sdf.format(c);

String time=sdf2.format(c);

System.out.println(day);

System.out.println(time);

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

}

catch (Exception E){

System.out.println("Unable to load driver.");

E.printStackTrace();

}

try{

Connection C = DriverManager.getConnection("jdbc:mysql://localhost/attendance","root","");

Statement S = C.createStatement();

ResultSet rs = S.executeQuery("select "+

"student.student_id,student.student_name,student.email,lecturer.lecturer_name,course.course_desc,"+

"tsubject.tsubject_desc, tsubject.stime, tsubject.sday from student,stu_course,course_sub,course,tsubject,lecturer "+

"where student.student_id=stu_course.student_id AND stu_course.course_id=course_sub.course_id AND "+

"course_sub.course_id=course.course_id AND "+

"course_sub.tsubject_id=tsubject.tsubject_id AND lecturer.lecturer_id=tsubject.lecturer_id AND student.student_id="+stud_id);

ResultSetMetaData rsStruc = rs.getMetaData();

while (rs.next()){

String student_id=rs.getString("student_id");

String stud_name=rs.getString("Student_name");

String email=rs.getString("email");

String lec_name=rs.getString("lecturer_name");

String course=rs.getString("course_desc");

String subject=rs.getString("tsubject_desc");

String stime=rs.getString("stime");

String sday=rs.getString("sday");

rs.close();

C.close();

}

}

catch (Exception E){

System.out.println("SQLException: " + E.getMessage());

}

}

publicstaticvoid main(String args[])

{

new attend("0503137");

}

}

[4022 byte] By [albert85a] at [2007-11-26 21:28:27]
# 1

The error actually is exactly what the error message says it is. People who make up these messages don't just randomly pick words from a dictionary, you know. They put words in that explain the problem.

You will find this error message occurs when you try to read data from the second row in the ResultSet. After you read data from the first row you close the ResultSet.

DrClapa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 2
while (rs.next()) {....rs.close();}you close the result set inside the loop, then you go back up and try to get another row, but the result set is closed. Only close the result set when you are done processing all the rows. (outside the loop)
dmbdmba at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 3

This thread gives more credence to my suggestion that they should have just made all errors just say "AN ERROR HAPPENED" instead of providing detail, as the detail just seems to be lost on so many.

Just kidding. Of course that suggestion would harm the rest of us who can read and think.

On a positive note, at least the OP didn't translate the actual error message into something like "it gives me an error" like I'm so tired of seeing so many do.

warnerjaa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 4

i want to ask something...

i have a java gui attGUI class file. i want to called the attend class which is state upstair

when the user click on ok button. i post up the code as well of my attGUI class:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class attGUI extends JFrame implements ActionListener{

private JTextField id;

private JLabel label1;

private JLabel topLabel;

private JButton ok;

public attGUI (String title){

buildGUI();

setTitle(title);

pack();

setVisible(true);

JFrame.setSize(32);

}

private void buildGUI(){

Container contentPane=getContentPane();

contentPane.setLayout(new BorderLayout());

id=new JTextField(10);

label1=new JLabel("Student ID");

topLabel=new JLabel("Welcome to Student Attendance System!!!");

topLabel.setFont(new java.awt.Font("Franklin Gothic Demi", 1, 18));

ok=new JButton("OK");

ok.addActionListener(this);

JPanel inputPanel=new JPanel();

inputPanel.add(label1);

inputPanel.add(id);

contentPane.add("North",topLabel);

contentPane.add("Center",inputPanel);

contentPane.add("South",ok);

}

public void actionPerformed(ActionEvent e){

if(e.getSource() == ok)

{

String Stuid= id.getText();

attend a= new attend(Studid);// is it called like this?

}

}

public static void main(String args[])

{

new attGUI("Student Attendance System");

}

}

albert85a at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 5

> attend a= new attend(Studid);// is it called like this?

All I can tell you is that if you have a class named "attend" and it has a constructor taking a String argument, then the code above will create an attend instance using that constructor. Other than that, how should we know how you're supposed to use your own homemade class?

warnerjaa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 6

> This thread gives more credence to my suggestion that

> they should have just made all errors just say "AN

> ERROR HAPPENED" instead of providing detail, as the

> detail just seems to be lost on so many.

Not a good idea I have a radical new idea. All error messages should save space by just returning a number. An out of date list of the error messages associated with the error number should be available from the software manufacturer.

sabre150a at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 7

> Not a good idea I have a radical new idea. All error

> messages should save space by just returning a

> number. An out of date list of the error messages

> associated with the error number should be available

> from the software manufacturer.

Available if you mail them a self-addressed, stamped envelope and

a cashier's cheque for 57 cents.

DrLaszloJamfa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 8

> Not a good idea I have a radical new idea. All error

> messages should save space by just returning a

> number. An out of date list of the error messages

> associated with the error number should be available

> from the software manufacturer.

And the description of most of the error messages should say "Probable programmer error".

DrClapa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...
# 9

> On a positive note, at least the OP didn't translate

> the actual error message into something like "it

> gives me an error" like I'm so tired of seeing so

> many do.

... as opposed to what this same guy did on his very next thread:

http://forum.java.sun.com/thread.jspa?threadID=5147739

:-(

warnerjaa at 2007-7-10 3:08:59 > top of Java-index,Java Essentials,Java Programming...