A stored procedure is a group of SQL statements that form a logical unit and perform a particular task, and they are used to encapsulate a set of operations or queries to execute on a database server.

String createProcedure = "create procedure SHOW_SUPPLIERS " +
			 "as " +
			 "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " +
			 "from SUPPLIERS, COFFEES " +
			 "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " +
			 "order by SUP_NAME";

The following code fragment uses the Connection object con to create a Statement object, which is used to send the SQL statement creating the stored procedure to the database:

Statement stmt = con.createStatement();
stmt.executeUpdate(createProcedure);

JDBC allows you to call a database stored procedure from an application written in the Java programming language.

CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();