Example usage for java.sql SQLException getCause

List of usage examples for java.sql SQLException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest03() {
    final String sql = "SELECT COUNT(DISTINCT web100_log_entry.connection_spec.remote_ip) AS num_clients FROM [guid754187384106:m_lab.2010_01] "
            + "WHERE IS_EXPLICITLY_DEFINED(web100_log_entry.connection_spec.remote_ip) AND IS_EXPLICITLY_DEFINED(web100_log_entry.log_time) "
            + "AND web100_log_entry.log_time > 1262304000 AND web100_log_entry.log_time < 1262476800";
    final String description = "A sample query from google, but we don't have Access for the query table #ERROR #accessDenied #403";

    this.logger.info("Test number: 03");
    this.logger.info("Running query:" + sql);
    this.logger.debug(description);
    java.sql.ResultSet result = null;
    try {/*from ww  w . j  a v a2  s .  c  o m*/
        Statement stmt = con.createStatement();
        //stmt.setQueryTimeout(60);
        result = stmt.executeQuery(sql);
    } catch (SQLException e) {
        this.logger.debug("SQLexception" + e.toString());
        //fail("SQLException" + e.toString());
        Assert.assertTrue(e.getCause().toString()
                .contains("Access Denied: Table measurement-lab:m_lab.2010_01: QUERY_TABLE"));
    }
    logger.info("QueryResult03 result is" + result.toString());
}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public void updateQueryTable() {
    connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;/*  w ww  .  j av a 2  s.c o  m*/
    try {
        //connection.setAutoCommit(false);
        statement = connection.createStatement();
        //statement = connection.createStatement();

        String query = "INSERT INTO DM_TESTCASE(TESTCASE, TEMPLATE_GID, MODEL_GID) values ('" + TestCase
                + "',(select GID from DM_SCENARIO_REF where TEMPLATE_NAME='" + TemplateXMLName1[0]
                + "'),(select MODEL_GID_REF from DM_SCENARIO_REF where TEMPLATE_NAME ='" + TemplateXMLName1[0]
                + "'))";
        System.out.println(query);
        System.out.print("***Inserted the Records***");
        //prestatement = connection.prepareStatement(query);
        //prestatement.addBatch();
        statement.executeUpdate(query);
        if (prestatement != null) {
            prestatement.close();
        }
    } catch (SQLException e) {

        log.error("Exception Caught*******" + e.getCause());

    }

}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public void updateTemplateTable() {
    connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;//  w w  w.j  a va 2  s.  com
    try {
        statement = connection.createStatement();
        //statement = connection.createStatement();
        String query = "INSERT INTO DM_SCENARIO_REF(TEMPLATE_PATH, TEMPLATE_EXTENSION, TEMPLATE_NAME,MODEL_GID_REF) values ('"
                + TemplatePath + "','.xml','" + Template
                + "',(select GID from DM_MODELXML_REF where MODEL_NAME='" + ModelXMLName + "'))";
        System.out.println(query);
        System.out.print("***Inserted the Records***");
        //prestatement = connection.prepareStatement(query);
        statement.executeUpdate(query);
        if (prestatement != null) {
            prestatement.close();
        }
    } catch (SQLException e) {

        System.out.println("Exception Caught*******" + e.getCause());

    }

}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public String getModelgid() throws SQLException {
    //connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;/*from   w  ww.j  a v  a 2s .c  o m*/
    try {
        //connection.setAutoCommit(false);
        statement = connection.createStatement();
        //statement = connection.createStatement();

        String query = "select GID from DM_MODELXML_REF where MODEL_NAME='" + ModelXMLName + "'";
        log.info(query);

        //prestatement = connection.prepareStatement(query);
        //prestatement.addBatch();
        PreparedStatement pst = connection.prepareStatement(query);
        rs = pst.executeQuery();
        rs.next();
        modelgid = rs.getString("GID");
        log.info("***Get Model GID the Records***" + modelgid);
        //connection.commit();
        //            if (prestatement != null) {
        //                prestatement.close();
        //            }
        rs.close();
    } catch (SQLException e) {

        log.error("Exception Caught while query for model id*******" + e.getCause());

    }

    return modelgid;

}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public void updateModelStatus(int GID) {
    connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;//from  w w w.j a  v a 2 s.co m
    try {
        //connection.setAutoCommit(false);
        statement = connection.createStatement();
        //statement = connection.createStatement();

        String query = "update DM_MASTERMODELXML_REF set TESTCASE_GEN_STATUS='COMPLETED' where GID=" + GID;
        System.out.println(query);
        System.out.print("successfully updated the status in DM_MODELXML_REF table");
        statement.executeUpdate(query);
        if (prestatement != null) {
            prestatement.close();
        }
    } catch (SQLException e) {

        log.error("Exception Caught while updating status in DM_MODELXML_REF table" + e.getCause());

    }

}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public String getTemplategid() throws SQLException {
    //connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;// www .jav a2  s  .com
    try {
        //connection.setAutoCommit(false);
        statement = connection.createStatement();
        //statement = connection.createStatement();

        String query = "select GID from DM_SCENARIO_REF where TEMPLATE_NAME='" + TemplateXMLName1[0] + "'";
        log.info(query);

        //prestatement = connection.prepareStatement(query);
        //prestatement.addBatch();
        PreparedStatement pst = connection.prepareStatement(query);
        rs = pst.executeQuery();
        rs.next();
        templategid = rs.getString("GID");
        log.info("***Get Template GID the Records***" + templategid);
        //connection.commit();
        //            if (prestatement != null) {
        //                prestatement.close();
        //            }
        rs.close();
    } catch (SQLException e) {

        log.error("Exception Caught while querying for template ID*******" + e.getCause());

    }

    return templategid;

}

