drop procedure testProc
go
create procedure testProc(@in varchar(10),@out int OUTPUT) as
select @out=count(*) from rh.T_BASE_AREA
go
testProc 1,1
package com.etong.util;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
public class T3 {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
// DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
String dbUrl = "jdbc:jtds:sqlserver://localhost:1433;Databasename=rhsys";
Connection conn = java.sql.DriverManager.getConnection(dbUrl,"sa","sa");
String sql="{call testProc(?,?)}";
CallableStatement cs=conn.prepareCall(sql);
cs.setString(1,"1039");
cs.registerOutParameter(2,Types.INTEGER);
cs.execute();
System.out.println(cs.getObject(2));
// ResultSet rs = (ResultSet)cs.getObject(2);
// while (rs.next()){
// System.out.println(rs.getObject(1));
// }
cs.close();
conn.close();
}
}
分享到:
评论