日期:2014-05-16 浏览次数:20401 次
mysql存储过程 “delimiter //”的意思是定义结束符号为“//”,以此来替换mysql中的“;” Connection conn = null; Statement s =null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql" ,"root","123"); String call="{call proid(?)}"; //调用语句 CallableStatement proc=conn.prepareCall(call); //调用存储过程 // proc.setString(1,"12345678"); //给输入参数传值 proc.registerOutParameter(1,Types.VARCHAR ); //声明输出参数是什么类型的 proc.execute(); //执行 String address=proc.getString(1); //获得输出参数 p(address); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); }finally{ try { rs.close(); s.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void p(String s){ System.out.print(s); } public static void p(int s){ System.out.print(s); }