Operation of the MySQL stored procedure

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.