List of usage examples for java.sql Connection setClientInfo
void setClientInfo(String name, String value) throws SQLClientInfoException;
From source file:org.apache.hadoop.hive.service.HSSessionItem.java
public String getPBTableModifiedTime(String DBName, String tableName) throws HiveServerException { l4j.info("get PB Table Modified Time of " + DBName + "::" + tableName); String modified_time = null;/*from w w w .j a v a2s . com*/ conf = SessionState.get().getConf(); String url = conf.get("hive.metastore.pbjar.url", "jdbc:postgresql://10.136.130.102:5432/pbjar"); String user = conf.get("hive.metastore.user", "tdw"); String passwd = conf.get("hive.metastore.passwd", "tdw"); String protoVersion = conf.get("hive.protobuf.version", "2.3.0"); String driver = "org.postgresql.Driver"; ResultSet rs = null; Connection connect = null; PreparedStatement ps = null; try { Class.forName(driver).newInstance(); } catch (InstantiationException e2) { e2.printStackTrace(); } catch (IllegalAccessException e2) { e2.printStackTrace(); } catch (ClassNotFoundException e2) { e2.printStackTrace(); } try { connect = DriverManager.getConnection(url, user, passwd); try { String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); String processID = processName.substring(0, processName.indexOf('@')); String appinfo = "getPBTableModifiedTime_" + processID + "_" + SessionState.get().getSessionName(); connect.setClientInfo("ApplicationName", appinfo); } catch (Exception e) { e.printStackTrace(); } } catch (SQLException e2) { e2.printStackTrace(); } try { ps = connect.prepareStatement("SELECT to_char(modified_time,'yyyymmddhh24miss') as modified_time " + " FROM pb_proto_jar WHERE db_name=? and tbl_name=? and protobuf_version=? order by modified_time desc limit 1"); } catch (SQLException e1) { e1.printStackTrace(); } try { ps.setString(1, DBName.toLowerCase()); } catch (SQLException e1) { e1.printStackTrace(); } try { ps.setString(2, tableName.toLowerCase()); ps.setString(3, protoVersion); } catch (SQLException e1) { e1.printStackTrace(); } try { l4j.info("select modifiedtime from tpg"); rs = ps.executeQuery(); } catch (SQLException e1) { e1.printStackTrace(); } try { if (rs.next()) { modified_time = rs.getString("modified_time"); } else { l4j.info("Can not find the modified_time of " + DBName + "::" + tableName + " in the tPG."); } } catch (SQLException e1) { e1.printStackTrace(); } try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } try { ps.close(); } catch (SQLException e) { e.printStackTrace(); } return modified_time; }