Example usage for java.sql ResultSet getLong

List of usage examples for java.sql ResultSet getLong

Introduction

In this page you can find the example usage for java.sql ResultSet getLong.

Prototype

long getLong(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a long in the Java programming language.

Usage

From source file:com.jd.survey.dao.survey.QuestionStatisticDAOImp.java

/**
 * Returns frequency statistics for a choice question' answers (Value, Count) 
 * @param question/*  w  ww .ja v  a  2s .c  om*/
 * @return
 */
private List<QuestionStatistic> getFrequencyStatistics(Question question, final Long totalRecordCount) {
    Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId();
    Short pageOrder = question.getPage().getOrder();
    Short questionOrder = question.getOrder();
    final String columnName = "p" + pageOrder + "q" + questionOrder;

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("select d." + columnName + " as col, count(*) as total ");
    stringBuilder.append(" from survey_data_" + surveyDefinitionId
            + " d inner join survey s on (s.id=d.survey_id and s.status='S')");
    stringBuilder.append(" group by d." + columnName);
    String selectSQLStatement = stringBuilder.toString();

    List<QuestionStatistic> questionStatistics = this.jdbcTemplate.query(selectSQLStatement,
            new RowMapper<QuestionStatistic>() {
                public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException {
                    QuestionStatistic questionStatistic = new QuestionStatistic();
                    questionStatistic.setEntry(rs.getString("col"));
                    questionStatistic.setCount(rs.getLong("total"));
                    questionStatistic.setTotalCount(totalRecordCount);
                    return questionStatistic;
                }
            });
    return questionStatistics;

}

From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java

@Override
public Long saveRun(SavedRun savedRun) throws Exception {

    PreparedStatement ps = getConnection()
            .prepareStatement("insert into saved_runs (name, user_id, date) values (?, ?, ?)");

    ps.setString(1, savedRun.getName());
    ps.setLong(2, savedRun.getUserId());
    ps.setTimestamp(3, new Timestamp(savedRun.getDate().getTime()));

    logger.info(ps);/*from   w w  w  .j  a  v a2 s  .  com*/
    ps.executeUpdate();

    ResultSet rs = ps.getGeneratedKeys();

    if (rs.next()) {
        return rs.getLong(1);

    }
    return null;
}

From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java

@Override
public Long createTestRunParameter(Long testRunId, String name, String value, boolean isInput)
        throws Exception {
    PreparedStatement ps = getConnection().prepareStatement(
            "insert into test_run_parameters (test_run_id, name, value, type) values (?,?,?,?)");

    ps.setLong(1, testRunId);/* ww  w.jav a  2 s  . c  o  m*/
    ps.setString(2, name);
    ps.setString(3, value);
    if (isInput) {
        ps.setString(4, "input");
    } else
        ps.setString(4, "output");

    logger.info(ps);
    ps.execute();

    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        return rs.getLong(1);
    }

    return null;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.QcliveAbstractBaseIntegrationTest.java

/**
 * Retrieves a map with archive_info table values 
 *///from   w w  w .  j  av  a  2 s . co m
protected List<Map<String, Object>> retrieveArchiveInfoRecords() {
    logger.info(" retrieveArchiveInfoRecords - IN");
    final List<Map<String, Object>> archiveInfoRecordsList = new ArrayList<Map<String, Object>>();
    localCommonTemplate.query(getArchiveInfoRecords, new RowCallbackHandler() {
        public void processRow(final ResultSet resultSet) throws SQLException {
            final Map<String, Object> elementIdMap = new HashMap<String, Object>();
            elementIdMap.put("ARCHIVE_ID", resultSet.getLong("ARCHIVE_ID"));
            elementIdMap.put("ARCHIVE_NAME", resultSet.getString("ARCHIVE_NAME"));
            elementIdMap.put("ARCHIVE_TYPE_ID", resultSet.getLong("ARCHIVE_TYPE_ID"));
            elementIdMap.put("CENTER_ID", resultSet.getLong("CENTER_ID"));
            elementIdMap.put("DISEASE_ID", resultSet.getLong("DISEASE_ID"));
            elementIdMap.put("PLATFORM_ID", resultSet.getLong("PLATFORM_ID"));
            elementIdMap.put("SERIAL_INDEX", resultSet.getLong("SERIAL_INDEX"));
            elementIdMap.put("REVISION", resultSet.getLong("REVISION"));
            elementIdMap.put("SERIES", resultSet.getLong("SERIES"));
            elementIdMap.put("DATE_ADDED", resultSet.getTimestamp("DATE_ADDED"));
            elementIdMap.put("DEPLOY_STATUS", resultSet.getString("DEPLOY_STATUS"));
            elementIdMap.put("DEPLOY_LOCATION", resultSet.getString("DEPLOY_LOCATION"));
            elementIdMap.put("IS_LATEST", resultSet.getLong("IS_LATEST"));
            elementIdMap.put("IS_LATEST", resultSet.getLong("INITIAL_SIZE_KB"));
            elementIdMap.put("FINAL_SIZE_KB", resultSet.getLong("FINAL_SIZE_KB"));
            elementIdMap.put("IS_LATEST_LOADED", resultSet.getLong("IS_LATEST_LOADED"));
            elementIdMap.put("DATA_LOADED_DATE", resultSet.getDate("DATA_LOADED_DATE"));
            archiveInfoRecordsList.add(elementIdMap);
        }
    });
    logger.info(" retrieveArchiveInfoRecords - OUT");
    return archiveInfoRecordsList;
}

From source file:bizlogic.Records.java

public static void writeCSV(Connection DBcon, String record_id) throws SQLException {

    Statement st;//ww w .  j a v  a 2s.  co  m
    ResultSet rs = null;

    System.out.println("WriteCSV started");

    try {
        st = DBcon.createStatement();
        rs = st.executeQuery("SELECT * FROM PUBLIC.t" + record_id);
        System.out.println("Result set read finished");
    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Records.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    }

    try {

        String DELIMITER = ",";
        String NEW_LINE = "\n";
        String FILE_HEADER = "Time,Series";

        System.out.println("Delete old file");
        FileWriter csvFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/Data/" + record_id + ".csv");

        //BufferedWriter csvFile = new BufferedWriter(
        //        new OutputStreamWriter(new FileOutputStream(new File(
        //                "/var/lib/tomcat8/webapps/ROOT/Records/Data/" + 
        //                        record_id + ".csv"))));

        csvFile.write("");

        csvFile.append(FILE_HEADER);
        csvFile.append(NEW_LINE);

        Calendar calendar = new GregorianCalendar();

        System.out.println("Writing file...");
        while (rs.next()) {

            long time_stamp = rs.getLong("time");
            double value = rs.getDouble("value");
            String _year;
            String _month;
            String _day;
            String _hour;
            String _min;
            String _sec;

            calendar.setTimeInMillis(time_stamp);

            _year = Integer.toString(calendar.get(Calendar.YEAR));
            _month = Integer.toString(calendar.get(Calendar.MONTH) + 1);
            _day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
            _hour = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
            _min = Integer.toString(calendar.get(Calendar.MINUTE));
            _sec = Integer.toString(calendar.get(Calendar.SECOND));

            csvFile.append(_year + "/" + _month + "/" + _day + " " + _hour + ":" + _min + ":" + _sec + DELIMITER
                    + Double.toString(value) + NEW_LINE); //new Date("2009/07/19 12:34:56")

        }
        System.out.print("File written");
        rs.close();
        //csvFile.flush();
        csvFile.close();
    }

    catch (IOException ex) {
        Logger.getLogger(Records.class.getName()).log(Level.WARNING, null, ex);
    }
}

From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java

@Override
public Long createSuiteRun(SuiteRun suite) throws Exception {
    PreparedStatement ps = getConnection().prepareStatement(
            "insert into suite_runs (start_time, end_time, name, runner_id, parameters, agent_name) "
                    + "values (?,?,?,?,?,?)");

    ps.setTimestamp(1, new Timestamp(suite.getStartTime().getTime()));
    ps.setTimestamp(2, new Timestamp(suite.getEndTime().getTime()));
    ps.setString(3, suite.getName());//from   w ww  .  j a  v  a 2s .c o m
    if (suite.getRunnerId() == null)
        suite.setRunnerId(0L);
    ps.setLong(4, suite.getRunnerId());
    ps.setString(5, suite.getParameters());
    String agentName = suite.getAgentName();
    if (agentName == null) {
        agentName = "";
    }
    ps.setString(6, agentName);

    logger.info(ps);
    ps.execute();

    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        return rs.getLong(1);
    }
    return null;
}

