Example usage for java.sql SQLException getErrorCode

List of usage examples for java.sql SQLException getErrorCode

Introduction

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

Prototype

public int getErrorCode() 

Source Link

Document

Retrieves the vendor-specific exception code for this SQLException object.

Usage

From source file:com.ibm.soatf.tool.Utils.java

public static String getSQLExceptionMessage(SQLException ex) {
    return String.format("SQL Code: %s Message: %s", ex.getErrorCode(), ex.getMessage());
}

From source file:it.itis.pertini.falessi.tunes.services.AbstractService.java

protected static ErrorMessage toErrorMessage(SQLException e) {
    ErrorMessage errorMessage = new ErrorMessage();
    errorMessage.setErrorCode(e.getErrorCode());
    errorMessage.setSqlState(e.getSQLState());

    StringWriter stringWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(stringWriter));
    errorMessage.setStackTrace(stringWriter.toString());

    return errorMessage;
}

From source file:info.extensiblecatalog.OAIToolkit.db.DButil.java

private static void logException(SQLException sqlex, String sql) {
    prglog.error("[PRG] SQLException with " + "SQLState='" + sqlex.getSQLState() + "' and " + "errorCode="
            + sqlex.getErrorCode() + " and " + "message=" + sqlex.getMessage() + "; sql was '" + sql + "'"
            + " open/total: " + connectionCounter + "/" + connectionCounterTotal);
}

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * @param data Clob to process and encode
 * @return String representation of Clob.
 *///from  w w w  . j  ava2 s  .c  om
static String processClobData(Clob data) {
    if (data == null)
        return "NULL";

    Reader reader = null;
    BufferedReader br = null;
    try {
        reader = data.getCharacterStream();
        br = new BufferedReader(reader);

        return processStringData(IOUtils.toString(br));
    } catch (SQLException e) {
        LOGGER.error("Could not read data from stream :" + e.getErrorCode() + " - " + e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error("Could not read data from stream :" + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(br);
    }
    return "NULL";
}

From source file:cai.sql.SQL.java

public static void error_msg(String msg, SQLException e, String stm) throws RuntimeException {
    String s = new String(
            "SQL: " + msg + ": " + e.getErrorCode() + "/" + e.getSQLState() + " " + e.getMessage());

    if (stm != null)
        s += "\nSQL: Statement `" + stm + "'";

    logger.error(s);// w w w.j  a v a2s  .co m

    if (JDBC_abort_on_error)
        throw new RuntimeException(s);
}

From source file:cit360.sandbox.BackEndMenu.java

public final static void connect() {
    Connection conn = null;// w ww  .j a v a 2 s .  co  m
    try {
        conn = DriverManager.getConnection("jdbc:mysql://localhost/cit361-sandbox?" + "user=root&password=");

        // Do something with the Connection

    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());

    }

    if (null != conn) {
        System.out.println("Connected to database!");
    } else {
        System.out.println("Failed to make connection!");
    }
    try {
        Statement stmt = conn.createStatement();
        String query = "select * from movies ;";
        //movies is the table name
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String name = rs.getObject(2).toString();
            String Start_Time = rs.getObject(3).toString();
            System.out.println(name + ": " + Start_Time);
            //movies table has name and price columns

        }
    } catch (SQLException e) {
        for (Throwable ex : e) {
            System.err.println("Error occurred " + ex);
        }
        System.out.println("Error in fetching data");
    }
}

From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java

public static void alternatePrintSQLException(SQLException ex) {
    while (ex != null) {
        System.err.println("SQLState: " + ex.getSQLState());
        System.err.println("Error Code: " + ex.getErrorCode());
        System.err.println("Message: " + ex.getMessage());
        Throwable t = ex.getCause();
        while (t != null) {
            System.out.println("Cause: " + t);
            t = t.getCause();/*from www .  ja v a  2  s .c  o  m*/
        }
        ex = ex.getNextException();
    }
}

From source file:Data.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.// ww  w .j  a v  a  2 s .  c om
 * @throws ClassNotFoundException 
 */
private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException {

    TimeSeries s1 = new TimeSeries("Humidit");
    TimeSeries s2 = new TimeSeries("Temprature");
    ResultSet rs = null;

    try {
        String sqlRequest = "SELECT * FROM `t_temphum`";
        rs = stmt.executeQuery(sqlRequest);
        Double hum;
        Double temp;
        Timestamp date;

        while (rs.next()) {
            hum = rs.getDouble("tmp_humidity");
            temp = rs.getDouble("tmp_temperature");
            date = rs.getTimestamp("tmp_date");

            if (tempUnit == "F") {
                temp = celsiusToFahrenheit(temp.toString());
            }

            if (date != null) {
                s1.add(new Second(date), hum);
                s2.add(new Second(date), temp);
            } else {
                JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne",
                        "Date null", JOptionPane.WARNING_MESSAGE);
            }
        }

        rs.close();
    } catch (SQLException e) {
        String exception = e.toString();

        if (e.getErrorCode() == 0) {
            JOptionPane.showMessageDialog(panelPrincipal,
                    "Le serveur met trop de temps  rpondre ! Veuillez rssayer plus tard ou contacter un administrateur",
                    "Connection timed out", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception,
                    "Titre : exception", JOptionPane.ERROR_MESSAGE);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (Exception e) {
        String exception = e.toString();
        JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    return dataset;

}

From source file:de.micromata.genome.jpa.EmgrFactory.java

/**
 * Convert exception.//w w  w . j a  v a2  s.c om
 *
 * @param ex the ex
 * @return the runtime exception
 */
public static RuntimeException convertException(RuntimeException ex) {
    if (ex instanceof QueryTimeoutException) {
        // this is a oracle/hibernate bug workouround.
        // hibernate think this is is a query timeout, but should a DataException
        if (ex.getCause() instanceof org.hibernate.QueryTimeoutException) {
            org.hibernate.QueryTimeoutException qto = (org.hibernate.QueryTimeoutException) ex.getCause();
            if (qto.getCause() instanceof SQLException) {
                SQLException sqlex = (SQLException) qto.getCause();
                // ORA-12899
                if (sqlex.getErrorCode() == 12899) {
                    return new DataPersistenceException(ex.getMessage(), qto.getSQL(), sqlex.getSQLState(), ex);
                }
            }
        }
    }
    if (ex instanceof PersistenceException) {
        Throwable cause = ex.getCause();
        if (cause instanceof ConstraintViolationException) {
            ConstraintViolationException cve = (ConstraintViolationException) cause;
            cve.getMessage();
            String sql = cve.getSQL();
            return new ConstraintPersistenceException(cve.getMessage(), sql, cve.getSQLState(),
                    cve.getConstraintName(), ex);
        } else if (cause instanceof DataException) {
            DataException dex = (DataException) cause;
            return new DataPersistenceException(ex.getMessage(), dex.getSQL(), dex.getSQLState(), ex);
        } else if (cause instanceof PropertyValueException) {
            if (StringUtils.startsWith(cause.getMessage(), "not-null ") == true) {
                return new NullableConstraintPersistenceException(ex.getMessage(), ex);
            }
        }
    }
    return ex;
}

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 ww w. j  av a2s . co  m*/
    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();

}