List of usage examples for java.sql SQLException toString
public String toString()
From source file:io.github.retz.db.Database.java
public boolean setFrameworkId(String value) { try (Connection conn = dataSource.getConnection()) { conn.setAutoCommit(true);/*from w w w .j a va 2 s .c o m*/ LOG.info("setting new framework: {}", value); return new Property(conn).setFrameworkId(value); } catch (SQLException e) { LOG.error(e.toString()); return false; } }
From source file:io.github.retz.db.Database.java
public List<Application> getAllApplications(String id) throws IOException { List<Application> ret = new LinkedList<>(); try (Connection conn = dataSource.getConnection()) { //pool.getConnection()) { conn.setAutoCommit(false);//from w w w . j a va 2 s .c om ret = getApplications(conn, id); conn.commit(); } catch (SQLException e) { LOG.error(e.toString()); e.printStackTrace(); } return ret; }
From source file:io.github.retz.db.Database.java
public void clear() { try (Connection conn = dataSource.getConnection(); Statement statement = conn.createStatement()) { statement.execute("DROP TABLE users, jobs, applications, properties"); //statement.execute("DELETE FROM jobs"); //statement.execute("DELETE FROM applications"); conn.commit();/*from ww w . j ava 2 s. c om*/ LOG.info("All tables dropped successfully"); } catch (SQLException e) { LOG.error(e.toString()); e.printStackTrace(); } }
From source file:org.apache.sqoop.manager.SqlManager.java
protected Map<String, String> getColumnTypeNamesForRawQuery(String stmt) { ResultSet results;// ww w .ja v a2 s . co m try { results = execute(stmt); } catch (SQLException sqlE) { LOG.error("Error executing statement: " + sqlE.toString(), sqlE); release(); return null; } try { Map<String, String> colTypeNames = new HashMap<String, String>(); int cols = results.getMetaData().getColumnCount(); ResultSetMetaData metadata = results.getMetaData(); for (int i = 1; i < cols + 1; i++) { String colTypeName = metadata.getColumnTypeName(i); String colName = metadata.getColumnName(i); if (colName == null || colName.equals("")) { colName = metadata.getColumnLabel(i); } colTypeNames.put(colName, colTypeName); } return colTypeNames; } catch (SQLException sqlException) { LOG.error("Error reading from database: " + sqlException.toString()); return null; } finally { try { results.close(); getConnection().commit(); } catch (SQLException sqlE) { LOG.warn("SQLException closing ResultSet: " + sqlE.toString()); } release(); } }
From source file:io.github.retz.db.Database.java
public Optional<User> getUser(String keyId) throws IOException { //try (Connection conn = DriverManager.getConnection(databaseURL)) { try (Connection conn = dataSource.getConnection()) { //pool.getConnection()) { conn.setAutoCommit(false);//w w w . j a v a 2 s . c om Optional<User> u = getUser(conn, keyId); conn.commit(); return u; } catch (SQLException e) { LOG.error(e.toString()); e.printStackTrace(); return Optional.empty(); } }
From source file:io.github.retz.db.Database.java
public void safeDeleteApplication(String appid) { try (Connection conn = dataSource.getConnection()) { //pool.getConnection()) { conn.setAutoCommit(false);//from ww w . ja v a2 s . c o m // TODO: check there are no non-finished Jobs // TODO: THINK: what about finished jobs?????? deleteApplication(conn, appid); LOG.info("commiting deletion... {}", appid); conn.commit(); } catch (SQLException e) { LOG.error(e.toString()); e.printStackTrace(); } }
From source file:io.github.retz.db.Database.java
public int countJobs() { try (Connection conn = dataSource.getConnection(); //pool.getConnection(); PreparedStatement p = conn.prepareStatement("SELECT count(id) FROM jobs")) { conn.setAutoCommit(true);/*from ww w . j av a 2s.com*/ try (ResultSet set = p.executeQuery()) { if (set.next()) { return set.getInt(1); } } } catch (SQLException e) { LOG.error(e.toString()); } return -1; }
From source file:io.github.retz.db.Database.java
private int countByState(Job.JobState state) { try (Connection conn = dataSource.getConnection(); //pool.getConnection(); PreparedStatement p = conn.prepareStatement("SELECT count(id) FROM jobs WHERE state = ?")) { conn.setAutoCommit(true);/*from w w w. ja v a 2 s. co m*/ p.setString(1, state.toString()); try (ResultSet set = p.executeQuery()) { if (set.next()) { return set.getInt(1); } return 0; } } catch (SQLException e) { LOG.error(e.toString(), e); } return -1; }
From source file:io.github.retz.db.Database.java
public int getLatestJobId() { try (Connection conn = dataSource.getConnection(); //pool.getConnection(); PreparedStatement p = conn.prepareStatement("SELECT id FROM jobs ORDER BY id DESC LIMIT 1")) { conn.setAutoCommit(true);/* w w w . j av a 2 s. com*/ try (ResultSet res = p.executeQuery()) { if (res.next()) { int id = res.getInt("id"); return id; } // No such application } } catch (SQLException e) { LOG.error(e.toString(), e); } return 0; }
From source file:org.apache.sqoop.manager.SqlManager.java
/** * Get column types for a query statement that we do not modify further. *//*from w w w. j a v a2 s.c om*/ protected Map<String, Integer> getColumnTypesForRawQuery(String stmt) { ResultSet results; try { results = execute(stmt); } catch (SQLException sqlE) { LOG.error("Error executing statement: " + sqlE.toString(), sqlE); release(); return null; } try { Map<String, Integer> colTypes = new SqlTypeMap<String, Integer>(); int cols = results.getMetaData().getColumnCount(); ResultSetMetaData metadata = results.getMetaData(); for (int i = 1; i < cols + 1; i++) { int typeId = metadata.getColumnType(i); // If we have an unsigned int we need to make extra room by // plopping it into a bigint if (typeId == Types.INTEGER && !metadata.isSigned(i)) { typeId = Types.BIGINT; } String colName = metadata.getColumnName(i); if (colName == null || colName.equals("")) { colName = metadata.getColumnLabel(i); } colTypes.put(colName, Integer.valueOf(typeId)); } return colTypes; } catch (SQLException sqlException) { LOG.error("Error reading from database: " + sqlException.toString()); return null; } finally { try { results.close(); getConnection().commit(); } catch (SQLException sqlE) { LOG.warn("SQLException closing ResultSet: " + sqlE.toString()); } release(); } }