You are on page 1of 2

=> SimpleJdbcInsert :-

-> SimpleJdbcInsert is the class which is present in


"org.springframework.jdbc.core.simple" package
-> The object provided by SimpleJdbcInsert is multithreaded and reusable
object which provides an easy way to insert values in database

===================================================================================
===============

=> Stored Procedure :-


-> It is prepared SQL query that is saved at database side so that we can use
it again and again
-> We need to to compile the query again and again, we can call it directly

-> We can provide 3 parameters in stored procedure :-


1. IN
2. OUT
3. INOUT

-> Syntax :-
= CREATE PROCEDURE procedureName(parameters)
BEGIN
-----sql query-----
END //

1. select query stored procedure :-


CREATE PROCEDURE getAllStudents()
BEGIN
select * from marks;
END //

2. select query stored procedure :-


CREATE PROCEDURE getStudentDetails(IN std_email VARCHAR(100))
BEGIN
select * from marks where email=std_email;
END //

3. select query stored procedure :-


CREATE PROCEDURE getStudentName(IN std_email VARCHAR(100), OUT
std_name VARCHAR(100))
BEGIN
select name from marks where email=std_email;
END //

4. show all procedures :-


SHOW PROCEDURE STATUS WHERE db='database_name';

5. delete procedure :-
DROP PROCEDURE procedureName;

6. call procedure at mysql :-


CALL procedureName();

7. insert query stored procedure :-


CREATE PROCEDURE insertStdDetails(IN name1 VARCHAR(100), IN
email1 VARCHAR(100), IN marks1 INT)
BEGIN
insert into marks values(name1, email1, marks1);
END //
-----------------------------------------

=> Stored Functions :-


-> Syntax :-
CREATE FUNCTION functionName(parameters)
RETURNS return_type
BEGIN
---------statements-------------
END //

-> NOTE : If it provides any error then execute following command :-


SET GLOBAL log_bin_trust_function_creators = 1;

-> How to execute functions :-


SELECT functionName();

-> For example :-


1. display name :-
CREATE FUNCTION display()
RETURNS VARCHAR(100)
BEGIN
RETURN 'hello deepak...!!';
END
//

2. addition :-
CREATE FUNCTION addition(no1 INT, no2 INT)
RETURNS INT
BEGIN
RETURN no1+no2;
END
//

-> Difference between Stored Procedure and Stored Functions :-

1. STORED PROCEDURE does not have any return type


STORED FUNCTIONS have return type

2. STORED PROCEDURE has IN, OUT and INOUT type parameters


STORED FUNCTIONS does not have IN, OUT and INOUT type parameters

3. STORED PROCEDURE can be used with insert, select, update, delete etc
queries
STORED FUNCTIONS can be used only for select query

------------------------------

You might also like