Example usage for java.sql DataTruncation printStackTrace

List of usage examples for java.sql DataTruncation printStackTrace

Introduction

In this page you can find the example usage for java.sql DataTruncation printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySQLConnection();
    Statement stmt = null;/*from   ww  w  .  j  a v  a  2 s  . com*/
    try {
        stmt = conn.createStatement();
        stmt.executeUpdate("DELETE FROM Mytable");
        displayError(stmt.getWarnings());
        stmt.executeUpdate(
                "INSERT INTO Mytable(id, name)" + "VALUES(1, 'NameLongerThanColumnLengthInDatabase')");
        displayError(stmt.getWarnings());
    } catch (DataTruncation dt) {
        displayError(dt);
        dt.printStackTrace();
    } catch (SQLException se) {
        System.out.println("Database error message: " + se.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        stmt.close();
        conn.close();
    }
}

From source file:DemoDataTruncation.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySQLConnection();
    Statement stmt = null;/*from   w w  w .  j  a va2  s.  co m*/
    try {
        stmt = conn.createStatement();
        stmt.executeUpdate("DELETE FROM animals_table");
        displayError(stmt.getWarnings());
        stmt.executeUpdate(
                "INSERT INTO animals_table(id, name)" + "VALUES(1, 'NameLongerThanColumnLengthInDatabase')");
        displayError(stmt.getWarnings());
    } catch (DataTruncation dt) {
        displayError(dt);
        dt.printStackTrace();
    } catch (SQLException se) {
        System.out.println("Database error message: " + se.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        stmt.close();
        conn.close();
    }
}