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:com.cloudera.sqoop.manager.SqlManager.java

@Override
public String getPrimaryKey(String tableName) {
    try {//from   ww  w  .  j av a 2  s . c om
        DatabaseMetaData metaData = this.getConnection().getMetaData();
        ResultSet results = metaData.getPrimaryKeys(null, null, tableName);
        if (null == results) {
            return null;
        }

        try {
            if (results.next()) {
                return results.getString("COLUMN_NAME");
            } else {
                return null;
            }
        } finally {
            results.close();
            getConnection().commit();
        }
    } catch (SQLException sqlException) {
        LOG.error("Error reading primary key metadata: " + sqlException.toString());
        return null;
    }
}

From source file:com.cloudera.sqoop.manager.SqlManager.java

/**
 * Prints the contents of a ResultSet to the specified PrintWriter.
 * The ResultSet is closed at the end of this method.
 * @param results the ResultSet to print.
 * @param pw the location to print the data to.
 *//*from ww  w  .j a  va  2s.  c o m*/
protected void formatAndPrintResultSet(ResultSet results, PrintWriter pw) {
    try {
        try {
            int cols = results.getMetaData().getColumnCount();
            pw.println("Got " + cols + " columns back");
            if (cols > 0) {
                ResultSetMetaData rsmd = results.getMetaData();
                String schema = rsmd.getSchemaName(1);
                String table = rsmd.getTableName(1);
                if (null != schema) {
                    pw.println("Schema: " + schema);
                }

                if (null != table) {
                    pw.println("Table: " + table);
                }
            }
        } catch (SQLException sqlE) {
            LOG.error("SQLException reading result metadata: " + sqlE.toString());
        }

        try {
            new ResultSetPrinter().printResultSet(pw, results);
        } catch (IOException ioe) {
            LOG.error("IOException writing results: " + ioe.toString());
            return;
        }
    } finally {
        try {
            results.close();
            getConnection().commit();
        } catch (SQLException sqlE) {
            LOG.warn("SQLException closing ResultSet: " + sqlE.toString());
        }

        release();
    }
}

From source file:com.cloudera.sqoop.manager.SqlManager.java

@Override
public String[] listTables() {
    ResultSet results = null;//from   w  w  w  .  j a v a 2  s.  c  o m
    String[] tableTypes = { "TABLE" };
    try {
        try {
            DatabaseMetaData metaData = this.getConnection().getMetaData();
            results = metaData.getTables(null, null, null, tableTypes);
        } catch (SQLException sqlException) {
            LOG.error("Error reading database metadata: " + sqlException.toString());
            return null;
        }

        if (null == results) {
            return null;
        }

        try {
            ArrayList<String> tables = new ArrayList<String>();
            while (results.next()) {
                String tableName = results.getString("TABLE_NAME");
                tables.add(tableName);
            }

            return tables.toArray(new String[0]);
        } catch (SQLException sqlException) {
            LOG.error("Error reading from database: " + sqlException.toString());
            return null;
        }
    } finally {
        if (null != results) {
            try {
                results.close();
                getConnection().commit();
            } catch (SQLException sqlE) {
                LOG.warn("Exception closing ResultSet: " + sqlE.toString());
            }
        }
    }
}

From source file:io.github.retz.db.Database.java

public void deleteOldJobs(int leeway) {
    try (Connection conn = dataSource.getConnection()) {
        conn.setAutoCommit(false);//from ww  w . j a v  a  2s .  c  o  m
        new Jobs(conn, MAPPER).collect(leeway);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
    }
}

From source file:io.github.retz.db.Database.java

public Optional<String> getFrameworkId() {
    try (Connection conn = dataSource.getConnection()) {
        return new Property(conn).getFrameworkId();
    } catch (SQLException e) {
        LOG.error(e.toString());//w w  w  .  j  a  v a 2  s . c o  m
        return Optional.empty();
    }
}

From source file:io.github.retz.db.Database.java

public boolean allTableExists() {
    try (Connection conn = dataSource.getConnection()) {
        return allTableExists(conn);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
        return false;
    }/*  w  w  w.j  av a  2s . co  m*/
}

From source file:io.github.retz.db.Database.java

public void deleteAllProperties() {
    try (Connection conn = dataSource.getConnection()) {
        conn.setAutoCommit(false);/*from w  w  w. j  a va2  s  .  c om*/
        new Property(conn).deleteAll();
        conn.commit();
    } catch (SQLException e) {
        LOG.error(e.toString());
    }
}

From source file:io.github.retz.db.Database.java

public void retryJobs(List<Integer> ids) {
    try (Connection conn = dataSource.getConnection()) {
        conn.setAutoCommit(false);//from ww w .  j a  v a2s.  c  om
        new Jobs(conn, MAPPER).doRetry(ids);
        conn.commit();
    } catch (SQLException e) {
        LOG.error(e.toString());
    }
}

From source file:io.github.retz.db.Database.java

public Optional<Application> getApplication(String appid) throws IOException {
    try (Connection conn = dataSource.getConnection()) { //pool.getConnection()) {
        conn.setAutoCommit(true);/*from  ww w. j  ava 2s  . c o  m*/
        return getApplication(conn, appid);
    } catch (SQLException e) {
        LOG.error(e.toString());
        e.printStackTrace();
    }
    return Optional.empty();
}

From source file:io.github.retz.db.Database.java

public void deleteAllJob(int maxId) {
    try (Connection conn = dataSource.getConnection(); //pool.getConnection();
            PreparedStatement p = conn.prepareStatement("DELETE FROM jobs WHERE id < ?")) {
        conn.setAutoCommit(true);/* w w  w  . ja  v a 2 s. co m*/
        p.setInt(1, maxId);
        p.execute();
    } catch (SQLException e) {
        LOG.error(e.toString());
    }
}