Section 12.4. Stored Procedures

   

12.4 Stored Procedures

You are likely aware that one way to increase performance in your database- intensive applications is to offload as much work as you can to the database. Databases can perform many calculations, create aggregate values, sort , and perform very advanced kinds of queries. Even if you are only writing simple queries, it is probably not a bad idea to have your database doing more for you, and a good way to do that is to write stored procedures.

But perhaps the chief reason that stored procedures are popular among developers is that they allow you to group a number of SQL statements together, more accurately and efficiently representing a real business process (that is, procedure). Stored procedures run fast because they are kept on the database server, compiled into a native state.

There are two ways to work with stored procedures in Java. The first is easy: you simply call and execute your procedure using executeUpdate() . The alternative is to write the procedure following SQLJ conventions. The purpose of SQLJ is to define an industry standard for embedding SQL statements into Java methods and enhance the work possible using stored procedures. The advantage to using SQLJ is that your code is more portable, because you actually write a standalone Java application to hold your stored procedure. You write normal connection, statement, and execution code in this class, and then compile it into a .jar (Java Archive) file. You then place the .jar on the database server. Because a special syntax is required for these things, you should visit www.sqlj.org to find out more.


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net