Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.liferay.sync.engine.service.SyncAccountService.java

public static Set<Long> getActiveSyncAccountIds() {
    if (_activeSyncAccountIds != null) {
        return _activeSyncAccountIds;
    }/* www  .  ja v  a  2  s.c om*/

    try {
        _activeSyncAccountIds = new HashSet<>(_syncAccountPersistence.findByActive(true));

        return _activeSyncAccountIds;
    } catch (SQLException sqle) {
        if (_logger.isDebugEnabled()) {
            _logger.debug(sqle.getMessage(), sqle);
        }

        return Collections.emptySet();
    }
}

From source file:com.liferay.sync.engine.service.SyncAccountService.java

public static SyncAccountPersistence getSyncAccountPersistence() {
    if (_syncAccountPersistence != null) {
        return _syncAccountPersistence;
    }// ww w .  ja va2s.com

    try {
        _syncAccountPersistence = new SyncAccountPersistence();

        registerModelListener(new SyncAccountModelListener());

        return _syncAccountPersistence;
    } catch (SQLException sqle) {
        if (_logger.isDebugEnabled()) {
            _logger.debug(sqle.getMessage(), sqle);
        }

        return null;
    }
}

From source file:gridool.util.jdbc.JDBCUtils.java

private static void rethrow(SQLException cause, String[] sqls) throws SQLException {
    StringBuilder msg = new StringBuilder(cause.getMessage());
    msg.append(" Query: ");
    if (sqls == null) {
        msg.append("[]");
    } else {/*from  w w  w.ja va 2s.  com*/
        msg.append(Arrays.asList(sqls));
    }
    SQLException e = new SQLException(msg.toString());
    e.setNextException(cause);
    throw e;
}

From source file:module.entities.NameFinder.DB.java

public static void InsertLexiconEntry(PreparedStatement statement, String lexiconType, String lemma,
        String entity, String lang) throws SQLException {
    try {//from  w w w.j a  va  2 s. c  om
        statement.setString(1, lexiconType);
        statement.setString(2, lemma);
        statement.setString(3, entity);
        statement.setString(4, lang);
        statement.addBatch();
        batchSize++;
        if (batchSize == 1000) {
            statement.executeBatch();
            statement.clearBatch();
            batchSize = 0;
        }
    } catch (SQLException ex) {
        System.err.println("Skipping:" + lemma + " " + entity + " " + ex.getMessage());
    }
}

From source file:gridool.util.jdbc.JDBCUtils.java

/**
 * Throws a new exception with a more informative error message.
 * //from   ww  w .j av a 2 s . c o  m
 * @param cause The original exception that will be chained to the new 
 * exception when it's rethrown. 
 * @param sql The query that was executing when the exception happened.     
 * @param params The query replacement paramaters; <code>null</code> is a 
 * valid value to pass in.
 */
private static void rethrow(SQLException cause, String sql, Object[] params) throws SQLException {
    StringBuilder msg = new StringBuilder(cause.getMessage());
    msg.append(" Query: ");
    msg.append(sql);
    msg.append(" Parameters: ");
    if (params == null) {
        msg.append("[]");
    } else {
        msg.append(Arrays.asList(params));
    }
    SQLException e = new SQLException(msg.toString());
    e.setNextException(cause);
    throw e;
}

From source file:com.liferay.sync.engine.service.SyncAccountService.java

public static void deleteSyncAccount(long syncAccountId, boolean unregister) {

    try {/*from w w w.ja v  a  2  s .  c  o m*/

        // Sync account

        if (unregister) {
            ServerEventUtil.unregisterSyncDevice(syncAccountId);
        }

        SyncAccount syncAccount = fetchSyncAccount(syncAccountId);

        _syncAccountPersistence.deleteById(syncAccountId);

        // Sync files

        try {
            deleteSyncFiles(syncAccount);
        } catch (IOException ioe) {
            _logger.error(ioe.getMessage(), ioe);
        }

        // Sync sites

        List<SyncSite> syncSites = SyncSiteService.findSyncSites(syncAccountId);

        for (SyncSite syncSite : syncSites) {
            SyncSiteService.deleteSyncSite(syncSite.getSyncSiteId());
        }

        // Sync user

        SyncUser syncUser = SyncUserService.fetchSyncUser(syncAccountId);

        if (syncUser != null) {
            SyncUserService.deleteSyncUser(syncUser.getSyncUserId());
        }

        // Sync watch events

        SyncWatchEventService.deleteSyncWatchEvents(syncAccountId);
    } catch (SQLException sqle) {
        if (_logger.isDebugEnabled()) {
            _logger.debug(sqle.getMessage(), sqle);
        }
    }
}

