How to log SPRING JDBCTEMPLATE Prepared called query for debugging purpose

109 views
Skip to first unread message

anurag

unread,
Mar 8, 2011, 6:30:58 PM3/8/11
to jdbcdslog-discuss, anuragg...@gmail.com
I am executing below code
jdbcTemplate.update("update demo_student set fname=? where id = ?",
new Object[] { "RAHUL", new Long(11) });
need generated query like.....for debugging purpose, real application
is having 20-30 parameters, its very tough to make query and send back
to database developer
update demo_student set fname='RAHUL' where id = 11;

Please provide me steps how I can log the query into file or console
window?

Andrey Kolyadenko

unread,
Mar 8, 2011, 6:38:06 PM3/8/11
to jdbcdslo...@googlegroups.com
Hi, you can follow steps from the wiki and configure logging proxy depends on your environment. If you will provide more details how you are accessing DB(app server/servlet container, DB type, how you configure DB connection) I may give you some hints.

anurag

unread,
Mar 8, 2011, 6:45:30 PM3/8/11
to jdbcdslog-discuss
I am using spring to initializing the database connections and those
are in applicationContext.xml configuration file
And java DAO part we are getting the jdbcTemplate Object and after
that we are executing the above query.for the logging things we are
using log4j.
Now question is how to get the query of prepared statements.Is this
details relevant for you to provide me some steps to log the query
Thanks a lot for your quick reply.

On Mar 9, 4:38 am, Andrey Kolyadenko <akolyade...@gmail.com> wrote:
> Hi, you can follow steps from the wiki and configure logging proxy depends
> on your environment. If you will provide more details how you are accessing
> DB(app server/servlet container, DB type, how you configure DB connection) I
> may give you some hints.
>

anurag

unread,
Mar 8, 2011, 6:58:10 PM3/8/11
to jdbcdslog-discuss
I have got the ....
{{{62627 [http-8080-1] INFO org.jdbcdslog.StatementLogger -
java.sql.PreparedStatement.executeQuery select id, email from user
where username = ? parameters: {'admin'} 12ms.}}}

from http://code.google.com/p/jdbcdslog/source/browse/wiki/UserGuide.wiki?r=126

here its showing parameters separate, Can you please tell me it can
show full query because based upon above output we have to again
rplaced the username with admin. again we have to some extra work.
Please update me for the same , waiting for your reply.......

Andrey Kolyadenko

unread,
Mar 8, 2011, 7:04:33 PM3/8/11
to jdbcdslo...@googlegroups.com, anurag
jdbcdslog doesn't have such feature, and I don't believe it does make sense to implement it in jdbcdslog, but I think you can develop simple script using your favorite language which will parse log file and then do that substitution automatically.

anurag

unread,
Mar 8, 2011, 7:11:51 PM3/8/11
to jdbcdslog-discuss
last question....
you mention "I don't believe it does make sense to implement it in
jdbcdslog, "
May I know why, If we provide query with parameters that will be easy
to take the query and run on TOAD or Query browser to find where is
the issues, in language code or database side.


On Mar 9, 5:04 am, Andrey Kolyadenko <akolyade...@gmail.com> wrote:
> jdbcdslog doesn't have such feature, and I don't believe it does make sense
> to implement it in jdbcdslog, but I think you can develop simple script
> using your favorite language which will parse log file and then do that
> substitution automatically.
>
> On Tue, Mar 8, 2011 at 3:58 PM, anurag <anuraggupta....@gmail.com> wrote:
> > I have got the ....
> > {{{62627 [http-8080-1] INFO org.jdbcdslog.StatementLogger -
> > java.sql.PreparedStatement.executeQuery select id, email from user
> > where username = ? parameters: {'admin'} 12ms.}}}
>
> > from
> >http://code.google.com/p/jdbcdslog/source/browse/wiki/UserGuide.wiki?...

Andrey Kolyadenko

unread,
Mar 8, 2011, 7:36:49 PM3/8/11
to jdbcdslo...@googlegroups.com
I think its because the purpose of jdbcdslog is to log what is happening, and in that particular case we will mix the cases when variable binded through PreparedStatement class, and just concatenated into sql string. The person who is looking to the logs will not see the difference.
But probably it does make sense to implement it through some configuration option, which will optionally turn on that substitution logic.
Reply all
Reply to author
Forward
0 new messages