請看看我的程式碼

jacquiyan發表於2002-09-08
public Iterator getAllRow(String ip){
Connection con = null;

Statement st = null;
String sql = null;

try {
con = MysqlConn.getConnection(ip);
sql = "select stateid,name from State";
st = con.createStatement();

System.out.println("sql="+sql);
final ResultSet rs = st.executeQuery(sql);

return new Iterator() {
private State state;//自定義類
public boolean hasNext() {
if (state == null) {
if (! rs.next()) {//出錯地方1,line54
return false;
}
state.StateId = rs.getShort("stateid");//出錯地方2,line57
state.StateName = rs.getString("name");//出錯地方3,line58
}
return true;
}

public Object next() {
if (! hasNext()) {
throw new NoSuchElementException();
}
State retval = state;
state = null;
return retval;
}

public void remove() {
throw new UnsupportedOperationException("no remove allowed");
}
};
}catch(Exception e){
e.printStackTrace();
}
finally {
try { st.close(); } catch(SQLException ne) { ne.printStackTrace(); }
try { con.close(); } catch(SQLException ne) { ne.printStackTrace(); }
}
}

編譯不透過,錯誤提示
1、unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 54, column 24
2、unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 57, column 34
3、unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 58, column 36

相關文章