Skip to main content

Posts

Showing posts with the label Stored Procedures

How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?

-- A stored procedure can process related data and return multiple result sets, this way may save fewer calls to database server. You need to include code to retrieve the result sets, Java JDBC Statement provide the getResultSet method to retrieve each result set. You can access the first result set by calling the getResultSet method on your Statement object. In a loop, position the cursor using the next method, and retrieve data from each column of the current row of the ResultSet object using getXXX methods. To determine if more result sets are available, you can call the getMoreResults method in Statement , which returns a boolean value of true if more result sets are available. If more result sets are available, you can call the getResultSet method again to access them, continuing the process until all result sets have been processed. If the getMoreResults method returns false , there are no more result sets to...

How to Use JDBC Java to Dynamically Create a Stored Procedure?

-- This example demonstrates how to create a stored procedure in JDBC in MySQL database. Assume that we have a table created by the following schema script: CREATE TABLE `mydb`.`employees` ( `EmployeeID` int(10) unsigned NOT NULL default '0', `Name` varchar(45) collate utf8_unicode_ci NOT NULL default '', `Office` varchar(10) collate utf8_unicode_ci NOT NULL default '', `CreateTime` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`EmployeeID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; We are going to dynamically add one stored procedure to mydb database import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class JDBCCreateTable { private static final String DBURL = "jdbc:mysql://localhost:3306/mydb?user=usr&password=sql&" + "useUnicode=true&characterEncoding=UTF-8"; ...

PL/SQL - Stored Procedures FAQs

What is PL/SQL and what is it used for? PL/SQL is Oracle's Procedural Language extension to SQL. PL/SQL's language syntax, structure and data types are similar to that of ADA . The PL/SQL language includes object oriented programming techniques such as encapsulation, function overloading, information hiding (all but inheritance). PL/SQL is commonly used to write data-centric programs to manipulate data in an Oracle database. Should one use PL/SQL or Java to code procedures and triggers? Internally the Oracle database supports two procedural languages, namely PL/SQL and Java. This leads to questions like "Which of the two is the best?" and "Will Oracle ever desupport PL/SQL in favor of Java?” Many Oracle applications are based on PL/SQL and it would be difficult of Oracle to ever desupport PL/SQL. In fact, all indications are that PL/SQL still has a bright future ahead of it. Many enhancements are still being made to PL/SQL. For example, Oracle 9iDB supports nativ...