Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, March 23, 2012

Query very slow via JDBC compared to Query Analyzer

I am trying out the JDBC driver SP3 for data access in a Java application,
and I find that some of the queries I had tested in Query Analyzer are
returning very slowly in my Java application. The queries not extremely
complex (just a couple joins), and they return small datasets (on the order
of 2-20 rows with 2 columns each).
In one example, I am waiting about 20 seconds for a query to return in my
Java application where it took less than one second in Query Analyzer.
I'm not really sure where to look to address these performance issues. Is
there something obvious I might have wrong on my connection string? I connect
to SQL Server over 100Mb Ethernet.
I'd appreciate any help!
Thanks
OK, it seems I did not choose very good search parameters when I looked for
answers previously... turns out the SendStringParametersAsUnicode as the
culprit. Sorry =) But thanks to those who posted previously.
"bbabey" wrote:

> I am trying out the JDBC driver SP3 for data access in a Java application,
> and I find that some of the queries I had tested in Query Analyzer are
> returning very slowly in my Java application. The queries not extremely
> complex (just a couple joins), and they return small datasets (on the order
> of 2-20 rows with 2 columns each).
> In one example, I am waiting about 20 seconds for a query to return in my
> Java application where it took less than one second in Query Analyzer.
> I'm not really sure where to look to address these performance issues. Is
> there something obvious I might have wrong on my connection string? I connect
> to SQL Server over 100Mb Ethernet.
> I'd appreciate any help!
> Thanks

Wednesday, March 7, 2012

Query Timeout

Hi there,
I have a java application which connects to an sqlServer database and issues
an SQL update statement.
When you attempt to connect to the database if there is no connection then
this is fine, it will retry for x times and timeout at the time you have
set.
The problem is if you have made a valid connection and then disconnect the
database from the network and try to run the sql UPDATE. The update will
only attempt one time and basically hang until the connection is
re-established.
The other way round, if the machine the java application is running on is
disconnected it works fine. i.e. it attempt to send the UPDATE query fro x
times and times out at the interval set.
It only seems to hang if the java application is still connected but the
database is disconnected. Is this a general problem with the jdbc driver?
Regards
Jamie
Jamie wrote:

> Hi there,
> I have a java application which connects to an sqlServer database and issues
> an SQL update statement.
> When you attempt to connect to the database if there is no connection then
> this is fine, it will retry for x times and timeout at the time you have
> set.
> The problem is if you have made a valid connection and then disconnect the
> database from the network and try to run the sql UPDATE. The update will
> only attempt one time and basically hang until the connection is
> re-established.
> The other way round, if the machine the java application is running on is
> disconnected it works fine. i.e. it attempt to send the UPDATE query fro x
> times and times out at the interval set.
> It only seems to hang if the java application is still connected but the
> database is disconnected. Is this a general problem with the jdbc driver?
> Regards
> Jamie
It's at a lower level than that. The failure you cause means the TCP stack will
take minutes before it notifies the driver that the socket is dead. You might
try setting the query timeout on your statement before executing it. Then the
driver may be able to return control to you sooner.
Joe Weinstein at BEA