2013-03-20 47 views
0

我越來越錯誤,當我試着做下面的代碼。我無法理解這個netbeans錯誤。錯誤如下。Jtable和MySql

Mar 21, 2013 2:28:19 AM timetable.generator.JFTTGenerator6 jButton2ActionPerformed 
SEVERE: null 
java.sql.SQLException: Before start of result set 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) 

請幫我!!!!

String subj=(String) jTable1.getValueAt(0,1); 
Connection con = Driver.connect(); 
ResultSet lec1=Handler.getData(con, 
"select lec_id from lecdetails,subjects where subjects.sub_code=lecdetails.sub_code 
and subjects.sub_name='"+subj+"'"); 
ResultSet rst1= Handler.getData(con, "select sub_name from subjects,lecdetails 
where subjects.sub_code=lecdetails.sub_code and subjects.sem='2nd' and 
lecdetails.lec_id <> '"+lec1.getString(1) +"' order by rand() limit 1 "); 
jTable2.setValueAt(lec1.getString(1), 0, 1); 

回答

4

在使用lec.getString(1)之前,您必須致電next()

所以,聲明 ResultSet rst1= Handler.getData,前

添加

if (lec1.next()){ 
    //second result set statement. 
    //set value in jtable 
} 
+0

謝謝!!!!! – ramindusn 2013-03-21 19:52:16