Example usage for java.sql SQLException SQLException

List of usage examples for java.sql SQLException SQLException

Introduction

In this page you can find the example usage for java.sql SQLException SQLException.

Prototype

public SQLException(Throwable cause) 

Source Link

Document

Constructs a SQLException object with a given cause.

Usage

From source file:com.eyeq.pivot4j.datasource.PooledOlapDataSource.java

/**
 * @see com.eyeq.pivot4j.datasource.CloseableDataSource#close()
 *//* ww w.  j a v  a2  s . c  o  m*/
@Override
public synchronized void close() throws SQLException {
    try {
        if (logger.isInfoEnabled()) {
            logger.info("Disposing the connection pool.");
        }

        this.getPool().close();
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException(e);
    }
}

From source file:com.wso2telco.core.dbutils.DbUtils.java

/**
 * IMPORTANT : This method must be deprecated. going forward use
 * "getDbConnection(DataSourceNames dataSourceName)" method Gets the * db connection.
 *
 * @return the db connection/*w w  w.ja  va  2  s.c  o  m*/
 * @throws SQLException
 *             the SQL exception
 * @throws DBUtilException
 *             the dbutilException exception
 */
public static Connection getDBConnection() throws SQLException, DBUtilException {
    initializeDatasources();

    if (Datasource != null) {
        return Datasource.getConnection();
    }
    throw new SQLException("Datasource not initialized properly");
}

