Java 连接sqlserver2000 获得字段数据时应该注意顺序

public Vector<ForumBean> listForum() {
// TODO 获得所有版块
Vector<ForumBean> lst=new Vector<ForumBean>();
DataConn cn=DataConn.getInstance();
String SQL="SELECT forum_id, title, forum_info, the_user FROM forum_forums";
try {
PreparedStatement statement = cn.getConnection().prepareStatement(SQL);
ResultSet set = statement.executeQuery();
while (set.next()) {
ForumBean forum=ForumBean.getInstance();
forum.setForum_id(set.getInt("forum_id"));
forum.setTitle(set.getString("title"));
forum.setForum_info(set.getString("forum_info"));
String user_id=set.getString("the_user");
UserBean user=UserBean.getInstance();
user.initInfo(user_id);
if(user.getType()==UserManagerImpl.MODERATOR_PRO){
forum.setThe_user(user_id);
}
else{
forum.setThe_user(set.getString("暂无"));
}
lst.add(forum);

}
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return lst;
}


在此读取数据时一定要按照select---from之间的顺序读取数据否则回抛出sql字段不能重新读取的异常

你可能感兴趣的:(java,sql)