Jdbc Core Technology 3-stored procedure and jdbc Core Technology
What is a stored procedure? A stored PROCEDURE is a piece of code stored IN a database. It can be called by a program to create a stored PROCEDURE create PROCEDURE SELECT_TESTTWO (in testid long, inout testall varchar (255 ))
BEGIN
SELECT 'name' from test where id = testid into testall;
END
Create a stored PROCEDURE command: create PROCEDURE PROCEDURE_Name (input, output parameters, can have multiple)
Struct BEGIN SQL END;
Call a stored procedure @ TestPublic Void Test_PROCEDURE()ThrowsException {Class.ForName("Com. mysql. jdbc. Driver"); Connection connection = DriverManager.GetConnection(Url, user, password); CallableStatement callableStatement = connection. prepareCall ("call SELECT_TESTTWO (?,?) "); // Call the Stored Procedure callableStatement. setLong (1, 1); callableStatement. registerOutParameter (2, Types.VARCHAR); CallableStatement. execute (); // execute the Stored Procedure // Assert. assertNotNull (callableStatement); System.Out. Println (callableStatement. getString (2 ));}
Show all stored procedures
Show procedure status; delete a stored PROCEDURE drop procedure demo;
Drop procedure SELECT_test;
Drop procedure SELECT_testone;
The storage process improves the efficiency. We can directly reduce the communication with the database and reduce the network burden.