From source file:com.mycompany.rproject.runnableClass.java

public static void use() throws IOException {
    AWSCredentials awsCreds = new PropertiesCredentials(
            new File("/Users/paulamontojo/Desktop/AwsCredentials.properties"));

    AmazonSQS sqs = new AmazonSQSClient(awsCreds);

    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sqs.setRegion(usWest2);//from   w  w  w .  ja v a  2s .  c  om
    String myQueueUrl = "https://sqs.us-west-2.amazonaws.com/711690152696/MyQueue";

    System.out.println("Receiving messages from MyQueue.\n");

    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
    List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
    while (messages.isEmpty()) {

        messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
    }

    String messageRecieptHandle = messages.get(0).getReceiptHandle();

    String a = messages.get(0).getBody();

    sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle));

    //aqui opero y cuando acabe llamo para operar el siguiente.

    String n = "";
    String dbName = "mydb";
    String userName = "pmontojo";
    String password = "pmontojo";
    String hostname = "mydb.cued7orr1q2t.us-west-2.rds.amazonaws.com";
    String port = "3306";
    String jdbcUrl = "jdbc:mysql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password="
            + password;
    Connection conn = null;
    Statement setupStatement = null;
    Statement readStatement = null;
    ResultSet resultSet = null;
    String results = "";
    int numresults = 0;
    String statement = null;

    try {

        conn = DriverManager.getConnection(jdbcUrl);

        setupStatement = conn.createStatement();

        String insertUrl = "select video_name from metadata where id = " + a + ";";
        String checkUrl = "select url from metadata where id = " + a + ";";

        ResultSet rs = setupStatement.executeQuery(insertUrl);

        rs.next();

        System.out.println("este es el resultdo " + rs.getString(1));

        String names = rs.getString(1);
        ResultSet ch = setupStatement.executeQuery(checkUrl);
        ch.next();
        System.out.println("este es la url" + ch.getString(1));
        String urli = ch.getString(1);

        while (urli == null) {
            ResultSet sh = setupStatement.executeQuery(checkUrl);
            sh.next();
            System.out.println("este es la url" + sh.getString(1));
            urli = sh.getString(1);

        }
        setupStatement.close();
        AmazonS3 s3Client = new AmazonS3Client(awsCreds);

        S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, names));

        IOUtils.copy(object.getObjectContent(),
                new FileOutputStream(new File("/Users/paulamontojo/Desktop/download.avi")));

        putOutput();
        write();
        putInDb(sbu.toString(), a);

    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    } finally {
        System.out.println("Closing the connection.");
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException ignore) {
            }
    }

    use();

}

From source file:edu.mayo.cts2.uriresolver.dao.DAOUtiltities.java

public static boolean checkTablesExist(DataSource ds) {
    Connection con = null;/*from w ww  .  j ava2 s. c om*/
    boolean tablesExist = true;
    try {
        con = ds.getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        for (int i = 0; i < TABLENAMES.length; i++) {
            if (!tableExists(metaData, TABLENAMES[i])) {
                tablesExist = false;
                logger.error("Database is missing table: " + TABLENAMES[i]);
            }
        }
        con.close();
    } catch (SQLException e) {
        logger.error("Unknown error while checking tables exist, check all connection values");
        return false;
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (SQLException e) {
            logger.error("Error while closing data source connection object: " + e.getMessage());
            return false;
        }
    }

    return tablesExist;
}

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

/**
 * Close statement./*  w  ww  .ja v  a  2 s .c  om*/
 *
 * @param statement
 *            the statement
 */
private static void closeStatement(Statement statement) {
    if (statement != null) {
        try {
            statement.close();
        } catch (SQLException e) {
            log.warn("Database error. Could not close Statement. Continuing with" + " others. - "
                    + e.getMessage(), e);
        }
    }
}

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

/**
 * Close statement.//from   w w w  .  jav a  2 s.  c  om
 *
 * @param preparedStatement
 *            the prepared statement
 */
private static void closeStatement(PreparedStatement preparedStatement) {
    if (preparedStatement != null) {
        try {
            preparedStatement.close();
        } catch (SQLException e) {
            log.warn("Database error. Could not close PreparedStatement. Continuing with" + " others. - "
                    + e.getMessage(), e);
        }
    }
}