"Stored Procedure 1"
Write a stored procedure procedure implement two numbers to add
DELIMITER &&create PROCEDURE pr_add (xx int,yy int) begindeclare ZZ int; SET Zz=xx+yy; SELECT ZZ as SUM; End&&delimiter;
MySQL calls the stored procedure call Pr_add (3,5);
Java calls stored procedures
Using CallableStatement
Package Com.zhiqi.fir;import java.sql.*;p ublic class Fir {private static String jdbcname= "Com.mysql.jdbc.Driver"; private static string Dburl= "Jdbc:mysql://localhost:3306/fruit";p rivate static string dbuser= "root";p rivate static String dbpassword= "123456";p ublic static void Main (string[] args) throws Exception {Class.forName (jdbcname); Connection conn=drivermanager.getconnection (Dburl,dbuser,dbpassword); CallableStatement Cast=conn.preparecall ("Call Pr_add (?,?)"); Cast.setint (1, 5); Cast.setint (2, 1); ResultSet Rs=cast.executequery (); while (Rs.next ()) {System.out.println (Rs.getint (1));} Conn.close ();}}
"Stored Procedure 2"
Operation of the MySQL stored procedure