Hi:
I am using the following code to test connections made to an SQL Server 2000
database:
Statement stmt = con.createStatement ();
stmt.executeQuery ("select * from control");
stmt = con.createStatement ();
stmt.executeQuery ("select * from control");
stmt = con.createStatement ();
stmt.executeQuery ("select * from control");
con has previously been set up as a Connection object obtained via a call to
DriverManager.
When I look at the output of sp_who in SQL Query Analyzer, I see that a new
SQL Server process has been created each time that createStatement is called
(actually, not the first time; only one process exists after that call, and
that process appears after the call to DriverManager.getConnection).
I'm trying to avoid the JDBC driver make multiple connections to the SQL
Server for performance reasons; if it really is making a new connection each
time, that would obviously require some time which I don't want to waste.
It's possible I'm misinterpeting the output of Query Analyzer, and that
multiple database processes can be listed that are all using the same actual
connection (this seems possible, as the output of stmt.getConnection()
remains the same each time a stmt object is allocated in the code above).
Can anyone explain this behavior?
Thanks,
Ryan
Add the property 'selectMethod=cursor' to your connection-getting and this
odd behavior of the driver will go away.
Joe
Ryan McFall wrote:
> Hi:
> I am using the following code to test connections made to an SQL Server 2000
> database:
> Statement stmt = con.createStatement ();
> stmt.executeQuery ("select * from control");
> stmt = con.createStatement ();
> stmt.executeQuery ("select * from control");
> stmt = con.createStatement ();
> stmt.executeQuery ("select * from control");
> con has previously been set up as a Connection object obtained via a call to
> DriverManager.
> When I look at the output of sp_who in SQL Query Analyzer, I see that a new
> SQL Server process has been created each time that createStatement is called
> (actually, not the first time; only one process exists after that call, and
> that process appears after the call to DriverManager.getConnection).
> I'm trying to avoid the JDBC driver make multiple connections to the SQL
> Server for performance reasons; if it really is making a new connection each
> time, that would obviously require some time which I don't want to waste.
> It's possible I'm misinterpeting the output of Query Analyzer, and that
> multiple database processes can be listed that are all using the same actual
> connection (this seems possible, as the output of stmt.getConnection()
> remains the same each time a stmt object is allocated in the code above).
> Can anyone explain this behavior?
> Thanks,
> Ryan
>
Tuesday, March 20, 2012
Connections made by call to createStatement?
Labels:
2000databasestatement,
call,
code,
con,
connections,
createstatement,
database,
executequery,
following,
hii,
microsoft,
mysql,
oracle,
server,
sql,
stmt
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment