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