Question

Is "prepared-statement" a stored procedure? From this link it appears not to be. Comparison with prepared statements From this link it appears to be. JDBC introduction

(ctrl+f stored procedure to find the bit related to stored procedure in the second link)

In the latter link the code example they show in that official oracle web page, is a prepared statement, not a callable statement as I thought it would correspond to a stored procedure.

Was it helpful?

Solution

You are right, the code referenced in that tutorial does not call a stored procedure. The intention is to convey that this is a stored procedure written in Java:

The latest generation of database products allows stored procedures to be written using the Java programming language and the JDBC API.

The following code is an example of how to create a very simple stored procedure using the Java programming language. Note that the stored procedure is just a static Java method that contains normal JDBC code. It accepts two input parameters and uses them to change an employee's car number.

(emphasis mine)

For example Oracle supports Java stored procedures, the example in the tutorial is how you would implement that stored procedure using Java. In my opinion it is highly confusing because it is not how you call a stored procedure from Java, and this should not have been part of the JDBC tutorial in this form.

To be clear: A PreparedStatement itself is not a stored procedure, but it can be used to call (execute) a stored procedure (the same applies to Statement), a CallableStatement just has more features that are suitable for executing stored procedures.

In the tutorial the Java stored procedure uses a PreparedStatement to execute a query as part of the execution of that Java stored procedure. It is unfortunate that this tutorial clouds the issue by discussing this advanced subject without talking about the normal task of executing stored procedures.

OTHER TIPS

PreparedStatement is not a stored procedure. It can be any kind of SQL statement.

The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled. As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top