public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");//加载驱动 String jdbc="jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=GBK"; Connection conn=DriverManager.getConnection(jdbc, "root", "");//链接到数据库 Statement state=conn.createStatement(); //容器 String sql="insert into xs values('1','桥本有菜','成人教师')"; //SQL语句 state.executeUpdate(sql); //将sql语句上传至数据库执行 conn.close();//关闭通道 }
通过JDBC组件中的CallableStatement接口实现调用存储过程。

核心代码如下:
 
Class.forName("com.mysql.jdbc.Driver");

Connection conn = DriverManager.getConnection("jdbc:mysql:///test","root","root");

 

CallableStatement cstmt = cn.prepareCall("{call

insert_Student(?,?,?)}");

cstmt.registerOutParameter(3,Types.INTEGER);

cstmt.setString(1, "wangwu");

cstmt.setInt(2, 25);

cstmt.execute();
 

 

 posted on 2019-08-30 14:09  来呀~快活啊  阅读(681)  评论(0编辑  收藏  举报