Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:io.github.retz.scheduler.RetzScheduler.java

void failed(Protos.TaskStatus status) {
    Optional<String> maybeUrl = MesosHTTPFetcher.sandboxBaseUri(conf.getMesosMaster(),
            status.getSlaveId().getValue(), frameworkInfo.getId().getValue(),
            status.getExecutorId().getValue());
    try {// w w w.j  a v a  2  s  .  co m
        JobQueue.failed(status.getTaskId().getValue(), maybeUrl, status.getMessage());
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
    } catch (JobNotFoundException e) {
        LOG.warn(e.toString(), e);
        // TODO: re-insert the failed job again?
    }
}

From source file:io.github.retz.scheduler.RetzScheduler.java

void retry(Protos.TaskStatus status) {
    String reason = "";
    if (status.hasMessage()) {
        reason = status.getMessage();/*w  w  w .j av a2  s . co  m*/
    }
    try {
        JobQueue.retry(status.getTaskId().getValue(), reason);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
    } catch (JobNotFoundException e) {
        LOG.warn(e.toString(), e);
        // TODO: re-insert the failed job again?
    }
}

From source file:io.github.retz.scheduler.RetzScheduler.java

void started(Protos.TaskStatus status) {
    Optional<String> maybeUrl = MesosHTTPFetcher.sandboxBaseUri(conf.getMesosMaster(),
            status.getSlaveId().getValue(), frameworkInfo.getId().getValue(),
            status.getExecutorId().getValue());
    try {/*from  www  . ja  va  2 s  .c  o m*/
        JobQueue.started(status.getTaskId().getValue(), maybeUrl);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
    } catch (JobNotFoundException e) {
        LOG.warn(e.toString(), e);
        // TODO: re-insert the failed job again?
    } catch (IOException e) {
        LOG.error(e.toString(), e);
    }
}

From source file:com.freedomotic.plugins.devices.harvester_chart.HarvesterChart.java

@ListenEventsOn(channel = "app.event.sensor.object.behavior.clicked")
public void onObjectClicked(EventTemplate event) {
    List<String> behavior_list = new ArrayList<String>();
    System.out.println("received event " + event.toString());
    ObjectReceiveClick clickEvent = (ObjectReceiveClick) event;
    //PRINT EVENT CONTENT WITH
    System.out.println(clickEvent.getPayload().toString());
    String objectName = clickEvent.getProperty("object.name");
    String protocol = clickEvent.getProperty("object.protocol");
    String address = clickEvent.getProperty("object.address");

    try {/* w  w  w .  j a  v  a2s  . c  om*/
        Statement stat = connection.createStatement();
        System.out.println("Protocol=" + protocol + ",Address=" + address);

        //for (EnvObjectLogic object : EnvObjectPersistence.getObjectByProtocol("wifi_id")){
        //EnvObjectLogic object = EnvObjectPersistence.getObjectByName(objectName);

        for (EnvObjectLogic object : EnvObjectPersistence.getObjectByAddress(protocol, address)) {
            for (BehaviorLogic behavior : object.getBehaviors()) {
                System.out.println(behavior.getName());
            }
        }

        //String query = "select date,value from events where protocol='"+clickEvent.getProperty("object.protocol")+"' and behavior='power' ORDER BY ID DESC LIMIT 1000;";
        String query = "select date,value from events where object='" + objectName
                + "' and behavior='power' ORDER BY ID DESC LIMIT 1000;";
        System.out.println(query);
        //String query = "select datetime(date, 'unixepoch', 'localtime') as TIME,value from events where protocol='remote_receiver' and behavior='button'";

        ResultSet rs = stat.executeQuery(query);
        //JFreeChart chart = ChartFactory.createLineChart("Test", "Id", "Score", dataset, PlotOrientation.VERTICAL, true, true, false); 

        //System.out.println("Wilson Kong Debug:"+rs.getLong("date"));
        final TimeSeries series = new TimeSeries("Data1", Millisecond.class);

        while (rs.next()) {
            Date resultdate = new Date(rs.getLong("date") * 1000);
            Millisecond ms_read = new Millisecond(resultdate);
            series.addOrUpdate(ms_read, rs.getDouble("value"));
            //series.add((Millisecond)rs.getLong("date"),(double)rs.getLong("value"));
        }
        XYDataset xyDataset = new TimeSeriesCollection(series);

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALVE", xyDataset, true, // legend
                true, // tooltips
                false // urls
        );
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
        JFrame f = new JFrame("Chart");
        f.setContentPane(chartPanel);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.pack();
        f.setVisible(true);
        //if (...) {
        //MyFrame myFrame = new MyFrame();
        //bindGuiToPlugin(myFrame);
        //showGui(); //triggers the showing of your frame. Before it calls onShowGui()
        //}
    } catch (SQLException ex) {
        Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
        System.out.println("Wilson Kong Error: " + ex.toString());
        //ex.printStackTrace();
        stop();
    }
}

