Call store procedure in java

Wednesday, January 20th, 2016 (0 Comment)

In the previous section, we know the interface to support the mining process and store information on database through the Statement, PreparedStatement objects. The using of SQL statements to communicate between the client and the database server will make the communication traffic on the network is very large. This increases network traffic makes the performance of the program is reduced, costly resources in database server because it always allocated to the creation and release memory when executing SQL statements, whether as command it is executed multiple times.

In this situation, use the store procedure is the best solution, the using of store procedure to support the processing of information in the database is quite effective by one of the following advantages:

  • You can call execute many tasks impact on the database through one name only.
  • Reduce traffic transmitted because use one short string (the name of the store procedure).
  • Store procedure is created and placed in the database server and only through the name to access to Database, it helps security program information.
  • Store procedure was compiled before and exists in DBMS, so performance and response information to the client very quickly, increasing efficiency of program implementation. Store procedure reused many times.
  • Take advantage of the implementation and the location of the program requirements in two places simultaneously: client – server. Thus increased performance program execution

Store procedure has many advantages, so to call a store procedure in the database we will use CallableStatement interface to call the store procedure.

1. Create table in database

You should review the previous section to retrieve scripts create ROOM table.

2. Create store procedure

Run scripts following to create a store procedure in database types:

a) SQL Server

b) Mysql

c) Oracle

  • with Oracle: you need use cursor to get result.

3. Call store procedure in java

Get information of ROOM table from java code, we have 3 functions for 3 database (SQL Server, Mysql, Oracle)

a) SQL Server

b) Mysql

c) Oracle

 

Tags: , ,

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

Leave a Reply

Your email address will not be published. Required fields are marked *