You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by reena upadhyay <re...@gmail.com> on 2015/11/30 08:50:47 UTC
How to set idle Hive jdbc connection out from java code using hive jdbc
I am using hive jdbc 1.0 in my java application to create connection with
hive server and execute query. I want to set the idle hive connection
timeout from java code. Like say, user first creates the hive connection,
and if the hive connection remains idle for next 10 minutes, then this
connection object should get expired. If user uses this same connection
object after 10 minutes for executing query, then hive jdbc should throw
error. Can you please tell me the way to achieve this through java code.
I know there is a property *hive.server2.idle.session.timeout *in hive, but
I don't know whether this is the right property required to be set from
java code or there is some other property. I tried setting this property in
jdbc connection string but it did not worked.
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e) {
LOG.error(ExceptionUtils.getStackTrace(e));
}
String jdbcurl = "
*jdbc:hive2://localhost:10000/idw?hive.server2.idle.session.timeout=1000ms";*
Connection con;
con = DriverManager.getConnection(jdbcurl,"root","");
Thread.sleep(3000);
Now below I am using connection object, hive jdbc should throw error here
as I used connection object after 3000 ms but I had set the idle timeout as
1000ms but hive jdbc had not thrown error
ResultSet rs = con.createStatement().executeQuery("select *
from idw.emp");
Need help on this.
Re: How to set idle Hive jdbc connection out from java code using
hive jdbc
Posted by Takahiko Saito <ty...@gmail.com>.
I don't think *hive.server2.idle.session.timeout can be set via client. It
might need to be set on server side.*
*So before you run your query, you might need to restart HS2 with that
property set, but I'm not sure that's what you are looking for.*
On Sun, Nov 29, 2015 at 11:50 PM, reena upadhyay <re...@gmail.com>
wrote:
> I am using hive jdbc 1.0 in my java application to create connection with
> hive server and execute query. I want to set the idle hive connection
> timeout from java code. Like say, user first creates the hive connection,
> and if the hive connection remains idle for next 10 minutes, then this
> connection object should get expired. If user uses this same connection
> object after 10 minutes for executing query, then hive jdbc should throw
> error. Can you please tell me the way to achieve this through java code.
>
> I know there is a property *hive.server2.idle.session.timeout *in hive,
> but I don't know whether this is the right property required to be set from
> java code or there is some other property. I tried setting this property in
> jdbc connection string but it did not worked.
>
> try {
> Class.forName("org.apache.hive.jdbc.HiveDriver");
> } catch (ClassNotFoundException e) {
> LOG.error(ExceptionUtils.getStackTrace(e));
> }
>
> String jdbcurl = "
> *jdbc:hive2://localhost:10000/idw?hive.server2.idle.session.timeout=1000ms";*
> Connection con;
> con = DriverManager.getConnection(jdbcurl,"root","");
>
> Thread.sleep(3000);
>
> Now below I am using connection object, hive jdbc should throw error here
> as I used connection object after 3000 ms but I had set the idle timeout as
> 1000ms but hive jdbc had not thrown error
>
> ResultSet rs = con.createStatement().executeQuery("select *
> from idw.emp");
>
> Need help on this.
>
--
Takahiko Saito