返回顶部

收藏

在java中调用mysql存储过程

更多
public class GenerateSampleData {
    public void select() {

        String sql="";
        Connection con = null;
        CallableStatement callAble=null;

        try{
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/test";
        con = DriverManager.getConnection(url, "abc", "abc");
        sql="{call test2(?)}";
                callAble=con.prepareCall(sql);
                callAble.registerOutParameter(1, Types.VARCHAR);
                callAble.execute();
                System.out.println(callAble.getString(1));
        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally{
            try {
                callAble.close();
                con.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }

标签:java

收藏

0人收藏

支持

0

反对

0

发表评论