有谁知道在数据库中出现Invalide cursor state是何原因,谢谢(200分)

  • 主题发起人 主题发起人 gbchen0
  • 开始时间 开始时间
G

gbchen0

Unregistered / Unconfirmed
GUEST, unregistred user!

import java.sql.*;

public class ServerName{

public static void main(String[] args){
//url指向Microsoft SQL Server 7.0系统表(master)
String url = "jdbc:odbc:mysqlServer";
String sn = "Unkonwn Server Name";
Connection conn;
//取出服务器信息,sysservers为一系统表
String qryString = "select * from sysservers";
Statement stmt;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(ClassNotFoundException excp0){

System.err.print("ClassNotFoundException: ");
System.err.println(excp0.getMessage());

}

try{

conn = DriverManager.getConnection(url, "sa", "");
SQLWarning sqlw = conn.getWarnings();

while(sqlw!=null){

System.out.println("SQLWarningMessage:"+sqlw.getMessage());
System.out.println("SQLWarningErrorCode:"+sqlw.getErrorCode());
System.out.println("SQLWarningSQLState:"+sqlw.getSQLState());
sqlw = sqlw.getNextWarning();

}

stmt = conn.createStatement();
sqlw = stmt.getWarnings();

while(sqlw!=null){

System.out.println("SQLWarningMessage:"+sqlw.getMessage());
System.out.println("SQLWarningErrorCode:"+sqlw.getErrorCode());
System.out.println("SQLWarningSQLState:"+sqlw.getSQLState());
sqlw = sqlw.getNextWarning();

}

ResultSet rSet = stmt.executeQuery(qryString);
sqlw = rSet.getWarnings();

while(sqlw!=null){

System.out.println("SQLWarningMessage:"+sqlw.getMessage());
System.out.println("SQLWarningErrorCode:"+sqlw.getErrorCode());
System.out.println("SQLWarningSQLState:"+sqlw.getSQLState());
sqlw = sqlw.getNextWarning();

}


sn = rSet.getString("srvname");
conn.close();
stmt.close();
System.out.println(sn);

}catch(SQLException excp1){

System.err.println("ErrorCode1:"+excp1.getErrorCode());
System.err.println("ErrorMessage1:"+excp1.getMessage());
System.err.println("ErrorState1:"+excp1.getSQLState());

}

}

}

运行上述程序出现以下错误:

SQLWarningMessage:[Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'master'.
SQLWarningErrorCode:5701
SQLWarningSQLState:01000
SQLWarningMessage:[Microsoft][ODBC SQL Server Driver][SQL Server]Changed language setting to us_english.
SQLWarningErrorCode:5703
SQLWarningSQLState:01000
ErrorCode1:0
ErrorMessage1:[Microsoft][ODBC Driver Manager] Invalid cursor state
ErrorState1:24000
Unkonwn Server Name

我用的数据库是Microsoft SQL Server 7.0
数据库的属性为
Type: MSSQL
Datatbase Name:
SQLQRYMODE: Server
USER Name: sa

有谁能够帮助我,谢谢了!

 
java干的?偶不懂jave的东东。
 
java的数据库指针一开始是指向第一条记录之前的。
所以在读取数据库记录之前,最好先用个next()的方法.
 
1,通过jdbcOdbc桥访问MS SQL7应该先建立一ODBC DSN.
2,rx.next()先。

 
必须先NEXT。
 
多人接受答案了。
 
同意next()先
 
后退
顶部