From source file:com.hp.test.framework.model.testcasegen.TestCaseGenerator.java

public String getModelgidtestcase() throws SQLException {
    //connection = ConnectDB.ConnectToolDB();

    ResultSet rs = null;//from   w  ww.  j  ava  2s  . c om
    try {
        //connection.setAutoCommit(false);
        statement = connection.createStatement();
        //statement = connection.createStatement();

        String query = "select MODEL_GID_REF from DM_SCENARIO_REF where TEMPLATE_NAME ='" + TemplateXMLName1[0]
                + "'";
        log.info(query);

        //prestatement = connection.prepareStatement(query);
        //prestatement.addBatch();
        PreparedStatement pst = connection.prepareStatement(query);
        rs = pst.executeQuery();
        rs.next();
        modelgidtestcase = rs.getString("MODEL_GID_REF");
        log.info("***Get Model GID for testcase***" + modelgidtestcase);
        //connection.commit();
        //            if (prestatement != null) {
        //                prestatement.close();
        //            }
        rs.close();
    } catch (SQLException e) {

        log.error("Exception Caught query for model id for test cases*******" + e.getCause());

    }

    return modelgidtestcase;

}

From source file:com.chiorichan.site.Site.java

private void finishLoad() throws SiteException, StartupException {
    // Framework site always uses the Builtin SQL Connector. Ignore YAML FileBase on this one.
    if (siteId.equalsIgnoreCase("framework")) {
        sql = Loader.getDatabase();//from   w w w.  ja va2 s  . c  om
    } else if (config != null && config.getConfigurationSection("database") != null) {
        String type = config.getString("database.type");

        String host = config.getString("database.host");
        String port = config.getString("database.port");
        String database = config.getString("database.database");
        String username = config.getString("database.username");
        String password = config.getString("database.password");

        String filename = config.getString("database.filename");

        sql = new DatabaseEngine();

        try {
            if (type.equalsIgnoreCase("mysql"))
                sql.init(database, username, password, host, port);
            else if (type.equalsIgnoreCase("sqlite"))
                sql.init(filename);
            else
                throw new SiteException("The SqlConnector for site '" + siteId
                        + "' can not support anything other then mySql or sqLite at the moment. Please change 'database.type' in the site config to 'mysql' or 'sqLite' and set the connection params.");
        } catch (SQLException e) {
            if (e.getCause() instanceof ConnectException)
                throw new SiteException("We had a problem connecting to database '" + database + "'. Reason: "
                        + e.getCause().getMessage());
            else
                throw new SiteException(e.getMessage());
        }
    }

    if (config != null) {
        List<String> onLoadScripts = config.getStringList("scripts.on-load");

        if (onLoadScripts != null) {
            for (String script : onLoadScripts) {
                try {
                    EvalMetaData meta = new EvalMetaData();
                    meta.shell = "groovy";

                    File file = getResourceWithException(script);
                    String result = factory.eval(file, meta, this).getString();

                    if (result == null || result.isEmpty())
                        Loader.getLogger().info(
                                "Finsihed evaling onLoadScript '" + script + "' for site '" + siteId + "'");
                    else
                        Loader.getLogger().info("Finsihed evaling onLoadScript '" + script + "' for site '"
                                + siteId + "' with result: " + result);
                } catch (EvalFactoryException e) {
                    SiteManager.getLogger()
                            .warning("There was an exception encountered while evaling onLoadScript '" + script
                                    + "' for site '" + siteId + "'.", e);
                } catch (FileNotFoundException e) {
                    SiteManager.getLogger().warning(
                            "The onLoadScript '" + script + "' was not found for site '" + siteId + "'.");
                }
            }
        }
    }

    SiteLoadEvent event = new SiteLoadEvent(this);

    try {
        Loader.getEventBus().callEventWithException(event);
    } catch (EventException e) {
        throw new SiteException(e);
    }

    // Plugins are not permitted to cancel the loading of the framework site
    if (event.isCancelled() && !siteId.equalsIgnoreCase("framework"))
        throw new SiteException("Loading of site '" + siteId + "' was cancelled by an internal event.");

    if (new File(getAbsoluteRoot(), "fw").exists() && !siteId.equalsIgnoreCase("framework"))
        SiteManager.getLogger().warning("It would appear that site '" + siteId
                + "' contains a subfolder by the name of 'fw', since this server uses the uri '/fw' for special functions, you will be unable to serve files from this folder!");
}

