JDBC Tutorials - Herong's Tutorial Examples - v3.12, by Dr. Herong Yang
Creating Procedures with Multiple Queries
This section describes how to create a procedure with multiple queries.
To do more tests on CallableStatement objects, I created another stored procedure with multiple queries:
herong> local\mysql\bin\mysql -u Herong -pTopSecret mysql> USE HerongDB; Database changed mysql> -- Changing the command delimiter to '$' mysql> DELIMITER '$'; mysql> -- Creating the procedure mysql> CREATE PROCEDURE HeadTail(OUT Size INTEGER) -> BEGIN -> SELECT ID, FirstName, LastName, BirthDate, ModTime -> FROM Profile ORDER BY ID LIMIT 0, 10; -> SELECT ID, FirstName, LastName, BirthDate, ModTime -> FROM Profile ORDER BY ID DESC LIMIT 0, 10; -> SELECT COUNT(*) INTO Size FROM Profile; -> END$ Query OK, 0 rows affected (0.00 sec) mysql> -- Testing the procedure mysql> CALL HeadTail(@Size)$ +-------+-----------+----------+------------+---------------------+ | ID | FirstName | LastName | BirthDate | ModTime | +-------+-----------+----------+------------+---------------------+ | 60006 | 547 | 22741 | 2000-12-31 | 2027-01-01 00:00:00 | | 60007 | a2f | 8954f | NULL | NULL | | 60008 | 2632 | 74f88 | NULL | NULL | | 60009 | 1680 | a1708 | NULL | NULL | | 60010 | 1234 | 984fc | NULL | NULL | | 60011 | 20d4 | 789e8 | NULL | NULL | | 60012 | 2037 | 79ba0 | NULL | NULL | | 60013 | f71 | d6b24 | NULL | NULL | | 60014 | 34f | add23 | NULL | NULL | | 60015 | 2310 | 889ca | NULL | NULL | +-------+-----------+----------+------------+---------------------+ 10 rows in set (0.00 sec) +-------+-----------+----------+-----------+---------+ | ID | FirstName | LastName | BirthDate | ModTime | +-------+-----------+----------+-----------+---------+ | 70005 | 1814 | d7f60 | NULL | NULL | | 70004 | cb0 | cd79d | NULL | NULL | | 70003 | 12e2 | 1607c | NULL | NULL | | 70002 | e7d | d6e27 | NULL | NULL | | 70001 | f86 | 5aafe | NULL | NULL | | 70000 | 25f6 | 1de8d | NULL | NULL | | 69999 | c49 | c18db | NULL | NULL | | 69998 | 744 | 799ed | NULL | NULL | | 69997 | 3e4 | 82d5e | NULL | NULL | | 69996 | dc7 | 12196 | NULL | NULL | +-------+-----------+----------+-----------+---------+ 10 rows in set (0.03 sec) Query OK, 0 rows affected (0.06 sec) mysql> -- Check the output parameter mysql> SELECT @Size$ +-------+ | @Size | +-------+ | 10001 | +-------+ 1 row in set (0.00 sec)
Table of Contents
JDBC (Java Database Connectivity) Introduction
Installing and Running Java DB - Derby
Derby (Java DB) JDBC DataSource Objects
Java DB (Derby) - DML Statements
Java DB (Derby) - ResultSet Objects of Queries
Java DB (Derby) - PreparedStatement
MySQL JDBC Driver (MySQL Connector/J)
MySQL - Reference Implementation of JdbcRowSet
►MySQL - JBDC CallableStatement
Overview of CallableStatement Objects
"CREATE PROCEDURE" - Creating a Simple Procedure
Creating Procedures with IN and OUT Parameters
Creating Procedures with INOUT Parameters
►Creating Procedures with Multiple Queries
Creating CallableStatement Objects with prepareCall()
Capturing ResultSet with executeQuery()
Creating CallableStatement Objects with Parameters
Common Errors with CallableStatement Parameters
Creating CallableStatement Objects with INOUT Parameters
Retrieving Multiple ResultSet Objects
Executing Stored Procedures without Permission
getProcedures() - Listing Stored Procedures
MySQL CLOB (Character Large Object) - TEXT
MySQL BLOB (Binary Large Object) - BLOB
Oracle Express Edition Installation on Windows
Oracle - Reference Implementation of JdbcRowSet
Oracle - JBDC CallableStatement
Oracle CLOB (Character Large Object) - TEXT
Oracle BLOB (Binary Large Object) - BLOB
Microsoft SQL Server Express Edition
Microsoft JDBC Driver for SQL Server
Microsoft JDBC Driver - Query Statements and Result Sets
Microsoft JDBC Driver - DatabaseMetaData Object
Microsoft JDBC Driver - DDL Statements
Microsoft JDBC Driver - DML Statements
SQL Server - PreparedStatement
SQL Server CLOB (Character Large Object) - TEXT
SQL Server BLOB (Binary Large Object) - BLOB
JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver
JDBC-ODBC Bridge Driver - Flat Text Files
JDBC-ODBC Bridge Driver - MS Access
JDBC-ODBC Bridge Driver - MS SQL Server
Summary of JDBC Drivers and Database Servers