jdbc连接mssqlserver2000
在sqlserver中定义:
CREATE PROCEDURE test
@RowCount int OUTPUT
AS
select EmployeeID, LastName, FirstName from employees where EmployeeID < 4
select @RowCount = count(*) from employees where EmployeeID < 4
GO
在java中:
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbUrl = "jdbc:microsoft:sqlserver://192.168.5.190:1433;databasename=Northwind";
String userName = "sa";
String password = "sa";
Connection dbConn;
CallableStatement cStatement;
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbUrl, userName, password);
cStatement = dbConn.prepareCall("{CALL test(?)}");
cStatement.registerOutParameter(1, java.sql.Types.INTEGER);
ResultSet rs = cStatement.executeQuery();
int rowCount = rs.getInt(1);
}
catch.....
程序执行到 int rowCount = rs.GetInt(1);时报错:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
不知为什么,请指教
在sqlserver中定义:
CREATE PROCEDURE test
@RowCount int OUTPUT
AS
select EmployeeID, LastName, FirstName from employees where EmployeeID < 4
select @RowCount = count(*) from employees where EmployeeID < 4
GO
在java中:
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbUrl = "jdbc:microsoft:sqlserver://192.168.5.190:1433;databasename=Northwind";
String userName = "sa";
String password = "sa";
Connection dbConn;
CallableStatement cStatement;
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbUrl, userName, password);
cStatement = dbConn.prepareCall("{CALL test(?)}");
cStatement.registerOutParameter(1, java.sql.Types.INTEGER);
ResultSet rs = cStatement.executeQuery();
int rowCount = rs.getInt(1);
}
catch.....
程序执行到 int rowCount = rs.GetInt(1);时报错:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
不知为什么,请指教
dbConn = DriverManager.getConnection(dbUrl, userName, password);
cStatement = dbConn.prepareCall("{CALL test(?)}");
cStatement.registerOutParameter(1, java.sql.Types.INTEGER);
//ResultSet rs = cStatement.executeQuery();
int rowCount = cStatement.getInt(1);
dbConn = DriverManager.getConnection(dbUrl, userName, password);
cStatement = dbConn.prepareCall("{CALL test(?)}");
cStatement.registerOutParameter(1, java.sql.Types.INTEGER);
//ResultSet rs = cStatement.executeQuery();
cStatement.execute();//刚刚漏掉执行了
int rowCount = cStatement.getInt(1);