List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:at.alladin.rmbt.db.dao.QoSTestResultDao.java
@Override public QoSTestResult getById(Long id) throws SQLException { try (PreparedStatement psGetById = conn.prepareStatement( "SELECT nntr.uid, test_uid, nnto.test, success_count, failure_count, result AS result, " + " nnto.results as results, qos_test_uid, nnto.test_desc, nnto.test_summary FROM qos_test_result nntr " + " JOIN qos_test_objective nnto ON nntr.qos_test_uid = nnto.uid WHERE nntr.uid = ? AND nntr.deleted = 'FALSE' and nntr.implausible = 'FALSE'")) { psGetById.setLong(1, id);//from w w w. ja va 2 s .co m if (psGetById.execute()) { try (ResultSet rs = psGetById.getResultSet()) { if (rs.next()) { QoSTestResult nntr = instantiateItem(rs); return nntr; } else { throw new SQLException("empty result set"); } } } else { throw new SQLException("no result set"); } } }
From source file:net.mindengine.oculus.frontend.db.jdbc.BeanMapper.java
@Override public Object mapRow(ResultSet rs, int rowNum) throws SQLException { // TODO Auto-generated method stub ResultSetMetaData metaData = rs.getMetaData(); int columns = metaData.getColumnCount(); try {/*from w ww. ja va 2 s . c o m*/ Class<?> clazz = Class.forName(className); Object obj = clazz.newInstance(); for (int i = 1; i <= columns; i++) { String column = metaData.getColumnName(i); FieldMapper fm = fields.get(column); if (fm != null) { Method method = fm.getMethod(); String typeName = fm.getType().getSimpleName(); typeName = StringUtils.capitalize(typeName); if (typeName.endsWith("[]")) { typeName = typeName.substring(0, typeName.length() - 2) + "s"; } if (typeName.equals("Date")) { typeName = "Timestamp"; } if (typeName.equals("Integer")) { typeName = "Int"; } Method rsMethod = ResultSet.class.getMethod("get" + typeName, String.class); Object value = rsMethod.invoke(rs, column); if (value instanceof Timestamp) { Timestamp timestamp = (Timestamp) value; value = new Date(timestamp.getTime()); } method.invoke(obj, value); } } return obj; } catch (Exception e) { throw new SQLException(e); } }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationVisitorDispatch.java
public static void executeLDR(ServerDBConnection serverDBConnection, final ChannelHandlerContext channelHandlerContext, final byte[] query) throws SQLException { final MysqlLoadDataInfileRequestCollector resultConsumer = new MysqlLoadDataInfileRequestCollector( channelHandlerContext);/*from w w w. j a v a2 s .c om*/ try { final NativeCharSet clientCharSet = MysqlNativeCharSet.UTF8; final SSConnection ssCon1 = serverDBConnection.getSSConn(); Throwable t = ssCon1.executeInContext(new Callable<Throwable>() { public Throwable call() { try { LoadDataRequestExecutor.execute(channelHandlerContext, ssCon1, resultConsumer, clientCharSet.getJavaCharset(), query); } catch (Throwable e) { return e; } return null; } }); if (t != null && t.getCause() != null) { throw new PEException(t); } if (resultConsumer.getFileName() == null) { throw new SQLException(new PEException("Cannot handle load data statement: " + new String(query))); } } catch (Throwable t) { throw new SQLException(t); } }
From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java
public boolean dataDefinitionCausesTransactionCommit() throws SQLException { throw new SQLException("Unsupported TDDatabaseMetaData#dataDefinitionCausesTransactionCommit()"); }
From source file:fedora.server.storage.ConnectionPool.java
/** * <p>//w w w. j a v a 2 s .c om * Constructs a ConnectionPool based on the calling arguments. * </p> * * @param driver * The JDBC driver class name. * @param url * The JDBC connection URL. * @param username * The database user name. * @param password * The database password. * @param maxActive * Maximum number of active instances in pool. * @param maxIdle * Maximum number of idle instances in pool. * @param maxWait * Maximum amount of time in milliseconds the borrowObject() method * should wait when whenExhaustedAction is set to * WHEN_EXHAUSTED_BLOCK. * @param minIdle * Minimum of idle instances in pool. * @param minEvictableIdleTimeMillis * Minimum amount of time in milliseconds an object can be idle in * pool before eligible for eviction (if applicable). * @param numTestsPerEvictionRun * Number of objects to be examined on each run of idle evictor * thread (if applicable). * @param timeBetweenEvictionRunsMillis * Time in milliseconds to sleep between runs of the idle object * evictor thread. * @param validationQuery * Query to run when validation connections, e.g. SELECT 1. * @param testOnBorrow * When true objects are validated before borrowed from the pool. * @param testOnReturn * When true, objects are validated before returned to hte pool. * @param testWhileIdle * When true, objects are validated by the idle object evictor * thread. * @param whenExhaustedAction * Action to take when a new object is requested and the the pool has * reached maximum number of active objects. * @throws SQLException * If the connection pool cannot be established for any reason. */ public ConnectionPool(String driver, String url, String username, String password, int maxActive, int maxIdle, long maxWait, int minIdle, long minEvictableIdleTimeMillis, int numTestsPerEvictionRun, long timeBetweenEvictionRunsMillis, String validationQuery, boolean testOnBorrow, boolean testOnReturn, boolean testWhileIdle, byte whenExhaustedAction) throws SQLException { try { Class.forName(driver); } catch (ClassNotFoundException e) { throw new SQLException( "JDBC class not found: " + driver + "; make sure " + "the JDBC driver is in the classpath"); } // // http://jakarta.apache.org/commons/dbcp/configuration.html Properties props = new Properties(); props.setProperty("url", url); props.setProperty("username", username); props.setProperty("password", password); props.setProperty("maxActive", "" + maxActive); props.setProperty("maxIdle", "" + maxIdle); props.setProperty("maxWait", "" + maxWait); props.setProperty("minIdle", "" + minIdle); props.setProperty("minEvictableIdleTimeMillis", "" + minEvictableIdleTimeMillis); props.setProperty("numTestsPerEvictionRun", "" + numTestsPerEvictionRun); props.setProperty("timeBetweenEvictionRunsMillis", "" + timeBetweenEvictionRunsMillis); if (validationQuery != null && validationQuery.length() > 0) { props.setProperty("validationQuery", validationQuery); } props.setProperty("testOnBorrow", "" + testOnBorrow); props.setProperty("testOnReturn", "" + testOnReturn); props.setProperty("testWhileIdle", "" + testWhileIdle); if (whenExhaustedAction == 0) { // fail (don't wait, just fail) props.setProperty("maxWait", "0"); } else if (whenExhaustedAction == 1) { // block (wait indefinitely) props.setProperty("maxWait", "-1"); } else if (whenExhaustedAction == 2) { // grow (override the maxActive value with -1, unlimited) props.setProperty("maxActive", "-1"); } try { dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(props); dataSource.setDriverClassName(driver); } catch (Exception e) { SQLException se = new SQLException("Error initializing connection pool"); se.initCause(se); throw se; } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#validateUserAccount(java.lang.String, java.lang.String) *///from w ww. ja va2 s . com public synchronized boolean validateUserAccount(final String userId, final String userGuid) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#validateUserAccount(final String userId, final String userGuid) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", userGuid); } boolean isValid = false; Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{ CALL getUserByAttribute(?, ?) }"); stmt.setString(1, userId); stmt.setInt(2, 0); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.executeQuery(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); while (resultSet.next()) { if ((StringUtils.equals(resultSet.getString(1), userGuid)) || (StringUtils.equals(resultSet.getString(2), userId))) { resultSet.close(); stmt.close(); sqlConn.close(); throw new UserManagementException( "A user currently exists with the provided information."); } } } } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isValid; }
From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.PoolDataSource.java
@Override public void setLoginTimeout(final int seconds) throws SQLException { throw new SQLException("not allowed"); }
From source file:co.nubetech.apache.hadoop.OracleDBRecordReader.java
/** * Set session time zone/*from w ww .j a v a2s . c om*/ * * @param conf * The current configuration. We read the * 'oracle.sessionTimeZone' property from here. * @param conn * The connection to alter the timezone properties of. */ public static void setSessionTimeZone(Configuration conf, Connection conn) throws SQLException { // need to use reflection to call the method setSessionTimeZone on // the OracleConnection class because oracle specific java libraries are // not accessible in this context. Method method; try { method = conn.getClass().getMethod("setSessionTimeZone", new Class[] { String.class }); } catch (Exception ex) { LOG.error("Could not find method setSessionTimeZone in " + conn.getClass().getName(), ex); // rethrow SQLException throw new SQLException(ex); } // Need to set the time zone in order for Java // to correctly access the column "TIMESTAMP WITH LOCAL TIME ZONE". // We can't easily get the correct Oracle-specific timezone string // from Java; just let the user set the timezone in a property. String clientTimeZone = conf.get(SESSION_TIMEZONE_KEY, "GMT"); try { method.setAccessible(true); method.invoke(conn, clientTimeZone); LOG.info("Time zone has been set to " + clientTimeZone); } catch (Exception ex) { LOG.warn("Time zone " + clientTimeZone + " could not be set on Oracle database."); LOG.warn("Setting default time zone: GMT"); try { // "GMT" timezone is guaranteed to exist. method.invoke(conn, "GMT"); } catch (Exception ex2) { LOG.error("Could not set time zone for oracle connection", ex2); // rethrow SQLException throw new SQLException(ex); } } }
From source file:net.sf.jabb.util.db.ConnectionUtility.java
/** * ????//from w ww. j a va 2 s. co m * @param source * @return the database connection * @throws SQLException */ public static Connection getConnection(String source) throws SQLException { DataSource ds = getDataSource(source); if (ds == null) { throw new SQLException("ConnectionUtility cannot get data source: " + source); } return ds.getConnection(); }
From source file:io.cloudslang.content.database.utils.SQLUtilsTest.java
@Test public void testProcessDumpException() throws SQLException { SQLException sqlException = new SQLException("dump is complete") { @Override/*from w ww . j av a 2 s.c o m*/ public String getSQLState() { return SQL_STATE; } }; final String dumpException = SQLUtils.processDumpException(sqlException); assertEquals("dump is complete", dumpException); }