package com.unit.wjh;
import java.sql.ResultSetMetaData;
import java.sql.CallableStatement;
import java.util.HashMap;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
public class test {
public test() {
}
public static void main(String[] args ){
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String strUrl="jdbc:sqlserver://localhost:1433;DatabaseName=Leading";
//String userName="sa1";
//String userPwd="123456";
Statement sm = null;
int rs = 0;
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "sa1", "123456");
CallableStatement proc = null;
proc = conn.prepareCall("{ call proc_update_unit(?,?,?,?) }");
proc.setInt(1,12345);
proc.setString(2, "米");
proc.setString(3, "箱");
proc.setInt(4,-1);
//proc.registerOutParameter(1, Types.VARCHAR);
// proc.registerOutParameter(5, Types.VARCHAR);
/* proc.execute();
String testPrint = proc.getString(1)+proc.getString(2);
System.out.println("存储过程返回的值是:"+testPrint); */
rs= proc.executeUpdate();
//System.out.println();
System.out.println(rs);
//处理执行结果
// if (rs!=null && rs.next()) {
// ResultSetMetaData rsmd = rs.getMetaData();
// HashMap<String, String> map = new HashMap<String,String>();
// for (int i = 1; i <= rsmd.getColumnCount(); i++) {
// map.put(rsmd.getColumnName(i),rs.getString(i));
// }
// System.out.println(map.toString());
// //return true;
// }
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
catch (Exception ex2) {
ex2.printStackTrace();
}
}
}
Java调用存储过程
最新推荐文章于 2021-02-13 11:17:33 发布