From source file:io.github.retz.scheduler.RetzScheduler.java

void finished(Protos.TaskStatus status) {
    Optional<String> maybeUrl = MesosHTTPFetcher.sandboxBaseUri(conf.getMesosMaster(),
            status.getSlaveId().getValue(), frameworkInfo.getId().getValue(),
            status.getExecutorId().getValue());

    int ret = status.getState().getNumber() - Protos.TaskState.TASK_FINISHED_VALUE;
    String finished = TimestampHelper.now();
    try {/*from  w  ww .ja v a 2s.  co  m*/
        JobQueue.finished(status.getTaskId().getValue(), maybeUrl, ret, finished);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
    } catch (JobNotFoundException e) {
        LOG.warn(e.toString(), e);
        // TODO: re-insert the failed job again?
    }

}

From source file:com.freedomotic.plugins.devices.harvester_chart.HarvesterChart.java

@Override
public void onStart() {
    String dbType = configuration.getStringProperty("driver", "h2");
    String dbUser = configuration.getStringProperty("dbuser", "sa");
    String dbPassword = configuration.getStringProperty("dbpassword", "");
    String dbName = configuration.getStringProperty("dbname", "harvester");
    String driverClass = "";
    try {/*  w ww.jav  a 2  s .  c o m*/
        String dbBasePath, dbPath;
        char shortDBType = 'z';
        if ("h2".equals(dbType)) {
            shortDBType = 'h';
        }
        if ("mysql".equals(dbType)) {
            shortDBType = 'm';
        }
        if ("sqlserver".equals(dbType)) {
            shortDBType = 's';
        }
        if ("sqlite".equals(dbType)) {
            shortDBType = 'l';
        }
        //System.out.println("Wilson Kong Debug Message:" + dbType);
        switch (shortDBType) {
        case ('h'):
            dbBasePath = configuration.getStringProperty("dbpath",
                    Info.getDevicesPath() + File.separator + "/es.gpulido.harvester/data");
            dbPath = dbBasePath;
            driverClass = "org.h2.Driver";
            break;
        case ('m'):
            dbBasePath = configuration.getStringProperty("dbpath", "localhost");
            dbPath = "//" + dbBasePath;
            driverClass = "com.mysql.jdbc.Driver";
            break;
        case ('s'):
            dbBasePath = configuration.getStringProperty("dbpath", "localhost");
            dbPath = "//" + dbBasePath;
            driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
            break;
        case ('l'):
            dbBasePath = configuration.getStringProperty("dbpath",
                    Info.getDevicesPath() + File.separator + "es.gpulido.harvester" + File.separator + "data");
            dbPath = dbBasePath + File.separator + dbName;
            driverClass = "org.sqlite.JDBC";
            break;
        default:
            dbPath = "";
        }
        //System.out.println("Wilson Kong Message: jdbc:" + dbType + ":" + dbPath + File.separator + dbName);
        Class.forName(driverClass);

        connection = DriverManager.getConnection("jdbc:" + dbType + ":" + dbPath, dbUser, dbPassword);
        // add application code here

        this.setDescription(
                "Connected to jdbc:" + dbType + ":" + dbPath + File.separator + dbName + " as user:" + dbUser);
    } catch (SQLException ex) {
        Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
        System.out.println("Wilson Kong Error: " + ex.toString());
        //ex.printStackTrace();
        stop();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
        this.setDescription("The " + driverClass + " Driver is not loaded");
        System.out.println("Wilson Kong Error: " + ex.toString());
        stop();
    }
}

From source file:com.mapd.utility.SQLImporter.java

private void createMapDTable(ResultSetMetaData metaData) {

    StringBuilder sb = new StringBuilder();
    sb.append("Create table ").append(cmd.getOptionValue("targetTable")).append("(");

    // Now iterate the metadata
    try {//from ww  w  .  j  av  a  2s.  c  om
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            if (i > 1) {
                sb.append(",");
            }
            LOGGER.debug("Column name is " + metaData.getColumnName(i));
            LOGGER.debug("Column type is " + metaData.getColumnTypeName(i));
            LOGGER.debug("Column type is " + metaData.getColumnType(i));

            sb.append(metaData.getColumnName(i)).append(" ");

            sb.append(getColType(metaData.getColumnType(i), metaData.getPrecision(i), metaData.getScale(i)));
        }
        sb.append(")");

        if (Integer.valueOf(cmd.getOptionValue("fragmentSize", "0")) > 0) {
            sb.append(" with (fragment_size = ");
            sb.append(cmd.getOptionValue("fragmentSize", "0"));
            sb.append(")");
        }

    } catch (SQLException ex) {
        LOGGER.error("Error processing the metadata - " + ex.toString());
        exit(1);
    }

    executeMapDCommand(sb.toString());

}

From source file:corner.migration.services.impl.MigrationServiceImpl.java

