关于网友提出的“ sql server 2000 jdbc driver访问sql server2000出错”问题疑问,本网通过在网上对“ sql server 2000 jdbc driver访问sql server2000出错”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: sql server 2000 jdbc driver访问sql server2000出错
描述: 代码如下:
import java.sql.*;
public class PrintEmployees
{
public static void main(String[] args)
{
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String connURL = "jdbc:microsoft:sqlserver://taxi:1433;User=sa;Password=;DatabaseName=Northwind";
try
{
Class.forName(driverName);
Connection conn = DriverManager.getConnection(connURL);
PreparedStatement stmt = conn.prepareStatement("SELECT FirstName, LastName, BirthDate FROM Employees");
ResultSet rs = stmt.executeQuery();
while (rs.next());
{
System.out.println("FirstName:" + rs.getString(1));
System.out.println(" LastName:" + rs.getString(2));
System.out.println("BirthDate:" + rs.getDate(3));
System.out.println("");
}
rs.close();
stmt.close();
conn.close();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
错误信息如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at PrintEmployees.main(PrintEmployees.java:19)
第19行的代码为:System.out.println("FirstName:" + rs.getString(1));
请问是什么原因?
解决方案1: System.out.println("FirstName:" + rs.getString(1));
中的1是什么呢?是数据库表中的字段还是?
应该是System.out.println("FirstName:" + rs.getString("FirstName"));吧,试试!
解决方案2: 检查你的数据类型, SQL 能否在ms sql client 命令行运行通过?
以上介绍了“ sql server 2000 jdbc driver访问sql server2000出错”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3625169.html