org.springframework.jdbc.core.JdbcTemplate.setQueryTimeout()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.setQueryTimeout()方法的一些代码示例,展示了JdbcTemplate.setQueryTimeout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.setQueryTimeout()方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:setQueryTimeout

JdbcTemplate.setQueryTimeout介绍

[英]Set the query timeout for statements that this JdbcTemplate executes.

Default is -1, indicating to use the JDBC driver's default (i.e. to not pass a specific query timeout setting on the driver).

Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
[中]设置此JdbcTemplate执行的语句的查询超时。
默认值为-1,表示使用JDBC驱动程序的默认值(即不传递驱动程序上的特定查询超时设置)。
注意:在事务级别指定了超时的事务内执行时,此处指定的任何超时将被剩余的事务超时覆盖。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the query timeout for statements that this RDBMS operation executes.
 * <p>Default is 0, indicating to use the JDBC driver's default.
 * <p>Note: Any timeout specified here will be overridden by the remaining
 * transaction timeout when executing within a transaction that has a
 * timeout specified at the transaction level.
 */
public void setQueryTimeout(int queryTimeout) {
  this.jdbcTemplate.setQueryTimeout(queryTimeout);
}

代码示例来源:origin: alibaba/nacos

@Override
public boolean checkMasterWritable() {
  testMasterWritableJT.setDataSource(jt.getDataSource());
  /**
   *  防止login接口因为主库不可用而rt太长
   */
  testMasterWritableJT.setQueryTimeout(1);
  String sql = " SELECT @@read_only ";
  try {
    Integer result = testMasterWritableJT.queryForObject(sql, Integer.class);
    if (result == null) {
      return false;
    } else {
      return result.intValue() == 0 ? true : false;
    }
  } catch (CannotGetJdbcConnectionException e) {
    fatalLog.error("[db-error] " + e.toString(), e);
    return false;
  }
}

代码示例来源:origin: alibaba/nacos

jt.setQueryTimeout(queryTimeout);
testMasterJT.setQueryTimeout(queryTimeout);
testMasterWritableJT.setQueryTimeout(1);

代码示例来源:origin: alibaba/nacos

@Override
  public void run() {
    defaultLog.info("check master db.");
    boolean isFound = false;
    int index = -1;
    for (BasicDataSource ds : dataSourceList) {
      index++;
      testMasterJT.setDataSource(ds);
      testMasterJT.setQueryTimeout(queryTimeout);
      try {
        testMasterJT
          .update("DELETE FROM config_info WHERE data_id='com.alibaba.nacos.testMasterDB'");
        if (jt.getDataSource() != ds) {
          fatalLog.warn("[master-db] {}", ds.getUrl());
        }
        jt.setDataSource(ds);
        tm.setDataSource(ds);
        isFound = true;
        masterIndex = index;
        break;
      } catch (DataAccessException e) { // read only
        e.printStackTrace(); // TODO remove
      }
    }
    if (!isFound) {
      fatalLog.error("[master-db] master db not found.");
      MetricsMonitor.getDbException().increment();
    }
  }
}

代码示例来源:origin: alibaba/nacos

jdbcTemplate.setQueryTimeout(queryTimeout);
jdbcTemplate.setDataSource(ds);

代码示例来源:origin: alibaba/nacos

@PostConstruct
public void init() {
  BasicDataSource ds = new BasicDataSource();
  ds.setDriverClassName(JDBC_DRIVER_NAME);
  ds.setUrl("jdbc:derby:" + NACOS_HOME + File.separator + DERBY_BASE_DIR + ";create=true");
  ds.setUsername(USER_NAME);
  ds.setPassword(PASSWORD);
  ds.setInitialSize(20);
  ds.setMaxActive(30);
  ds.setMaxIdle(50);
  ds.setMaxWait(10000L);
  ds.setPoolPreparedStatements(true);
  ds.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES
    .toMillis(10L));
  ds.setTestWhileIdle(true);
  jt = new JdbcTemplate();
  jt.setMaxRows(50000);
  jt.setQueryTimeout(5000);
  jt.setDataSource(ds);
  DataSourceTransactionManager tm = new DataSourceTransactionManager();
  tjt = new TransactionTemplate(tm);
  tm.setDataSource(ds);
  tjt.setTimeout(5000);
  if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
    reload();
  }
}

代码示例来源:origin: spring-projects/spring-framework

template.setQueryTimeout(queryTimeout.intValue());

代码示例来源:origin: apache/servicemix-bundles

/**
 * Set the query timeout for statements that this RDBMS operation executes.
 * <p>Default is 0, indicating to use the JDBC driver's default.
 * <p>Note: Any timeout specified here will be overridden by the remaining
 * transaction timeout when executing within a transaction that has a
 * timeout specified at the transaction level.
 */
public void setQueryTimeout(int queryTimeout) {
  this.jdbcTemplate.setQueryTimeout(queryTimeout);
}

代码示例来源:origin: org.springframework/org.springframework.jdbc

/**
 * Set the query timeout for statements that this RDBMS operation executes.
 * <p>Default is 0, indicating to use the JDBC driver's default.
 * <p>Note: Any timeout specified here will be overridden by the remaining
 * transaction timeout when executing within a transaction that has a
 * timeout specified at the transaction level.
 */
public void setQueryTimeout(int queryTimeout) {
  this.jdbcTemplate.setQueryTimeout(queryTimeout);
}

