| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
ymc4
10年前发布

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