JAVA执行存储过程
以SQLServer为例
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
public class TestCall {
public static void main(String[] args) {
try{
Connection conn=null;
CallableStatement cs=null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://127.0.0.1:1433;databaseName=studentdb";
conn=DriverManager.getConnection(url,"sa","sqlserver");
String sql="{call s_insert(?,?)}";
cs=conn.prepareCall(sql);
cs.setString(1,"张三");
cs.setInt(2, 12);
int num=-1;
num=cs.executeUpdate();
System.out.println("num:"+num);
}catch (Exception e) {
e.printStackTrace();
}
}
}
作者:hyljava
补充:软件开发 , Java ,