This part shows you how to make and drop systems in Derby.
Creating a procedure
You can make a system utilizing the CREATE PROCEDURE proclamation.
Syntax
Following is the punctuation of the CREATE PROCEDURE articulation.
CREATE PROCEDURE procedure_name (parameter_type parameter_name1, parameter_type
parameter_name2 . . . .) parameter_style;
Example
Assume, we have made a table in Derby as demonstrated underneath.
CREATE TABLE Emp ( Id INT NOT NULL GENERATED ALWAYS AS IDENTITY,
Name VARCHAR(255),
Salary INT NOT NULL,
Location VARCHAR(255),
Phone_Number BIGINT
);
Also, embedded qualities in it as follows −
INSERT INTO Employees(Name, Salary, Location) VALUES
('Amit', 30000, 'Hyderabad'),
('Kalyan', 40000, 'Vishakhapatnam'),
('Renuka', 50000, 'Delhi'),
('Archana', 15000, 'Mumbai'),
('Trupthi', 45000, 'Kochin')";
Following model makes a methodology named Update_Procedure which acknowledges JAVA boundaries.
ij> CREATE PROCEDURE Update_Procedure(IN id INTEGER, IN name VARCHAR(10))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
'ProcedureExample.testProc';
> 0 rows inserted/updated/deleted
Where ProcedureExample class looks like −
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class ProcedureExample {
public static void testProc(int salary, String name) throws Exception {
String connectionURL = "jdbc:derby:MYDATABASE;create=true";
Connection conn = DriverManager.getConnection(connectionURL);
String query = "UPDATE Employees SET SALARY = ? WHERE NAME = ?";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setInt(1, salary);
pstmt.setString (2, name);
pstmt.executeUpdate();
}
}
You can check the rundown of strategies utilizing SHOW PROCEDURES question.
ij> SHOW PROCEDURES;
PROCEDURE_SCHEM |PROCEDURE_NAME |REMARKS
------------------------------------------------------------------------
APP |UPDATE_PROCEDURE |ProcedureExample.te&
SALES |EXAMPLE_ PROCEDURE |com.example.sales.c&
SQLJ |INSTALL_JAR |org.apache.derby.ca&
SQLJ |REMOVE_JAR |org.apache.derby.ca&
SQLJ |REPLACE_JAR |org.apache.derby.ca&
SYSCS_UTIL |SYSCS_BACKUP_DATABASE |org.apache.derby.ca&
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Here you can notice the recently made system.
Dropping a procedure
You can drop a system utilizing the DROP PROCEDURE proclamation.
Syntax
Following is the language structure of the DROP PROCEDURE proclamation.
DROP PROCEDURE procedure_name;
Example
Following model drops a system named Update_Procedure made previously.
ij> DROP PROCEDURE Update_Procedure;
> 0 rows inserted/updated/deleted