创建:
CREATE PROCEDURE `abc`(IN tname char(20),in tpass char(20))
BEGIN
INSERT INTO t_user (name,pass) values(tname,tpass);
END;
调用:
call pro_name(value1,value2);
java中调用:
package test;
import java.sql.*;
import java.sql.ResultSet;
public class Test {
public static void main(String[] args) {
String driver = "com.mysql.jdbc.Driver";
String strUrl = "jdbc:mysql://127.0.0.1:3306/java_test";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
CallableStatement cstmt = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "root", "pass");
CallableStatement proc = null;
proc = conn.prepareCall("{ call java_test.ddd(?,?) }");
proc.setString(1, "5555");
proc.setString(2, "8555");
proc.execute();
} catch (SQLException ex2) {
ex2.printStackTrace();
} catch (Exception ex2) {
ex2.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
} catch (SQLException ex1) {
}
}
}
}