J
JY
How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
Thanks
PreparedStatement to the database to execute?
Thanks
JY said:How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
Raymond DeCampo said:That isn't how prepared statements (necessarily) work. The idea behind
the prepared statement is that the driver or database will precompile the
SQL into some driver or database specific format that allows for value
bindings. Typically the execution plan for the SQL is determined by this
(the execution plan is the steps the database will take to retrieve the
results; e.g., use index XYZ, full table scan of ABC, etc.).
It is possible for a JDBC driver to trivially implement PreparedStatements
by generating SQL and transmitting that to the database. However, in such
a driver PreparedStatements would not be any more efficient than regular
Statements.
If what you really wanted to achieve was to known what parameters are
being passed to the PreparedStatement there are JDBC spy tools that can
help.
HTH,
Ray
JY said:I need to print out all the SQL messages as being submitted to database, in
my log file. I want to write a method which will take PreparedStatement as
an argument and print out its SQL to server.log file. Anywhere in my
application after I have set arguments to a PreparedStatement, I will call
this method before executing the SQL in PreparedStatement. Thats why I ask
this question. Any way I can achieve this task?
Raymond DeCampo said:JY said:I need to print out all the SQL messages as being submitted to database,
in my log file. I want to write a method which will take
PreparedStatement as an argument and print out its SQL to server.log
file. Anywhere in my application after I have set arguments to a
PreparedStatement, I will call this method before executing the SQL in
PreparedStatement. Thats why I ask this question. Any way I can achieve
this task?
Perhaps the best approach will be to examine the logging options provided
by your JDBC driver. But I re-iterate, the term "SQL message" does not
necessarily apply to a PreparedStatement. Also, you do not "execute the
SQL in [a] PreparedStatement." You execute the PreparedStatement.
HTH,
Ray
Can find a lot of examples at the "The Java Developers Almanac 1.4"JY said:How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
Thanks
That is because the SQL statement is embedded in the DataWindow object.JY said:Raymond DeCampo said:Perhaps the best approach will be to examine the logging options providedJY said:JY wrote:
How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
That isn't how prepared statements (necessarily) work. The idea behind
the prepared statement is that the driver or database will precompile the
SQL into some driver or database specific format that allows for value
bindings. Typically the execution plan for the SQL is determined by this
(the execution plan is the steps the database will take to retrieve the
results; e.g., use index XYZ, full table scan of ABC, etc.).
It is possible for a JDBC driver to trivially implement
PreparedStatements by generating SQL and transmitting that to the
database. However, in such a driver PreparedStatements would not be any
more efficient than regular Statements.
If what you really wanted to achieve was to known what parameters are
being passed to the PreparedStatement there are JDBC spy tools that can
help.
HTH,
Ray
--
This signature intentionally left blank.
I need to print out all the SQL messages as being submitted to database,
in my log file. I want to write a method which will take
PreparedStatement as an argument and print out its SQL to server.log
file. Anywhere in my application after I have set arguments to a
PreparedStatement, I will call this method before executing the SQL in
PreparedStatement. Thats why I ask this question. Any way I can achieve
this task?
by your JDBC driver. But I re-iterate, the term "SQL message" does not
necessarily apply to a PreparedStatement. Also, you do not "execute the
SQL in [a] PreparedStatement." You execute the PreparedStatement.
HTH,
Ray
So java does not have a function which can tell me the SQL statement which
will be executed? In other languages like PowerBuilder, you can get the SQL
statement you are going to submit.
JY said:So java does not have a function which can tell me the SQL statement which
will be executed? In other languages like PowerBuilder, you can get the SQL
statement you are going to submit.
Raymond DeCampo said:JY said:JY wrote:
How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
That isn't how prepared statements (necessarily) work. The idea behind
the prepared statement is that the driver or database will precompile the
SQL into some driver or database specific format that allows for value
bindings. Typically the execution plan for the SQL is determined by this
(the execution plan is the steps the database will take to retrieve the
results; e.g., use index XYZ, full table scan of ABC, etc.).
It is possible for a JDBC driver to trivially implement
PreparedStatements by generating SQL and transmitting that to the
database. However, in such a driver PreparedStatements would not be any
more efficient than regular Statements.
If what you really wanted to achieve was to known what parameters are
being passed to the PreparedStatement there are JDBC spy tools that can
help.
HTH,
Ray
--
This signature intentionally left blank.
I need to print out all the SQL messages as being submitted to database,
in my log file. I want to write a method which will take
PreparedStatement as an argument and print out its SQL to server.log
file. Anywhere in my application after I have set arguments to a
PreparedStatement, I will call this method before executing the SQL in
PreparedStatement. Thats why I ask this question. Any way I can achieve
this task?
Perhaps the best approach will be to examine the logging options provided
by your JDBC driver. But I re-iterate, the term "SQL message" does not
necessarily apply to a PreparedStatement. Also, you do not "execute the
SQL in [a] PreparedStatement." You execute the PreparedStatement.
HTH,
Ray
So java does not have a function which can tell me the SQL statement which
will be executed? In other languages like PowerBuilder, you can get the SQL
statement you are going to submit.
PreparedStatement to the database to execute?
So java does not have a function which can tell me the SQL statement which
will be executed? In other languages like PowerBuilder, you can get the SQL
statement you are going to submit.
JY said:How can I get the SQL statement which will be submitted by the
PreparedStatement to the database to execute?
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.