List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IServerDataDAO#updateServer(java.lang.String, java.util.List) *///from ww w.java 2s. co m public synchronized boolean updateServer(final String serverGuid, final List<Object> serverData) throws SQLException { final String methodName = IServerDataDAO.CNAME + "#updateServer(final String serverGuid, final List<Object> serverData) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", serverGuid); for (Object str : serverData) { DEBUGGER.debug("Value: {}", str); } } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall( "{CALL updateServerData(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"); stmt.setString(1, serverGuid); // systemGuid stmt.setString(2, (String) serverData.get(1)); // systemOs stmt.setString(3, (String) serverData.get(2)); // systemStatus stmt.setString(4, (String) serverData.get(3)); // systemRegion stmt.setString(5, (String) serverData.get(4)); // networkPartiton stmt.setString(6, (String) serverData.get(5)); // datacenter stmt.setString(7, (String) serverData.get(6)); // systemType stmt.setString(8, (String) serverData.get(7)); // domainName stmt.setString(9, (String) serverData.get(8)); // cpuType stmt.setInt(10, (Integer) serverData.get(9)); // cpuCount stmt.setString(11, (String) serverData.get(10)); // serverModel stmt.setString(12, (String) serverData.get(11)); // serialNumber stmt.setInt(13, (Integer) serverData.get(12)); // installedMemory stmt.setString(14, (String) serverData.get(13)); // operIp stmt.setString(15, (String) serverData.get(14)); // operHostname stmt.setString(16, (String) serverData.get(15)); // mgmtIp stmt.setString(17, (String) serverData.get(16)); // mgmtHostname stmt.setString(18, (String) serverData.get(17)); // backupIp stmt.setString(19, (String) serverData.get(18)); // backupHostname stmt.setString(20, (String) serverData.get(19)); // nasIp stmt.setString(21, (String) serverData.get(20)); // nasHostname stmt.setString(22, (String) serverData.get(21)); // natAddr stmt.setString(23, (String) serverData.get(22)); // systemComments stmt.setString(24, (String) serverData.get(23)); // engineer stmt.setString(25, (String) serverData.get(24)); // mgrEntry stmt.setInt(26, (Integer) serverData.get(25)); // dmgrPort stmt.setString(27, (String) serverData.get(26)); // serverRack stmt.setString(28, (String) serverData.get(27)); // rackPosition stmt.setString(29, (String) serverData.get(28)); // owningDmgr if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } isComplete = (!(stmt.execute())); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return isComplete; }
From source file:com.dynamobi.ws.util.ConnectionManager.java
/** * Used by the caller to signal that they are done with the connection * and allow other tasks to use it.// w w w .jav a 2 s .c o m * @param auth - the caller's Spring authentication. * @param c - the connection to release */ public static void release_connection(Authentication auth, Connection c) throws SQLException { String[] parts = auth.getCredentials().toString().split(":", 2); if (parts.length < 1) { throw new SQLException("SEVERE: Authentication changed."); } String uuid = parts[0]; if (!conns.containsKey(uuid)) { throw new SQLException("SEVERE: Missing ConnectionInfo object for UUID " + uuid); } ConnectionInfo info = conns.get(uuid); info.busy = false; info.update_time(); }
From source file:com.flexive.core.Database.java
/** * Retrieves a DataSource./* w w w. ja va 2 s . c o m*/ * * @param divisionId the division id * @param useTX request transaction support? * @return a DataSource * @throws SQLException If no DataSource could be retrieved */ private static DataSource getDataSource(int divisionId, boolean useTX) throws SQLException { // Check division if (!DivisionData.isValidDivisionId(divisionId)) { throw new SQLException("Unable to obtain connection: Division not defined (" + divisionId + ")."); } DataSource[] dataSourceCache = useTX ? dataSources : dataSourcesNoTX; // use cached datasource, if available if (divisionId == DivisionData.DIVISION_TEST && useTX && testDataSource != null) { return testDataSource; } else if (divisionId == DivisionData.DIVISION_TEST && !useTX && testDataSourceNoTX != null) { return testDataSourceNoTX; } else if (divisionId != DivisionData.DIVISION_TEST && dataSourceCache[divisionId] != null) { return dataSourceCache[divisionId]; } synchronized (Database.class) { // Try to obtain a connection String finalDsName = null; try { if (divisionId == DivisionData.DIVISION_GLOBAL) { // Special case: global config database finalDsName = DS_GLOBAL_CONFIG; } else { // else: get data source from global configuration GlobalConfigurationEngine globalConfiguration = EJBLookup.getGlobalConfigurationEngine(); finalDsName = globalConfiguration.getDivisionData(divisionId).getDataSource(); if (!useTX) finalDsName += NO_TX_SUFFIX; } LOG.info("Looking up datasource for division " + divisionId + ": " + finalDsName); final DataSource dataSource = getDataSource(finalDsName, false); if (divisionId == DivisionData.DIVISION_TEST) { if (useTX) { return (testDataSource = dataSource); } else { return (testDataSourceNoTX = dataSource); } } else { return (dataSourceCache[divisionId] = dataSource); } } catch (NamingException exc) { if (divisionId == 1) { // try default JavaEE 6 data source try { final DataSource ds = tryGetDefaultDataSource(EJBLookup.getInitialContext(), GlobalConfigurationEngineBean.DEFAULT_DS + (useTX ? "" : NO_TX_SUFFIX), new DefaultDivisionDataSourceInitializer()); if (ds != null) { if (LOG.isInfoEnabled()) { LOG.info("No datasource configured for division 1, using default datasource: " + GlobalConfigurationEngineBean.DEFAULT_DS); } // remember data source for #getDataSource(String) dataSourcesByName.put(finalDsName, ds); defaultDataSourceInitialized = true; // remember to unload driver in cleanup // set division data source, return return (dataSourceCache[divisionId] = ds); } else { if (LOG.isErrorEnabled()) { LOG.error( "Default datasource for division 1 not found (not a JavaEE 6 container?)"); } // fall through to error handling } } catch (NamingException e) { // not bound, throw error } } String sErr = "Naming Exception, unable to retrieve Connection to [" + finalDsName + "]: " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } catch (FxNotFoundException exc) { String sErr = "Failed to retrieve datasource for division " + divisionId + " (not configured)."; LOG.error(sErr); throw new SQLException(sErr); } catch (FxLoadException exc) { String sErr = "Failed to load datasource configuration: " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } catch (FxApplicationException exc) { String sErr = "Unknown error while loading datasource for division " + divisionId + ": " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } } }
From source file:com.bc.fiduceo.db.AbstractDriver.java
Sensor getSensor(int id) throws SQLException { final Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); final ResultSet resultSet = statement.executeQuery("SELECT * FROM SENSOR where ID = " + id); if (resultSet.next()) { final Sensor sensor = new Sensor(); sensor.setName(resultSet.getString("Name")); return sensor; } else {// ww w . jav a 2 s. c o m throw new SQLException("No Sensor available for ID '" + id + "'"); } }
From source file:jp.primecloud.auto.tool.management.db.SQLExecuter.java
public int getGroupid(String sql) throws SQLException, Exception { Connection con = null;/* w w w.ja v a 2 s . co m*/ Statement stmt = null; ResultSet rs = null; int groupid = 0; log.info("[" + sql + "] ???"); try { con = dbConnector.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { groupid = rs.getInt("groupid"); } log.info("[" + sql + "] ????"); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SQLException(e); } catch (Exception e) { log.error(e.getMessage(), e); throw new Exception(e); } finally { try { dbConnector.closeConnection(con, stmt, rs); } catch (Exception e) { e.printStackTrace(); } } return groupid; }
From source file:com.tesora.dve.dbc.ServerDBConnection.java
public NativeType findType(String nativeTypeName) throws SQLException { try {//from w w w . ja v a 2s .com return populateDBMetadata().findType(nativeTypeName); } catch (PEException e) { throw new SQLException(e); } }
From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java
public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { throw new SQLException( "Unsupported TDDatabaseMetaData#getColumnPrivileges(String, String, String, String)"); }
From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java
/** * Parses a GeoJSON 1.0 file and writes it to a table. * * A GeoJSON file is structured as follows: * * { "type": "FeatureCollection", "features": [ { "type": "Feature", * "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": * {"prop0": "value0"} }, { "type": "Feature", "geometry": { "type": * "LineString", "coordinates": [ [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], * [105.0, 1.0] ] }, "properties": { "prop0": "value0", "prop1": 0.0 } }, * {"type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ * [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] * ]}, "properties": { "prop0": "value0", "prop1": {"this": "that"} } } ] } * * Note: To include information on the coordinate range for geometries, a * GeoJSON object may have a member named "bbox". * * Syntax:/*from w ww.ja va 2 s . co m*/ * * { "type": "FeatureCollection", "bbox": [100.0, 0.0, 105.0, 1.0], * "features": [ ... ] } * * * @param progress */ private void parseGeoJson(ProgressVisitor progress) throws SQLException, IOException { this.progress = progress.subProcess(100); init(); if (parseMetadata()) { GF = new GeometryFactory(new PrecisionModel(), parsedSRID); parseData(); setSRIDConstraint(); } else { throw new SQLException("Cannot create the table " + tableLocation + " to import the GeoJSON data"); } }
From source file:org.jfree.data.jdbc.JDBCPieDataset.java
/** * ExecuteQuery will attempt execute the query passed to it against the * existing database connection. If no connection exists then no action * is taken.// ww w .ja va 2s.c o m * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed * @param con the connection the query is to be executed against * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { Statement statement = null; ResultSet resultSet = null; try { statement = con.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != 2) { throw new SQLException("Invalid sql generated. PieDataSet requires 2 columns only"); } int columnType = metaData.getColumnType(2); double value = Double.NaN; while (resultSet.next()) { Comparable key = resultSet.getString(1); switch (columnType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: value = resultSet.getDouble(2); setValue(key, value); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Timestamp date = resultSet.getTimestamp(2); value = date.getTime(); setValue(key, value); break; default: System.err.println("JDBCPieDataset - unknown data type"); break; } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } if (statement != null) { try { statement.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } } }
From source file:com.netspective.axiom.schema.constraint.BasicForeignKey.java
public Row getFirstReferencedRow(ConnectionContext cc, ColumnValue value) throws NamingException, SQLException { Column refColumn = getReferencedColumns().getSole(); Table refTable = refColumn.getTable(); QueryDefnSelect accessor = refColumn.getTable().getAccessorByColumnEquality(refColumn); if (accessor == null) throw new SQLException("Unable to accessor for selecting reference column " + refColumn); Object bindValue = value.getValueForSqlBindParam(); if (bindValue == null) throw new SQLException("No bind value provided for reference column " + refColumn); Row resultRow = null;/* w ww .j a va2 s. c o m*/ QueryResultSet qrs = accessor.execute(cc, new Object[] { bindValue }, false); if (qrs != null) { ResultSet rs = qrs.getResultSet(); if (rs.next()) { resultRow = refTable.createRow(); resultRow.getColumnValues().populateValues(rs, ColumnValues.RESULTSETROWNUM_SINGLEROW); } } qrs.close(false); return resultRow; }