From source file:com.oic.event.GetProfile.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    if (!validation(json)) {
        responseJSON.put("status", "1");
        webSocket.sendJson(responseJSON);
        return;//from  ww w. j a v  a2s  . c om
    }
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        String sql = "SELECT user.userid, name, avatarid, grade, sex, birth, comment, privategrade, privatesex, privatebirth FROM user JOIN setting ON (user.userid = setting.userid) WHERE user.userid = ?;";
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement(sql);
        ps.setLong(1, Long.parseLong(json.get("userid").toString()));
        rs = ps.executeQuery();

        if (rs.next()) {
            responseJSON.put("userid", rs.getLong("userid"));
            responseJSON.put("username", rs.getString("name"));
            responseJSON.put("avatarid", rs.getInt("avatarid"));
            if (rs.getString("privategrade").equals("public")) {
                responseJSON.put("grade", rs.getInt("grade"));
            }
            if (rs.getString("privatesex").equals("public")) {
                responseJSON.put("gender", OicGender.getGender(rs.getString("sex")).toString());
            }
            if (rs.getString("privatebirth").equals("public")) {
                responseJSON.put("birthday", Tools.convertData(rs.getDate("birth")));
            }
            responseJSON.put("comment", rs.getString("comment"));
            responseJSON.put("status", 0);
        } else {
            responseJSON.put("status", 1);
        }
    } catch (SQLException se) {
        responseJSON.put("status", 1);
        se.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception e1) {
        }
        try {
            ps.close();
        } catch (Exception e1) {
        }
    }
    webSocket.sendJson(responseJSON);
}

