java_stored_procedure_vs.PL/SQL_procedures

M

marko

What is the difference between these two ?

Isn't java stored procedure just a connection via JBDC, and a SQL call to
database, for example :

PreparedStatement stmt = connection.prepareStatement
("SELECT STANDARD_RATE " +
" FROM AVAILABLE_ROOM_TYPES WHERE HOT_ID = TO_NUMBER(?) " +
" AND ROOM_TYPE = ? ");

stmt.setString(1,hotelId); stmt.setString(2,roomType);

ResultSet rset = stmt.executeQuery();and what is faster ?
 
J

John B. Matthews

"marko" <[email protected]> said:
What is the difference between these two ?

I assume you mean the difference between a stored procedure and a
PreparedStatement, each performing the same query.
Isn't java stored procedure just a connection via JBDC, and a SQL
call to database, for example :

PreparedStatement stmt = connection.prepareStatement
("SELECT STANDARD_RATE " +
" FROM AVAILABLE_ROOM_TYPES WHERE HOT_ID = TO_NUMBER(?) " +
" AND ROOM_TYPE = ? ");

stmt.setString(1,hotelId); stmt.setString(2,roomType);

ResultSet rset = stmt.executeQuery(); and what is faster ?

Surely the relative performance depends on how the target database
parses, caches and plans to execute the query. What are your results?

[Please don't post tabs.]
 
A

Arne Vajhøj

marko said:
What is the difference between these two ?

Isn't java stored procedure just a connection via JBDC, and a SQL call to
database, for example :

PreparedStatement stmt = connection.prepareStatement
("SELECT STANDARD_RATE " +
" FROM AVAILABLE_ROOM_TYPES WHERE HOT_ID = TO_NUMBER(?) " +
" AND ROOM_TYPE = ? ");

stmt.setString(1,hotelId); stmt.setString(2,roomType);

ResultSet rset = stmt.executeQuery();and what is faster ?

Java can actually be used in at least two ways with Oracle.

The code using the the Oracle DB can be Java code that access
the database via JDBC.

That is what your code example it.

But Oracle support Java in another way.

Instead of writing your stored procedure in PL/SQL then you can
write in in Java.

Oracle DB has a JVM embedded and can execute Java stored procedures.

I am far from an Oracle expert and I can not say what is fastest.

I would probably use:
- PL/SQL for stored procedures that are SQL statement oriented
- Java for stored procedures that are really code oriented (string
manipulation, math, etc.)

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top