From source file:com.aoindustries.website.signup.SignupCustomizeServerActionHelper.java

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SignupSelectPackageForm signupSelectPackageForm,
        SignupCustomizeServerForm signupCustomizeServerForm) throws IOException, SQLException {
    AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();
    PackageDefinition packageDefinition = rootConn.getPackageDefinitions()
            .get(signupSelectPackageForm.getPackageDefinition());
    if (packageDefinition == null)
        throw new SQLException(
                "Unable to find PackageDefinition: " + signupSelectPackageForm.getPackageDefinition());
    List<PackageDefinitionLimit> limits = packageDefinition.getLimits();

    // Find the cheapest resources to scale prices from
    int maxPowers = 0;
    PackageDefinitionLimit cheapestPower = null;
    int maxCPUs = 0;
    PackageDefinitionLimit cheapestCPU = null;
    int maxRAMs = 0;
    PackageDefinitionLimit cheapestRAM = null;
    int maxSataControllers = 0;
    PackageDefinitionLimit cheapestSataController = null;
    int maxScsiControllers = 0;
    PackageDefinitionLimit cheapestScsiController = null;
    int maxDisks = 0;
    PackageDefinitionLimit cheapestDisk = null;
    for (PackageDefinitionLimit limit : limits) {
        String resourceName = limit.getResource().getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                if (limitPower > maxPowers)
                    maxPowers = limitPower;
                if (cheapestPower == null)
                    cheapestPower = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestPower = limit;
                }//from w ww.  ja v  a2s.  c  om
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                if (limitCpu > maxCPUs)
                    maxCPUs = limitCpu;
                if (cheapestCPU == null)
                    cheapestCPU = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestCPU = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                if (limitRAM > maxRAMs)
                    maxRAMs = limitRAM;
                if (cheapestRAM == null)
                    cheapestRAM = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestRAM = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                if (limitSataController > maxSataControllers)
                    maxSataControllers = limitSataController;
                if (cheapestSataController == null)
                    cheapestSataController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestSataController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                if (limitScsiController > maxScsiControllers)
                    maxScsiControllers = limitScsiController;
                if (cheapestScsiController == null)
                    cheapestScsiController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestScsiController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int hardLimit = limit.getHardLimit();
            if (hardLimit > 0) {
                if (cheapestDisk == null)
                    cheapestDisk = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestDisk = limit;
                }
                if (hardLimit > maxDisks)
                    maxDisks = hardLimit;
            }
        }
    }
    if (cheapestCPU == null)
        throw new SQLException("Unable to find cheapestCPU");
    if (cheapestRAM == null)
        throw new SQLException("Unable to find cheapestRAM");
    if (cheapestDisk == null)
        throw new SQLException("Unable to find cheapestDisk");

    // Find all the options
    List<Option> powerOptions = new ArrayList<Option>();
    List<Option> cpuOptions = new ArrayList<Option>();
    List<Option> ramOptions = new ArrayList<Option>();
    List<Option> sataControllerOptions = new ArrayList<Option>();
    List<Option> scsiControllerOptions = new ArrayList<Option>();
    List<List<Option>> diskOptions = new ArrayList<List<Option>>();
    for (int c = 0; c < maxDisks; c++)
        diskOptions.add(new ArrayList<Option>());
    for (PackageDefinitionLimit limit : limits) {
        Resource resource = limit.getResource();
        String resourceName = resource.getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                assert cheapestPower != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxPowers == 1 ? resource.toString()
                        : (maxPowers + "x" + resource.toString());
                powerOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxPowers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxCPUs == 1 ? resource.toString() : (maxCPUs + "x" + resource.toString());
                cpuOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxCPUs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxRAMs == 1 ? resource.toString() : (maxRAMs + "x" + resource.toString());
                ramOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxRAMs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                assert cheapestSataController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxSataControllers == 1 ? resource.toString()
                        : (maxSataControllers + "x" + resource.toString());
                sataControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxSataControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                assert cheapestScsiController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxScsiControllers == 1 ? resource.toString()
                        : (maxScsiControllers + "x" + resource.toString());
                scsiControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxScsiControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int limitDisk = limit.getHardLimit();
            if (limitDisk > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal adjustedRate = additionalRate;
                // Discount adjusted rate if the cheapest disk is of this type
                if (cheapestDisk.getResource().getName().startsWith("hardware_disk_")) {
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    adjustedRate = adjustedRate.subtract(cheapestRate);
                }
                for (int c = 0; c < maxDisks; c++) {
                    List<Option> options = diskOptions.get(c);
                    // Add none option
                    if (maxDisks > 1 && options.isEmpty())
                        options.add(new Option(-1, "None",
                                c == 0 ? adjustedRate.subtract(additionalRate) : BigDecimal.valueOf(0, 2)));
                    options.add(new Option(limit.getPkey(), resource.toString(),
                            c == 0 ? adjustedRate : additionalRate));
                }
            }
        }
    }

    // Sort by price
    Collections.sort(powerOptions, new Option.PriceComparator());
    Collections.sort(cpuOptions, new Option.PriceComparator());
    Collections.sort(ramOptions, new Option.PriceComparator());
    Collections.sort(sataControllerOptions, new Option.PriceComparator());
    Collections.sort(scsiControllerOptions, new Option.PriceComparator());
    for (List<Option> diskOptionList : diskOptions)
        Collections.sort(diskOptionList, new Option.PriceComparator());

    // Clear any customization settings that are not part of the current package definition (this happens when they
    // select a different package type)
    if (signupCustomizeServerForm.getPowerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getPowerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setPowerOption(-1);
    }
    if (signupCustomizeServerForm.getCpuOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getCpuOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setCpuOption(-1);
    }
    if (signupCustomizeServerForm.getRamOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getRamOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setRamOption(-1);
    }
    if (signupCustomizeServerForm.getSataControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getSataControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setSataControllerOption(-1);
    }
    if (signupCustomizeServerForm.getScsiControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getScsiControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setScsiControllerOption(-1);
    }
    List<String> formDiskOptions = signupCustomizeServerForm.getDiskOptions();
    while (formDiskOptions.size() > maxDisks)
        formDiskOptions.remove(formDiskOptions.size() - 1);
    for (int c = 0; c < formDiskOptions.size(); c++) {
        String S = formDiskOptions.get(c);
        if (S != null && S.length() > 0 && !S.equals("-1")) {
            int pkey = Integer.parseInt(S);
            PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(pkey);
            if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
                formDiskOptions.set(c, "-1");
        }
    }

    // Determine if at least one disk is selected
    boolean isAtLeastOneDiskSelected = signupCustomizeServerForm.isAtLeastOneDiskSelected();

    // Default to cheapest if not already selected
    if (cheapestPower != null && signupCustomizeServerForm.getPowerOption() == -1)
        signupCustomizeServerForm.setPowerOption(cheapestPower.getPkey());
    if (signupCustomizeServerForm.getCpuOption() == -1)
        signupCustomizeServerForm.setCpuOption(cheapestCPU.getPkey());
    if (signupCustomizeServerForm.getRamOption() == -1)
        signupCustomizeServerForm.setRamOption(cheapestRAM.getPkey());
    if (cheapestSataController != null && signupCustomizeServerForm.getSataControllerOption() == -1)
        signupCustomizeServerForm.setSataControllerOption(cheapestSataController.getPkey());
    if (cheapestScsiController != null && signupCustomizeServerForm.getScsiControllerOption() == -1)
        signupCustomizeServerForm.setScsiControllerOption(cheapestScsiController.getPkey());
    for (int c = 0; c < maxDisks; c++) {
        List<Option> options = diskOptions.get(c);
        if (!options.isEmpty()) {
            Option firstOption = options.get(0);
            if (!isAtLeastOneDiskSelected && options.size() >= 2
                    && firstOption.getPriceDifference().compareTo(BigDecimal.ZERO) < 0) {
                firstOption = options.get(1);
            }
            String defaultSelected = Integer.toString(firstOption.getPackageDefinitionLimit());
            if (formDiskOptions.size() <= c || formDiskOptions.get(c) == null
                    || formDiskOptions.get(c).length() == 0 || formDiskOptions.get(c).equals("-1"))
                formDiskOptions.set(c, defaultSelected);
        } else {
            formDiskOptions.set(c, "-1");
        }
    }

    // Find the basePrice (base plus minimum number of cheapest of each resource class)
    BigDecimal basePrice = packageDefinition.getMonthlyRate();
    if (basePrice == null)
        basePrice = BigDecimal.valueOf(0, 2);
    if (cheapestPower != null && cheapestPower.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestPower.getAdditionalRate().multiply(BigDecimal.valueOf(maxPowers)));
    if (cheapestCPU.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestCPU.getAdditionalRate().multiply(BigDecimal.valueOf(maxCPUs)));
    if (cheapestRAM.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestRAM.getAdditionalRate());
    if (cheapestSataController != null && cheapestSataController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestSataController.getAdditionalRate());
    if (cheapestScsiController != null && cheapestScsiController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestScsiController.getAdditionalRate());
    if (cheapestDisk.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestDisk.getAdditionalRate());

    // Store to request
    request.setAttribute("packageDefinition", packageDefinition);
    request.setAttribute("powerOptions", powerOptions);
    request.setAttribute("cpuOptions", cpuOptions);
    request.setAttribute("ramOptions", ramOptions);
    request.setAttribute("sataControllerOptions", sataControllerOptions);
    request.setAttribute("scsiControllerOptions", scsiControllerOptions);
    request.setAttribute("diskOptions", diskOptions);
    request.setAttribute("basePrice", basePrice);
}