代码示例来源:origin: io.bufferslayer/buffer-spring-jdbc

public void setQueryTimeout(int queryTimeout) {
 delegate.setQueryTimeout(queryTimeout);
}

代码示例来源:origin: io.bufferslayer/bufferslayer-spring-jdbc

public void setQueryTimeout(int queryTimeout) {
 delegate.setQueryTimeout(queryTimeout);
}

代码示例来源:origin: stackoverflow.com

JdbcTemplate template = new JdbcTemplate(...);
template.setQueryTimeout(...);
NamedParameterJdbcTemplate named = new NamedParameterJdbcTemplate(template);

代码示例来源:origin: stackoverflow.com

JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
jdbcTemplate.setQueryTimeout(2);
jdbcTemplate.execute(...);

代码示例来源:origin: yandex/graphouse

@Bean
public JdbcTemplate clickHouseJdbcTemplate(
  DataSource clickHouseDataSource,
  @Value("${graphouse.clickhouse.query-timeout-seconds}") int queryTimeoutSeconds
) {
  final JdbcTemplate jdbcTemplate = new JdbcTemplate();
  jdbcTemplate.setDataSource(clickHouseDataSource);
  jdbcTemplate.setQueryTimeout(queryTimeoutSeconds);
  return jdbcTemplate;
}

代码示例来源:origin: yandex/graphouse

@Bean
public JdbcTemplate clickHouseJdbcTemplateAutohide(
  DataSource clickHouseDataSource,
  @Value("${graphouse.autohide.clickhouse.query-timeout-seconds}") int autoHideQueryTimeoutSeconds) {
  final JdbcTemplate jdbcTemplate = new JdbcTemplate();
  jdbcTemplate.setDataSource(clickHouseDataSource);
  jdbcTemplate.setQueryTimeout(autoHideQueryTimeoutSeconds);
  return jdbcTemplate;
}

代码示例来源:origin: Netflix/metacat

/**
 * hive metadata read JDBC template. Query timeout is set to control long running read queries.
 *
 * @param connectorContext connector config.
 * @param hiveDataSource hive data source
 * @return hive JDBC Template
 */
@Bean
public JdbcTemplate hiveReadJdbcTemplate(
  final ConnectorContext connectorContext,
  @Qualifier("hiveDataSource") final DataSource hiveDataSource) {
  final JdbcTemplate result = new JdbcTemplate(hiveDataSource);
  result.setQueryTimeout(getDataStoreReadTimeout(connectorContext) / 1000);
  return result;
}

代码示例来源:origin: Netflix/metacat

/**
 * hive metadata write JDBC template. Query timeout is set to control long running write queries.
 *
 * @param connectorContext connector config.
 * @param hiveDataSource hive data source
 * @return hive JDBC Template
 */
@Bean
public JdbcTemplate hiveWriteJdbcTemplate(
  final ConnectorContext connectorContext,
  @Qualifier("hiveDataSource") final DataSource hiveDataSource) {
  final JdbcTemplate result = new JdbcTemplate(hiveDataSource);
  result.setQueryTimeout(getDataStoreWriteTimeout(connectorContext) / 1000);
  return result;
}

代码示例来源:origin: com.netflix.metacat/metacat-connector-hive

/**
 * hive metadata read JDBC template. Query timeout is set to control long running read queries.
 *
 * @param connectorContext connector config.
 * @param hiveDataSource hive data source
 * @return hive JDBC Template
 */
@Bean
public JdbcTemplate hiveReadJdbcTemplate(
  final ConnectorContext connectorContext,
  @Qualifier("hiveDataSource") final DataSource hiveDataSource) {
  final JdbcTemplate result = new JdbcTemplate(hiveDataSource);
  result.setQueryTimeout(getDataStoreReadTimeout(connectorContext) / 1000);
  return result;
}

代码示例来源:origin: com.netflix.metacat/metacat-connector-hive

/**
 * hive metadata write JDBC template. Query timeout is set to control long running write queries.
 *
 * @param connectorContext connector config.
 * @param hiveDataSource hive data source
 * @return hive JDBC Template
 */
@Bean
public JdbcTemplate hiveWriteJdbcTemplate(
  final ConnectorContext connectorContext,
  @Qualifier("hiveDataSource") final DataSource hiveDataSource) {
  final JdbcTemplate result = new JdbcTemplate(hiveDataSource);
  result.setQueryTimeout(getDataStoreWriteTimeout(connectorContext) / 1000);
  return result;
}

代码示例来源:origin: fast-sql/FastSQL

/**
 * 创建一个SQL实例
 */
public SQL sql() {
  if (this.jdbcTemplate == null) {
    this.jdbcTemplate = new JdbcTemplate();
    this.jdbcTemplate.setIgnoreWarnings(ignoreWarnings);
    this.jdbcTemplate.setFetchSize(fetchSize);
    this.jdbcTemplate.setMaxRows(maxRows);
    this.jdbcTemplate.setQueryTimeout(queryTimeout);
    this.jdbcTemplate.setSkipResultsProcessing(skipResultsProcessing);
    this.jdbcTemplate.setSkipUndeclaredResults(skipUndeclaredResults);
    this.jdbcTemplate.setResultsMapCaseInsensitive(resultsMapCaseInsensitive);
    this.jdbcTemplate.setDataSource(this.dataSource);
  }
  return new SQL(this.jdbcTemplate, this.dataSourceType);
}

相关文章