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.tfm.utad.sqoopdata.SqoopVerticaDB.java

private static Long findMaxID(Connection conn) {
    Long id = (long) 0;
    Statement stmt = null;/*from w  ww .j av a  2 s . c o  m*/
    String query;
    try {
        stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        query = "SELECT MAX(id) AS id FROM s1.coordinates";
        LOG.info("Query execution: " + query);
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            id = (long) rs.getInt("id");
        }
    } catch (SQLException e) {
        LOG.error("SQLException error: " + e.toString());
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException ex) {
                LOG.error("Statement error: " + ex.toString());
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                LOG.error("Connection error: " + ex.toString());
            }
        }
    }
    return id;
}

From source file:org.apache.falcon.util.HsqldbTestUtils.java

public static String[] listTables() {
    ResultSet results = null;//from ww  w  . j a v  a  2 s .com
    String[] tableTypes = { "TABLE" };
    try {
        try {
            DatabaseMetaData metaData = getConnection().getMetaData();
            results = metaData.getTables(null, null, null, tableTypes);
        } catch (SQLException sqlException) {
            LOG.error("Error reading database metadata: " + sqlException.toString(), sqlException);
            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(), sqlException);
            return null;
        }
    } finally {
        if (null != results) {
            try {
                results.close();
                getConnection().commit();
            } catch (SQLException sqlE) {
                LOG.error("Exception closing ResultSet: " + sqlE.toString(), sqlE);
            }
        }
    }
}

From source file:com.tfm.utad.sqoopdata.SqoopVerticaDB.java