From source file:com.its.core.local.hezhou.task.ExportImageFilesReadTaskNew.java

private List<VehicelRecordBean> getExportRecordList(Connection conn) throws Exception {
    List<VehicelRecordBean> recordList = new ArrayList<VehicelRecordBean>();
    PreparedStatement preStatement = null;
    ResultSet rs = null;
    try {//  ww  w  .  j  a v  a2s .c  o  m
        //         log.debug(""+this.getSelecImageFileRecordSql());
        preStatement = conn.prepareStatement(this.getSelecImageFileRecordSql());
        rs = preStatement.executeQuery();

        while (rs.next()) {
            VehicelRecordBean record = new VehicelRecordBean();
            record.setId(rs.getLong("ID"));
            record.setDeviceIp(rs.getString("DeviceIP"));
            record.setPlate(rs.getString("LicenseNumber"));
            record.setPlateColorCode(rs.getString("LicenseColor"));
            record.setDirectionCode(rs.getString("Direction"));
            record.setCatchTime(rs.getTimestamp("CatchDate"));
            record.setDrivewayNo(rs.getString("RoadId"));
            record.setSpeed(rs.getString("Speed"));
            record.setFeatureImagePath(rs.getString("ImagePath"));
            recordList.add(record);
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        throw ex;
    } finally {
        DatabaseHelper.close(rs, preStatement);
    }
    return recordList;
}

From source file:it.univaq.servlet.Modifica_pub.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
    try {/*from  w ww  .  j a  v  a 2  s. co m*/
        HttpSession s = SecurityLayer.checkSession(request);
        Map data = new HashMap();
        int id = 0;

        data.put("tipologia", DataUtil.getTipologiaByEmail((String) s.getAttribute("email")));
        if (s != null && DataUtil.getTipologiaByEmail((String) s.getAttribute("username")) != 0) {
            if (action_upload(request)) {
                data.put("sessione", s.getAttribute("username"));
                response.sendRedirect("catalogo");

            } else {
                data.put("sessione", s.getAttribute("username"));
                //prendo tutti i dati di una pubblicazione per permettere la  modifica
                id = Integer.parseInt(request.getParameter("id"));
                request.setAttribute("id", id);
                ResultSet rs = Database.selectRecord("pubblicazione", "id=" + id);
                String titolo = null, autore = null, descrizione = null;
                int keyword = 0;
                while (rs.next()) {
                    titolo = rs.getString("titolo");
                    autore = rs.getString("autore");
                    descrizione = rs.getString("descrizione");
                    keyword = rs.getInt("keyword");

                }
                Pubblicazione pub = new Pubblicazione(id, titolo, autore, descrizione, keyword);
                data.put("pubblicazione", pub);

                //prendo tutti dati ristampa

                ResultSet rs2 = Database.selectRecord("ristampa", "idpub=" + id);
                long isbn = 0;
                int numpagine = 0;
                String editore = null, lingua = null;
                String datapub = null;
                while (rs2.next()) {
                    isbn = rs2.getLong("isbn");
                    numpagine = rs2.getInt("numpagine");
                    editore = rs2.getString("editore");
                    lingua = rs2.getString("lingua");
                    datapub = DataUtil.dateToString(rs2.getDate("datapub"));
                }
                Ristampa rist = new Ristampa(isbn, numpagine, lingua, editore, datapub);
                data.put("ristampa", rist);

                //prendo keywords

                ResultSet rs3 = Database.selectRecord("keyword", "id=" + keyword);
                String key1 = null, key2 = null, key3 = null, key4 = null;
                while (rs3.next()) {
                    key1 = rs3.getString("key1");
                    key2 = rs3.getString("key2");
                    key3 = rs3.getString("key3");
                    key4 = rs3.getString("key4");
                }

                ParoleChiave keywords = new ParoleChiave(keyword, key1, key2, key3, key4);
                data.put("keyword", keywords);

                FreeMarker.process("modifica_pub.html", data, response, getServletContext());

            }
        } else
            action_error(request, response);
    } catch (Exception ex) {
        Logger.getLogger(Modifica_pub.class.getName()).log(Level.SEVERE, null, ex);

    }
}