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 = "jdbcdbc: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
有谁能够帮助我,谢谢了!