private static void findBetweenMinIDAndMaxID(Connection conn, Long minID, Long maxID) {
    Statement stmt = null;/*  w w w .  j  a va  2  s.  c  om*/
    String query;
    try {
        stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        query = "SELECT * FROM s1.coordinates WHERE id > " + minID + " AND id <= " + maxID + "";
        LOG.info("Query execution: " + query);
        ResultSet rs = stmt.executeQuery(query);
        int batch = 0;
        List<CoordinateCartoDB> result = new ArrayList<>();
        long start_time = System.currentTimeMillis();
        while (rs.next()) {
            batch++;
            CoordinateCartoDB cdb = new CoordinateCartoDB((long) rs.getInt("id"), rs.getString("userstr"),
                    rs.getString("created_date"), rs.getString("activity"), rs.getFloat("latitude"),
                    rs.getFloat("longitude"), (long) rs.getInt("userid"));
            result.add(cdb);
            if (batch == 50) {
                sendDataToCartoDB(result);
                batch = 0;
                result = new ArrayList<>();
            }
        }
        if (batch > 0) {
            sendDataToCartoDB(result);
        }
        long end_time = System.currentTimeMillis();
        long difference = end_time - start_time;
        LOG.info("CartoDB API execution time: " + String.format("%d min %d sec",
                TimeUnit.MILLISECONDS.toMinutes(difference), TimeUnit.MILLISECONDS.toSeconds(difference)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(difference))));
    } catch (SQLException e) {
        LOG.error("SQLException error: " + e.toString());
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException ex) {
                LOG.error("Statement error: " + ex.toString());
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                LOG.error("Connection error: " + ex.toString());
            }
        }
    }
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String checkRoomId(String room_number, String hospital_id) {
    String check = "default";
    try {/*  w ww . j  ava2 s .  com*/
        connection = DBConnection.getDBConnection().getConnection();
        String SQL = "select room_number from room where hospital_id = ? and room_number = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        preparedStatement.setString(2, room_number);
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            check = "Available";
        } else {
            check = "Unavailable";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        check = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return check;

}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String getRooms(String hospital_id) {
    String rooms = "";
    try {//from  w  w w.  ja  v  a 2 s .com

        connection = DBConnection.getDBConnection().getConnection();
        //String SQL = "select room_number,room_id from room where hospital_id = ?";
        String SQL = "select room_number,room_id from room where hospital_id = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String room_number = resultSet.getString("room_number");
            String room_id = resultSet.getString("room_id");
            //String room_id = resultSet.getString("room_id");
            rooms += "<option value=\"" + room_id + "\">" + room_number + "</option>";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        //throw new IllegalStateException
        rooms = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return rooms;
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String equipmentsGetRooms(String hospital_id) {
    String rooms = "";
    try {/* w ww  .  j  av a2 s.  c  o m*/
        connection = DBConnection.getDBConnection().getConnection();
        String SQL = "select * from room where hospital_id = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String room_id = resultSet.getString("room_id");
            String room_number = resultSet.getString("room_number");
            rooms += "<tr><form action='./deleteRoom' method='post'><td>" + room_number + "</td><td>" + room_id
                    + "</td><input type='hidden' name='room_id' value='" + room_id
                    + "'><input type='hidden' name='hospital_id' value='" + hospital_id + "'>";
            rooms += "<td><button type=\"submit\" onClick=\"return confirm('Do you wish to delete the Room. Ref: Room number = "
                    + room_number
                    + " Related devices will also be removed.');\" style='color:red'>delete</button></td>";
            rooms += "</form></tr>";
        }
    } catch (SQLException | IOException | PropertyVetoException e) {
        //throw new IllegalStateException
        rooms = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return rooms;
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String getRooms(String hospital_id, String room_id_default) {
    String rooms = "";
    try {//from   w w w  . j  a va2 s.c o  m

        connection = DBConnection.getDBConnection().getConnection();
        //String SQL = "select room_number,room_id from room where hospital_id = ?";
        String SQL = "select room_number,room_id from room where hospital_id = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String room_number = resultSet.getString("room_number");
            String room_id = resultSet.getString("room_id");
            if (room_id_default.equals(room_id))
                rooms += "<option selected=\"selected\" value=\"" + room_id + "\">" + room_number + "</option>";
            else
                rooms += "<option value=\"" + room_id + "\">" + room_number + "</option>";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        //throw new IllegalStateException
        rooms = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return rooms;
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String checkSerialAuth(String serial, String auth) {

    String check = "default";
    String SQL = "";
    try {//w ww . j  a  va2s. co m

        connection = DBConnection.getDBConnection().getConnection();

        SQL = "select serial from rpi where serial = ? or auth = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, serial);
        preparedStatement.setString(2, auth);
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            check = "Available";
        } else {
            check = "Unavailable";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        check = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return check;

}

From source file:io.github.retz.web.JobRequestHandler.java

static String listJob(spark.Request req, spark.Response res) throws IOException {
    Optional<AuthHeader> authHeaderValue = WebConsole.getAuthInfo(req);
    LOG.debug("list jobs owned by {}", authHeaderValue.get().key());
    ListJobRequest listJobRequest = MAPPER.readValue(req.body(), ListJobRequest.class);
    LOG.debug("q: state={}, tag={}", listJobRequest.state(), listJobRequest.tag());
    String user = Objects.requireNonNull(authHeaderValue.get().key());
    try {//from   ww  w .  ja  va  2 s .  c om
        List<Job> jobs = JobQueue.list(user, listJobRequest.state(), listJobRequest.tag(), MAX_LIST_JOB_SIZE);

        boolean more = false;
        if (jobs.size() > ListJobResponse.MAX_JOB_NUMBER) {
            more = true;
            jobs = jobs.subList(0, ListJobResponse.MAX_JOB_NUMBER);
        }
        ListJobResponse listJobResponse = new ListJobResponse(jobs, more);
        listJobResponse.ok();
        res.status(200);
        res.type("application/json");
        return MAPPER.writeValueAsString(listJobResponse);
    } catch (SQLException e) {
        LOG.error(e.toString(), e);
        res.status(500);
        return "\"Internal Error\"";
    }
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String checkHospitalId(String hospital_id, int sel) {

    String check = "default";
    String SQL = "";
    try {//from  ww  w .  j  av a  2s .  c o m

        connection = DBConnection.getDBConnection().getConnection();
        if (sel == 0) {
            SQL = "select hospital_id from hospital where hospital_id = ?";

        } else if (sel == 1) {
            SQL = "select id from hospital where id = ?";
        } else {
            return check;
        }
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            check = "Available";
        } else {
            check = "Unavailable";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        check = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return check;

}