• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how get connection Id of JDBC connection object

 
gagan narula
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need to allow user to kill queries running in database(i.e Mysql)from our web application. I have gone tghrough some links and I come to know that we can achieve this by killing connection of connection object.

But I am not able to find any method in JDBC connection object API to get connection id of object in Java Docs

Can any one please let me know any way to get the conncetion id of JDBC connection object or is there any other way by which I can achieve the same.

Please help me out.

Thanks
Gagan
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what a "connection ID" is, but what good would it do you? As long as you have a Connection object, you can close it. I'm fairly certain that it would be DB-dependent if the query is aborted at that point, though; some DBs may still execute it until completion.
 
gagan narula
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this wont solve my problem. Actually we want to kill queries which are taking more time manually.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consult the documentation of whichever DB you're using; the DB may kill a query if the connection is closed, or you may need to call some system stored procedure, or nothing may work. This is highly DB-specific, and JDBC has no provisions for this.
 
gagan narula
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To kill any query on mysql there is a command:

Kill <connection id>

I have created a sample application in Java and execute the same query from Java manually. I am able to kill the query but in the same program, I have got the connection id using watch of eclipse. The connection id is present in the connection object of JDBC but there is no function available to get the same value from program

Thanks
Gagan
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to get at it by casting the Connection to whatever MySQL-specific class/interface implements it; maybe that has methods to get at the ID. Heck, that may even have a method to cancel the last query...
 
gagan narula
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am not getting your reply. Connection object has property as connection id by the help of which we can kill the query. There is no method available in the connection class to get the value of that property.

Can you please explain it to me by the help of some example that would be very nice of you.

Gagan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic