本文整理汇总了Java中com.zaxxer.hikari.HikariDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HikariDataSource.getConnection方法的具体用法?Java HikariDataSource.getConnection怎么用?Java HikariDataSource.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.zaxxer.hikari.HikariDataSource
的用法示例。
在下文中一共展示了HikariDataSource.getConnection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUpdateTime
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private static String getUpdateTime(){
try {
String time="";
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
final Connection connection = mysqlDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_TIME_SQL);
ResultSet resultSet=preparedStatement.executeQuery();
while (resultSet.next()){
time=resultSet.getString(1);
}
System.out.println("当前是第"+time+"次爬取");
return time;
} catch (SQLException e) {
e.printStackTrace();
return "2";
}
}
示例2: executeChangeUpdateTimeSQL
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public static boolean executeChangeUpdateTimeSQL(){
try {
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
final Connection connection = mysqlDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(CHANGE_UPDATE_TIME_SQL);
preparedStatement.setString(1,getChangeUpdateTime());
preparedStatement.setString(2,Helper.getCrawlTime());
boolean isSuccessful=preparedStatement.executeUpdate()!=0;
if (isSuccessful){
System.out.println("成功更新爬取次数");
}
return isSuccessful;
} catch (SQLException e) {
e.printStackTrace();
System.out.println("更新爬取次数失败");
return false;
}
}
示例3: loadMetricsLinks
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public static List<PaperMetricsLink> loadMetricsLinks() {
List<PaperMetricsLink> paperMetricsLinks = new ArrayList<>();
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
//从第二张数据表中取出已有所有论文相关指标页面链接
try (final Connection connection = mysqlDataSource.getConnection()) {
try (final PreparedStatement preparedStatement = connection.prepareStatement("SELECT URL FROM REF_DATA")) {
try (ResultSet results = preparedStatement.executeQuery()) {
while (results.next()) {
final String url = results.getString("URL");
paperMetricsLinks.add(new PaperMetricsLink(url));
}
}
}
} catch (SQLException e) {
System.out.println("Connected DB Failed");
}
return paperMetricsLinks;
}
示例4: getLastUrlForLastTime
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public static String getLastUrlForLastTime() {
String urlForLastTime = null;
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
//从第二张数据表中取出已有所有论文相关指标页面链接
try (final Connection connection = mysqlDataSource.getConnection()) {
try (final PreparedStatement preparedStatement = connection.prepareStatement("SELECT URL FROM NT_PAPERS LIMIT 1")) {
try (ResultSet results = preparedStatement.executeQuery()) {
while (results.next()) {
urlForLastTime = results.getString("URL");
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return urlForLastTime;
}
示例5: testAccessibility
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
@Ignore
public void testAccessibility() throws SQLException {
final HikariDataSource mysqlDataSource =
DataSource.getMysqlDataSource();
final Connection connection =
mysqlDataSource.getConnection();
final PreparedStatement preparedStatement =
connection.prepareStatement("SHOW TABLES;");
final ResultSet resultSet =
preparedStatement.executeQuery();
Assert.assertNotNull(resultSet);
}
示例6: openConnectionPool
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private static void openConnectionPool(String url, String driverClass, String username, String password) throws Exception {
//force the driver to be loaded
Class.forName(driverClass);
HikariDataSource pool = new HikariDataSource();
pool.setJdbcUrl(url);
pool.setUsername(username);
pool.setPassword(password);
pool.setMaximumPoolSize(4);
pool.setMinimumIdle(1);
pool.setIdleTimeout(60000);
pool.setPoolName("Hl7MergeCheckerPool" + url);
pool.setAutoCommit(false);
connectionPool = pool;
//test getting a connection
Connection conn = pool.getConnection();
conn.close();
}
示例7: getRefDataNum
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public static int getRefDataNum() {
int num = 0;
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
try (final Connection connection = mysqlDataSource.getConnection()) {
try (final Statement statement = connection.createStatement()) {
try (ResultSet results =statement.executeQuery("select count(*) as rowCount from REF_DATA")) {
results.next();
num = results.getInt("rowCount");
}
}
} catch (SQLException e) {
System.out.println("Connected DB Failed");
}
return num;
}
示例8: store
import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
public boolean store() {
System.out.println("Store begin: type = MetricsPaper.");
LOGGER.info("本次更新论文" + Log.getUpdateTotalNumbers().get() + "篇,"
+ "正在更新第" + Log.getCurrentUpdateNumbers().incrementAndGet() + "篇\n"
+ "链接为:" + getUrl());
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
// 加上选择条件 URL
REF_UPDATE_SQL = REF_UPDATE_SQL + "'" + getUrl() + "'";
try (final Connection connection = mysqlDataSource.getConnection()){
try (final PreparedStatement preparedStatement = connection.prepareStatement(REF_UPDATE_SQL)) {
bindUpdateSql(preparedStatement);
// 判断执行是否成功
boolean succeed = preparedStatement.executeUpdate() != 0;
if (succeed) {
LOGGER.info("当前共有" + getUpdateSucceedNumbers().incrementAndGet() + "篇论文相关指标更新成功...\n"
+ "链接为;" + getUrl());
}else {
LOGGER.info("当前共有" + getUpdateFailedNumbers().incrementAndGet() + "篇论文相关指标更新失败...\n"
+ "链接为;" + getUrl());
}
boolean isSuccess= updateRefDataIntoES();//更新论文指标到ElasticSearch中的REF_DATA
if (!isSuccess){
LOGGER.info("更新论文指标到ElasticSearch中的REF_DATA失败");
}else {
LOGGER.info("更新论文指标到ElasticSearch中的REF_DATA成功");
}
//保存更新的具体数据到数据库中
DBLog.saveUpdateDetailLog(getUrl(),getCurrentUpdateNumbers().get(),getUpdateTotalNumbers().get(),succeed,
DetailCrawler.getUpdateTime());
if (getCurrentUpdateNumbers().get() == getUpdateTotalNumbers().get()) {
LOGGER.info("更新完成,本次更新相关指标论文总量:" +getUpdateTotalNumbers().get()
+ " 成功数:" + getUpdateSucceedNumbers().get()
+ " 失败数:" + getUpdateFailedNumbers());
long startTime= DetailCrawler.getUpdateMillisecond();//开始更新的时间
long endTime=System.currentTimeMillis();//结束更新的时间
long total=endTime-startTime;
String averageTime=Helper.getSeconds(total/getUrlNumbers().get());
//保存更新完成后的总体情况数据到数据库中
DBLog.saveFinalUpdateLog(DetailCrawler.getUpdateTime(),getUpdateSucceedNumbers().get(),
getUpdateFailedNumbers().get(),getUpdateTotalNumbers().get());
}
return succeed;
}
}catch (SQLException e){
e.printStackTrace();
}
return false;
}