java调用存储过程

来源:互联网 发布:学一个月python 找工作 编辑:程序博客网 时间:2024/05/22 17:22

最近一直学习存储过程,今天把java调用存储过程的方法学习了一下。准确说是复习了一下,以前用过,时间长了忘了

String driver="com.mysql.jdbc.Driver";String strUrl="jdbc:mysql://localhost:3306/DBname";String strUser="root";String strPwd="root";Connection conn=null;//PreparedStatement pst=null;CallableStatement cst=null;//java.sql.CallableStatmentResultSet rs=null;try{    Class.forName(driver);    conn=DriverManager.getConnection(strUrl,strUser,strPwd);    cst=conn.prepareCall("call proc_name(?,?)");//调用存储过程    cst.setInt(1,1);//给参数,从1开始    cst.exectute();    String name=cst.getString(2);//取参数}catch(SQLException e){e.printStackTrace();}finally{ if(rs != null){            rs.close();            if(stmt!=null){              stmt.close();            }            if(conn!=null){              conn.close();            }          }  }

记得导jdbc驱动的包

0 0
原创粉丝点击