/**
 * Execute the given schema script on the given JDBC Connection.
 * <p>/*from   www  .j  a  v a2s  .co m*/
 * Note that the default implementation will log unsuccessful statements and
 * continue to execute. Override the <code>executeSchemaStatement</code>
 * method to treat failures differently.
 * 
 * @param con
 *            the JDBC Connection to execute the script on
 * @param sql
 *            the SQL statements to execute
 * @throws SQLException
 *             if thrown by JDBC methods
 * @see #executeSchemaStatement
 * @param con
 *            the JDBC Connection to execute the script on
 * @param sql
 *            the SQL statements to execute
 * @throws SQLException
 *             if thrown by JDBC methods
 */
protected void executeSchemaScript(Connection con, String... sql) throws SQLException {
    if (sql != null && sql.length > 0) {
        boolean oldAutoCommit = con.getAutoCommit();
        if (!oldAutoCommit) {
            con.setAutoCommit(false);
        }
        try {
            Statement stmt = con.createStatement();
            try {
                for (int i = 0; i < sql.length; i++) {
                    try {
                        logger.info("[db-upgrade] " + sql[i]);
                        executeSchemaStatement(stmt, sql[i]);
                    } catch (SQLException se) {
                        logger.error("[db-upgrade]" + se.toString(), se);
                        throw se;
                    }
                }
            } finally {
                JdbcUtils.closeStatement(stmt);
            }
        } finally {
            if (!oldAutoCommit) {
                con.setAutoCommit(false);
            }
        }
    }
}

From source file:com.netspective.sparx.sql.QueryResultSetDataSource.java

public Object getActiveRowColumnData(int columnIndex, int flags) {
    try {//from   www.j a va2 s .c  o m
        if (cacheColumnData) {
            if (retrievedColumnData[columnIndex])
                return cachedColumnData[columnIndex];

            cachedColumnData[columnIndex] = resultSet.getObject(columnIndex + 1);
            retrievedColumnData[columnIndex] = true;
            return cachedColumnData[columnIndex];
        } else
            return resultSet.getObject(columnIndex + 1);
    } catch (SQLException e) {
        log.error("Unable to retrieve column data: columnIndex = " + columnIndex + ", row = " + activeRowIndex
                + ", flags = " + flags, e);
        return e.toString();
    }
}

From source file:edu.ku.brc.af.auth.specify.SpecifySecurityMgr.java

@Override
public boolean authenticateDB(final String user, final String pass, final String driverClass, final String url,
        final String dbUserName, final String dbPwd) throws Exception {
    Connection conn = null;/*from  w  ww  . j  a  v  a 2 s .c o  m*/
    Statement stmt = null;
    boolean passwordMatch = false;

    try {
        Class.forName(driverClass);

        conn = DriverManager.getConnection(url, dbUserName, dbPwd);

        String query = "SELECT * FROM specifyuser where name='" + user + "'"; //$NON-NLS-1$ //$NON-NLS-2$
        stmt = conn.createStatement();
        ResultSet result = stmt.executeQuery(query);
        String dbPassword = null;

        while (result.next()) {
            if (!result.isFirst()) {
                throw new LoginException("authenticateDB - Ambiguous user (located more than once): " + user); //$NON-NLS-1$
            }
            dbPassword = result.getString(result.findColumn("Password")); //$NON-NLS-1$

            if (StringUtils.isNotEmpty(dbPassword) && StringUtils.isAlphanumeric(dbPassword)
                    && UIHelper.isAllCaps(dbPassword) && dbPassword.length() > 20) {
                dbPassword = Encryption.decrypt(dbPassword, pass);
            }
            break;
        }

        /*if (dbPassword == null)
        {
        throw new LoginException("authenticateDB - Password for User " + user + " undefined."); //$NON-NLS-1$ //$NON-NLS-2$
        }*/
        if (pass != null && dbPassword != null && pass.equals(dbPassword)) {
            passwordMatch = true;
        }

        // else: passwords do NOT match, user will not be authenticated
    } catch (java.lang.ClassNotFoundException e) {
        e.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifySecurityMgr.class, e);
        log.error("authenticateDB - Could not connect to database, driverclass - ClassNotFoundException: "); //$NON-NLS-1$
        log.error(e.getMessage());
        throw new LoginException("authenticateDB -  Database driver class not found: " + driverClass); //$NON-NLS-1$
    } catch (SQLException ex) {
        if (debug)
            log.error("authenticateDB - SQLException: " + ex.toString()); //$NON-NLS-1$
        if (debug)
            log.error("authenticateDB - " + ex.getMessage()); //$NON-NLS-1$
        throw new LoginException("authenticateDB - SQLException: " + ex.getMessage()); //$NON-NLS-1$
    } finally {
        try {
            if (conn != null)
                conn.close();
            if (stmt != null)
                stmt.close();
        } catch (SQLException e) {
            edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifySecurityMgr.class, e);
            log.error("Exception caught: " + e.toString()); //$NON-NLS-1$
            e.printStackTrace();
        }
    }
    return passwordMatch;
}