From source file:gridool.db.partitioning.monetdb.MonetDBCopyIntoOperation.java

@Override
public Serializable execute() throws SQLException {
    final Connection conn;
    try {//from ww w  .j av a2  s  . c om
        conn = getConnection();
    } catch (ClassNotFoundException e) {
        LOG.error(e);
        throw new SQLException(e.getMessage());
    }
    if (createTableDDL != null) {// prepare a table
        try {
            JDBCUtils.update(conn, createTableDDL);
        } catch (SQLException e) {
            conn.rollback();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Table already exists. Try to truncate " + tableName, e);
            }
            truncateTable(conn, tableName);
            // fall through
        }
    }

    final File loadFile = prepareLoadFile(tableName, rowsData);
    this.rowsData = null;
    final String query = complementCopyIntoQuery(copyIntoQuery, loadFile);
    try {
        JDBCUtils.update(conn, query);
        conn.commit();
    } catch (SQLException e) {
        LOG.error("rollback a transaction", e);
        conn.rollback();
        throw e;
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            LOG.debug(e);
        }
        if (!loadFile.delete()) {
            LOG.warn("Could not remove a tempolary file: " + loadFile.getAbsolutePath());
        }
    }

    return Boolean.TRUE;
}

From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IServerDataDAO#addServer(java.util.List)
 *///www  .  ja va2  s .c o m
