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:net.ageto.gyrex.persistence.jdbc.pool.internal.PoolDataSourceFactory.java

@Override
public XADataSource createXADataSource(final Properties props) throws SQLException {
    throw new SQLException("not allowed");
}

From source file:com.sf.ddao.factory.param.DefaultParameter.java

public Object extractParam(Context context) throws SQLException {
    final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class);
    Object[] args = callCtx.getArgs();
    Object param;/*www . j  av a  2 s .  c  o m*/
    if (num != null) {
        if (num == RETURN_ARG_IDX) {
            param = callCtx.getLastReturn();
        } else {
            if (args.length <= num) {
                throw new SQLException("Query refers to argument #" + num + ", while method has only "
                        + args.length + " arguments");
            }
            param = args[num];
        }
    } else {
        param = args[0];
    }
    if (propName == null) {
        return param;
    }
    if (param instanceof Map) {
        return ((Map) param).get(propName);
    }
    try {
        return PropertyUtils.getProperty(param, propName);
    } catch (Exception e) {
        throw new SQLException("Failed to get statement parameter " + name + " from " + param, e);
    }
}

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

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SignupSelectPackageForm signupSelectPackageForm,
        SignupCustomizeServerForm signupCustomizeServerForm,
        SignupCustomizeManagementForm signupCustomizeManagementForm) 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();

    // Get the total harddrive space in gigabytes
    int totalHardwareDiskSpace = SignupCustomizeServerActionHelper.getTotalHardwareDiskSpace(rootConn,
            signupCustomizeServerForm);/*from  ww  w.  j  a  va 2s  .  co m*/

    // Find all the options
    List<Option> backupOnsiteOptions = new ArrayList<Option>();
    List<Option> backupOffsiteOptions = new ArrayList<Option>();
    List<Option> distributionScanOptions = new ArrayList<Option>();
    List<Option> failoverOptions = new ArrayList<Option>();
    for (PackageDefinitionLimit limit : limits) {
        Resource resource = limit.getResource();
        String resourceName = resource.getName();
        if (resourceName.startsWith("backup_onsite_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower == PackageDefinitionLimit.UNLIMITED || limitPower > 0) {
                // This is per gigabyte of physical space
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                backupOnsiteOptions.add(new Option(limit.getPkey(), resource.toString(),
                        additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace))));
            }
        } else if (resourceName.startsWith("backup_offsite_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower == PackageDefinitionLimit.UNLIMITED || limitPower > 0) {
                // This is per gigabyte of physical space
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                backupOffsiteOptions.add(new Option(limit.getPkey(), resource.toString(),
                        additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace))));
            }
        }
    }
    // Distribution scan option
    {
        Resource resource = rootConn.getResources().get(Resource.DISTRIBUTION_SCAN);
        if (resource == null) {
            servletContext.log(null,
                    new SQLException("Unable to find Resource: " + Resource.DISTRIBUTION_SCAN));
        } else {
            PackageDefinitionLimit limit = packageDefinition.getLimit(resource);
            if (limit != null) {
                int hard = limit.getHardLimit();
                if (hard == PackageDefinitionLimit.UNLIMITED || hard > 0) {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    distributionScanOptions
                            .add(new Option(limit.getPkey(), resource.toString(), additionalRate));
                }
            }
        }
    }
    // Failover option
    {
        Resource resource = rootConn.getResources().get(Resource.FAILOVER);
        if (resource == null) {
            servletContext.log(null, new SQLException("Unable to find Resource: " + Resource.FAILOVER));
        } else {
            PackageDefinitionLimit limit = packageDefinition.getLimit(resource);
            if (limit != null) {
                int hard = limit.getHardLimit();
                if (hard == PackageDefinitionLimit.UNLIMITED || hard > 0) {
                    // This is per gigabyte of physical space
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    additionalRate = additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace));
                    failoverOptions.add(new Option(limit.getPkey(), resource.toString(), additionalRate));

                    // Only once the failover option is available will the MySQL replication option be available
                    Resource mrResource = rootConn.getResources().get(Resource.MYSQL_REPLICATION);
                    if (mrResource == null) {
                        servletContext.log(null,
                                new SQLException("Unable to find Resource: " + Resource.MYSQL_REPLICATION));
                    } else {
                        PackageDefinitionLimit mrLimit = packageDefinition.getLimit(mrResource);
                        if (mrLimit != null) {
                            int mrHard = mrLimit.getHardLimit();
                            if (mrHard == PackageDefinitionLimit.UNLIMITED || mrHard > 0) {
                                BigDecimal mrAdditionalRate = mrLimit.getAdditionalRate();
                                if (mrAdditionalRate == null)
                                    mrAdditionalRate = BigDecimal.valueOf(0, 2);
                                failoverOptions.add(new Option(mrLimit.getPkey(), mrResource.toString(),
                                        additionalRate.add(mrAdditionalRate)));
                            }
                        }
                    }
                }
            }
        }
    }

    if (!backupOnsiteOptions.isEmpty())
        backupOnsiteOptions.add(0, new Option(-1, "No On-Site Backup", BigDecimal.valueOf(0, 2)));
    if (!backupOffsiteOptions.isEmpty())
        backupOffsiteOptions.add(0, new Option(-1, "No Off-Site Backup", BigDecimal.valueOf(0, 2)));
    if (!distributionScanOptions.isEmpty())
        distributionScanOptions.add(0, new Option(-1, "No daily scans", BigDecimal.valueOf(0, 2)));
    if (!failoverOptions.isEmpty())
        failoverOptions.add(0, new Option(-1, "No Fail-Over Mirror", BigDecimal.valueOf(0, 2)));

    // Sort by price
    Collections.sort(backupOnsiteOptions, new Option.PriceComparator());
    Collections.sort(backupOffsiteOptions, new Option.PriceComparator());
    Collections.sort(distributionScanOptions, new Option.PriceComparator());
    Collections.sort(failoverOptions, 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 (signupCustomizeManagementForm.getBackupOnsiteOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getBackupOnsiteOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setBackupOnsiteOption(-1);
    }
    if (signupCustomizeManagementForm.getBackupOffsiteOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getBackupOffsiteOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setBackupOffsiteOption(-1);
    }
    if (signupCustomizeManagementForm.getDistributionScanOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getDistributionScanOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setDistributionScanOption(-1);
    }
    if (signupCustomizeManagementForm.getFailoverOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getFailoverOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setFailoverOption(-1);
    }

    // Store to request
    request.setAttribute("packageDefinition", packageDefinition);
    request.setAttribute("hardwareRate", SignupCustomizeServerActionHelper.getHardwareMonthlyRate(rootConn,
            signupCustomizeServerForm, packageDefinition));
    request.setAttribute("backupOnsiteOptions", backupOnsiteOptions);
    request.setAttribute("backupOffsiteOptions", backupOffsiteOptions);
    request.setAttribute("distributionScanOptions", distributionScanOptions);
    request.setAttribute("failoverOptions", failoverOptions);
}

