当前位置: 首页>>代码示例>>Java>>正文


Java CommunicationsException类代码示例

本文整理汇总了Java中com.mysql.jdbc.exceptions.jdbc4.CommunicationsException的典型用法代码示例。如果您正苦于以下问题:Java CommunicationsException类的具体用法?Java CommunicationsException怎么用?Java CommunicationsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CommunicationsException类属于com.mysql.jdbc.exceptions.jdbc4包,在下文中一共展示了CommunicationsException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConnection

import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException; //导入依赖的package包/类
public Connection getConnection() {
	try {
		if(sqlite){
			// To avoid concurrency problem with SQLite, we will just use one connection. Cf : constructor above for SQLite
			synchronized (SQLiteConn) {
				SQLiteConn = DriverManager.getConnection("jdbc:sqlite:" + BAT.getInstance().getDataFolder().getAbsolutePath() + File.separator
							+ "bat_database.db");
				return SQLiteConn;
			}
		}
		return ds.getConnection();
	} catch (final SQLException e) {
		BAT.getInstance().getLogger().severe(
		        "BAT can't etablish connection with the database. Please report this and include the following lines :");
		if(e.getCause() instanceof CommunicationsException){
		    BAT.getInstance().getLogger().severe(e.getCause().getMessage());
		}
           if (BAT.getInstance().getConfiguration().isDebugMode()) {
               e.printStackTrace();
           }
		return null;
	}
}
 
开发者ID:alphartdev,项目名称:BungeeAdminTools,代码行数:24,代码来源:DataSourceHandler.java

示例2: isExceptionIndicativeOfOverload

import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException; //导入依赖的package包/类
/**
 * Indicates whether an exception is a symptom of MySQL being overloaded or slow.
 * Typical symptoms are connection pool exhaustion or MySQL connection/socket timeouts.
 */
public static boolean isExceptionIndicativeOfOverload(Exception e) {
  return e instanceof MySQLNonTransientConnectionException
      || e instanceof CommunicationsException
      || (e instanceof SQLNestedException
              && e.getCause() instanceof NoSuchElementException);
}
 
开发者ID:pinterest-attic,项目名称:pinlater,代码行数:11,代码来源:MySQLBackendUtils.java

示例3: DataSourceHandler

import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException; //导入依赖的package包/类
/**
 * Constructor used for MySQL
 * 
 * @param host
 * @param port
 * @param database
 * @param username
 * @param password
 * @throws SQLException 
 */
public DataSourceHandler(final String host, final String port, final String database, final String username, final String password) throws SQLException{
	// Check database's informations and init connection
	this.host = Preconditions.checkNotNull(host);
	this.port = Preconditions.checkNotNull(port);
	this.database = Preconditions.checkNotNull(database);
	this.username = Preconditions.checkNotNull(username);
	this.password = Preconditions.checkNotNull(password);

	BAT.getInstance().getLogger().config("Initialization of HikariCP in progress ...");
	BasicConfigurator.configure(new NullAppender());
	ds = new HikariDataSource();
	ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + 
			"?useLegacyDatetimeCode=false&serverTimezone=" + TimeZone.getDefault().getID());
	ds.setUsername(this.username);
	ds.setPassword(this.password);
	ds.addDataSourceProperty("cachePrepStmts", "true");
	ds.setMaximumPoolSize(8);
	try {
		final Connection conn = ds.getConnection();
	    int intOffset = Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000;
	    String offset = String.format("%02d:%02d", Math.abs(intOffset / 3600), Math.abs((intOffset / 60) % 60));
	    offset = (intOffset >= 0 ? "+" : "-") + offset;
		conn.createStatement().executeQuery("SET time_zone='" + offset + "';");
		conn.close();
		BAT.getInstance().getLogger().config("BoneCP is loaded !");
	} catch (final SQLException e) {
		BAT.getInstance().getLogger().severe("BAT encounters a problem during the initialization of the database connection."
				+ " Please check your logins and database configuration.");
		if(e.getCause() instanceof CommunicationsException){
		    BAT.getInstance().getLogger().severe(e.getCause().getMessage());
		}
		if(BAT.getInstance().getConfiguration().isDebugMode()){
		    BAT.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
		}
		throw e;
	}
	sqlite = false;
}
 
开发者ID:alphartdev,项目名称:BungeeAdminTools,代码行数:49,代码来源:DataSourceHandler.java

示例4: handleSqlException

import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException; //导入依赖的package包/类
public static DatabaseConnectionException handleSqlException(SQLException ex) throws DatabaseConnectionException {
    if (ex instanceof CommunicationsException) {
        return new DatabaseConnectionException();
    }
    else if (ex instanceof SQLException) {
        if (ex.getMessage().startsWith("Unable to open a test connection")) {
            return new DatabaseConnectionException();
        }
    }
    throw new RuntimeException("An unknown SQL exception has occurred.", ex);
}
 
开发者ID:OverCaste,项目名称:OverPermissions,代码行数:12,代码来源:MySQLManager.java


注:本文中的com.mysql.jdbc.exceptions.jdbc4.CommunicationsException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。