Y
youweibin
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
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));
请问是什么原因?
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));
请问是什么原因?