在java中调用mysql存储过程

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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();
            }
            
        }

    }