From source file:org.apache.eagle.alert.metadata.impl.JdbcMetadataHandler.java

private void closeResource(ResultSet rs, PreparedStatement statement, Connection connection) {
    if (rs != null) {
        try {//from   w  w  w . j a v  a2s.c  o  m
            rs.close();
        } catch (SQLException e) {
            LOG.info(e.getMessage(), e);
        }
    }
    if (statement != null) {
        try {
            statement.close();
        } catch (SQLException e) {
            LOG.info("Failed to close statement: {}", e.getMessage(), e);
        }
    }
    if (connection != null) {
        try {
            connection.close();
        } catch (SQLException e) {
            LOG.error("Failed to close connection: {}", e.getMessage(), e.getCause());
        }
    }
}

From source file:org.metis.push.PusherBean.java

/**
 * Called by Spring after all of this bean's properties have been set.
 *///  ww w .ja  va  2  s  .  c  om
public void afterPropertiesSet() throws Exception {

    // create the session registry
    setWdsSessions(new Hashtable<String, WdsSocketSession>(getInitCapacity()));

    // log info for the jdbc driver being used
    // this will also attempt to open connection
    // with jdbc driver
    try {
        Connection con = getDataSource().getConnection();
        if (con != null) {
            DatabaseMetaData dbmd = con.getMetaData();
            setDbConnectionAcquired(true);
            if (dbmd != null) {
                setDriverName(dbmd.getDriverName().trim().toLowerCase());
                // record the URL to the DB
                setDbUrl(dbmd.getURL().trim());
                isOracle = (getDriverName() != null && getDriverName().indexOf(ORACLE_STR) >= 0) ? true : false;
                LOG.info(getBeanName() + ":Is Oracle JDBC Driver = " + isOracle);
                LOG.info(getBeanName() + ":JDBC Driver name = " + getDriverName());
                LOG.info(getBeanName() + ":JDBC Driver version = " + dbmd.getDriverVersion().trim());
                LOG.info(getBeanName() + ":JDBC Driver product name = " + dbmd.getDatabaseProductName().trim());
                LOG.info(getBeanName() + ":JDBC URL = " + getDbUrl());
                LOG.info(getBeanName() + ":JDBC Driver database product version = "
                        + dbmd.getDatabaseProductVersion().trim());
                con.close();
            } else {
                LOG.info(getBeanName() + ": Unable to get JDBC driver meta data");
            }
        } else {
            LOG.info(getBeanName() + ": Unable to get JDBC connection");
        }
    } catch (SQLException exc) {
        LOG.error(getBeanName() + ": got this exception when trying to " + "get driver meta data: "
                + exc.toString());
        LOG.error(getBeanName() + ": exception stack trace follows:");
        dumpStackTrace(exc.getStackTrace());
        LOG.error(getBeanName() + ": Caused by " + exc.getCause().toString());
        LOG.error(getBeanName() + ": causing exception stack trace follows:");
        dumpStackTrace(exc.getCause().getStackTrace());
    }

    // bean must be assigned a JDBC DataSource
    if (getDataSource() == null) {
        throw new Exception(
                getBeanName() + ".afterPropertiesSet: this bean has not been " + "assigned a JDBC DataSource");
    }

    // do some validation
    if (getSqls4Get() == null) {
        throw new Exception("The PusherBean must be assigned at least one SQL statement");
    }

    // create and validate the injected SQL statements

    sqlStmnts4Get = new ArrayList<SqlStmnt>();
    for (String sql : getSqls4Get()) {
        // get the frequency settings
        Map<String, Long> map = Utils.parseTimeInterval(sql);
        sql = Utils.stripTimeInterval(sql);
        sql = Utils.stripCall(sql);
        SqlStmnt stmt = getSQLStmnt(this, sql, getJdbcTemplate());

        if (stmt.isEqual(sqlStmnts4Get)) {
            throw new Exception("Injected SQL statements for GET are not distinct");
        }
        // set the frequency
        stmt.setIntervalTime(map.get(TIME_INTERVAL));
        if (map.get(TIME_INTERVAL_MAX) != null) {
            stmt.setIntervalMax(map.get(TIME_INTERVAL_MAX));
        }
        if (map.get(TIME_INTERVAL_STEP) != null) {
            stmt.setIntervalStep(map.get(TIME_INTERVAL_STEP));
        }
        sqlStmnts4Get.add(stmt);
    }
    if (LOG.isDebugEnabled()) {
        for (SqlStmnt sqlstmnt : sqlStmnts4Get) {
            LOG.debug(getBeanName() + ": SQL for GET = " + sqlstmnt.getOriginal());
            LOG.debug(getBeanName() + ": Parameterized SQL for GET = " + sqlstmnt.getPrepared());
        }
    }

    if (getHazelcastInstance() != null) {
        LOG.debug(getBeanName() + ": My Hazelcast Instance Name = " + getHazelcastInstance().getName());
        ;
    }
}