From source file:com.ea.core.orm.handle.impl.MybatisSqlORMHandle.java

@Override
protected Object execute(ORMParamsDTO dto) throws Exception {
    // TODO Auto-generated method stub
    Connection connection = this.getMybatisSessionTemplate().getConnection();
    final ORMParamsDTO tmp = dto;
    PreparedStatement ps = connection.prepareStatement(tmp.getSqlid());
    if (tmp.getParam() != null) {
        Object data = tmp.getParam();
        if (data instanceof Object[]) {
            Object[] array = (Object[]) data;
            int index = 1;
            for (Object obj : array) {
                setParam(ps, index++, obj);
            }/*from   www  .ja  v  a 2s.c o m*/
        } else if (data instanceof Collection) {
            for (Object array : (Collection) data) {
                if (array instanceof Object[]) {
                    int index = 1;
                    for (Object obj : (Object[]) array) {
                        setParam(ps, index++, obj);
                    }
                    ps.addBatch();
                } else {
                    throw new SQLException("SQLDB?Object[]???!");
                }

            }
        } else {
            throw new SQLException(
                    "SQLDB?Object[]Collection???!");
        }
    }
    return ps.executeQuery();
}

From source file:com.flipkart.flux.type.SetJsonType.java

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    try {/*from   w  ww  . j ava 2  s  .c o m*/
        st.setString(index, serialize(value));
    } catch (JsonProcessingException e) {
        throw new SQLException("Cannot serialize object to JSON. Exception " + e.getMessage());
    }
}

From source file:com.nabla.wapp.server.database.CommonConnectionPool.java

/**
 * Constructor/*from  w w  w  . ja  v a  2 s .  c o m*/
 * @param dbName         - database name as defined in pool
 * @param serverContext      - web app context
 * @throws SQLException 
 */
public CommonConnectionPool(final String dbName, final ServletContext serverContext) throws SQLException {
    Assert.argumentNotNull(dbName, "Have you set the database name in your web.xml file?");
    Assert.argumentNotNull(serverContext);

    url = "jdbc:apache:commons:dbcp:/" + dbName;
    if (!isLoaded(dbName)) {
        load(dbName);
        final String driverName = serverContext.getInitParameter(DATABASE_DRIVER_NAME);
        Assert.notNull(driverName, "Have you set the database driver name in your web.xml file?");
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            if (log.isDebugEnabled())
                log.debug("fail to find database driver class '" + driverName + "'", e);
            throw new SQLException("fail to find database driver class '" + driverName + "'");
        }
    }
}

From source file:org.exitcode.spring.torque.TorqueDelegatingDataSource.java

@Override
public Connection getConnection() throws SQLException {
    LOG.debug("getConnection(), db: " + databaseName);
    try {/*ww w  . j a  v  a2s .c  om*/
        return Torque.getConnection(databaseName);
    } catch (TorqueException e) {
        throw new SQLException(e);
    }
}

From source file:com.adaptris.jdbc.connection.FailoverConnection.java

public FailoverConnection(FailoverConfig config) throws SQLException {
    this();// w w w .  j  a v  a 2 s. c  om
    setConfig(config);
    currentIndex = START_OF_LIST;
    if (config.getConnectionUrls().size() < 1) {
        throw new SQLException("No Configured URL list for connections");
    }
    initialiseDriver();
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.SQLDataSourceWrapper.java

public <T> T unwrap(Class<T> iface) throws SQLException {
    try {/*  w ww.ja  v a 2s .  c o  m*/
        return (T) invokeMethod(basicDataSource, "unwrap", iface);
    } catch (Exception ex) {
        throw new SQLException(ex);
    }
}

From source file:com.healthmarketscience.jackcess.DataTypes.java

public static byte fromSQLType(int sqlType) throws SQLException {
    Byte b = (Byte) SQL_TYPES.getKey(new Integer(sqlType));
    if (b != null) {
        return b.byteValue();
    } else {/*  w  ww. ja  v  a  2 s . c  o  m*/
        throw new SQLException("Unsupported SQL type: " + sqlType);
    }
}