public synchronized boolean addServer(final List<Object> serverData) throws SQLException {
    final String methodName = IServerDataDAO.CNAME
            + "#addServer(final List<Object> serverData) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);

        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 insertNewServer(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
        stmt.setString(1, (String) serverData.get(0)); // 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.aliyun.odps.jdbc.OdpsForwardResultSet.java

protected void checkClosed() throws SQLException {
    if (isClosed) {
        throw new SQLException("The result set has been closed");
    }/*from w  w w  .j  av a 2 s  .c om*/
}

From source file:h2o.common.util.dao.datasource.AbstractDataSource.java

@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException {
    Assert.notNull(iface, "Interface argument must not be null");
    if (!DataSource.class.equals(iface)) {
        throw new SQLException("DataSource of type [" + getClass().getName()
                + "] can only be unwrapped as [javax.sql.DataSource], not as [" + iface.getName());
    }/*from  w  ww . j a v  a 2s.c om*/
    return (T) this;
}

From source file:it.emacro.extractor.db.ConnectionPool.java

private void setupDataSource() throws SQLException {
    // String path = "WebContent/WEB-INF/config/database.properties";
    String path = it.emacro.services.ApplicationData.getInstance().getWebroot()
            + "WEB-INF/config/database.properties";
    // String path =
    // "D:\\workspace\\lotto\\WebContent\\WEB-INF\\config\\database.properties";
    // properties = PropertyLoader.getPropertiesOrEmpty(path);

    // path = "D:\\workspace\\lotto\\WebContent\\WEB-INF\\config\\database.properties";
    properties = PropertyLoader.getPropertiesOrEmpty(path);

    String driver = properties.getProperty(DRIVER);
    String url = properties.getProperty(URL);
    String username = properties.getProperty(USERNAME);
    String password = properties.getProperty(PASSWORD);
    // log.debug("Database username: " + username);
    // log.debug("Database password: " + password);
    // log.debug("Database driver: " + driver);
    // log.debug("Database url: " + url);

    try {/*from ww w  . j  a  v  a 2 s .c  om*/
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new SQLException("Can not load driver");
    }

    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setUrl(url);
}

From source file:it.larusba.neo4j.jdbc.http.HttpResultSet.java

/**
 * Check if this connection is closed or not.
 * If it's closed, then we throw a SQLException, otherwise we do nothing.
 *
 * @throws SQLException//from   w w w . j av a  2 s  .  c  o  m
 */
private void checkClosed() throws SQLException {
    if (isClosed()) {
        throw new SQLException("Connection is closed.");
    }
}

From source file:de.ufinke.cubaja.sql.ObjectFactoryGenerator.java

ObjectFactory getFactory(Class<?> dataClass, WarnMode warnMode) throws Exception {

    ObjectFactory factory = factoryMap.get(dataClass);
    if (factory != null) {
        return factory;
    }/*www  .ja  v  a  2s  .co m*/

    if (dataClass.isPrimitive()) {
        throw new SQLException(text.get("primitive"));
    }

    dataClassType = new Type(dataClass);

    builtin = null;
    if (singleColumnSqlType != 0) {
        TypeCombination combination = new TypeCombination(singleColumnSqlType, dataClass);
        builtin = ObjectFactoryType.getType(combination);
    }
    if (builtin == null) {
        createSetterMap(dataClass);
        checkSetterMap(dataClass, warnMode);
    }

    Class<?> factoryClass = Loader.createClass(this, "QueryObjectFactory", dataClass);
    factory = (ObjectFactory) factoryClass.newInstance();
    factoryMap.put(dataClass, factory);

    setterMap = null;

    return factory;
}