请问这小段代码有什么问题?distinct & SQLException

Jay02 2002-06-01 08:01:21
try {
rs = st.executeQuery("select distinct 分类 from 表");
while(rs.next()) {
String type = rs.getString(1);
if (type == null) type = "(未分类)";
classes.addLast(type);
}
}
catch (SQLException e) {
System.out.println(e);
}

运行时:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

程序不退出。

去掉 SQL 语句中的 distinct 则没有问题,为何?

ps, 数据库用的是Access,使用JDBC-ODBC,但不建数据源

高手请指教。多谢!
...全文
105 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pentax 2002-06-03
  • 打赏
  • 举报
回复
我用Sybase怎么没问题,是不是Access不支持。
Jay02 2002-06-03
  • 打赏
  • 举报
回复
我放弃了:(
换了一种方式,在Access里建立查询,那是支持distinct的
Jay02 2002-06-03
  • 打赏
  • 举报
回复
我也这么想,可能Access不支持
不过我的代码好像成功过一次,哎,现在找不到那种状态了:(
哪位大牛能帮我呀?
Jay02 2002-06-02
  • 打赏
  • 举报
回复
补充:
rs设置:
st = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE
);
yuanqingfei 2002-06-02
  • 打赏
  • 举报
回复
我的也是出现这种问题:
不过是中文的:非法的游标状态
nullhue 2002-06-02
  • 打赏
  • 举报
回复
rs 如何设置的?
Jay02 2002-06-01
  • 打赏
  • 举报
回复
对了,我的ODBC这么连的:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(
"jdbc:odbc:;" +
"DRIVER=Microsoft Access Driver (*.mdb);" +
"DBQ=mmms.mdb"
);

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