List of usage examples for java.sql ResultSet first
boolean first() throws SQLException;
ResultSet
object. From source file:org.sakaiproject.evalgroup.providers.SimpleEvalGroupProviderImpl.java
public int countEvalGroupsForUser(String userId, String permission) { Connection conn;//from w w w .j a va 2 s. co m ResultSet result; int count = 0; try { conn = dataSource.getConnection(); String userEid = this.getUserEid(userId); Statement statement = conn.createStatement(); result = statement .executeQuery("SELECT count(*) as total from GRP_PROVIDER_group_membership where user_eid = '" + userEid + "';"); result.first(); count = result.getInt("total"); conn.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } return count; }
From source file:org.integratedmodelling.sql.SQLServer.java
public boolean haveTable(String tableName) throws ThinklabStorageException { boolean ret = false; Connection conn = getConnection(); ResultSet rset = null; try {//from ww w. j a v a 2 s . c o m rset = conn.getMetaData().getTables(null, null, tableName, null); ret = rset.first(); } catch (SQLException e) { } finally { try { rset.close(); conn.close(); } catch (Exception e) { } } return ret; }
From source file:servlets.Install_servlets.java
/** * ************************************************************************** **************************************************************************** * USER LOG-IN HANDLER/*from w ww. jav a2 s .com*/ * *************************************************************************** * ************************************************************************** */ private void checkInstallationValidityPostHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Properties properties = new Properties(); properties.load(DBConnectionManager.class.getResourceAsStream("/conf/data_location.properties")); String data_location = properties.getProperty("data_location"); File f = new File(data_location + "/db_config.properties"); boolean is_valid = f.exists(); String install_type = "install"; String is_docker = System.getenv("is_docker"); if (is_valid) { //COMPARE IF DATABASE VERSION IS SAME THAT APP VERSION BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(DBConnectionManager.class.getResourceAsStream("/conf/version.info"))); bufferedReader.readLine(); //ignore first line String codeVersion = new StringBuffer().append(bufferedReader.readLine()).toString().replace("v", ""); String installedVersion = "0"; try { PreparedStatement ps = (PreparedStatement) DBConnectionManager.getConnectionManager() .prepareStatement("SELECT version FROM appVersion;"); ResultSet rs = (ResultSet) DBConnectionManager.getConnectionManager().execute(ps, true); if (rs.first()) { installedVersion = rs.getString("version"); } if (!codeVersion.equalsIgnoreCase(installedVersion)) { is_valid = false; install_type = "upgrade"; } } catch (SQLException e) { is_valid = false; } } JsonObject obj = new JsonObject(); obj.add("success", new JsonPrimitive(is_valid)); obj.add("installation_type", new JsonPrimitive(install_type)); obj.add("is_docker", new JsonPrimitive("true".equals(is_docker))); // obj.add("is_docker", new JsonPrimitive(true)); response.getWriter().print(obj.toString()); }
From source file:ua.aits.Carpath.model.ArchiveArticleModel.java
public ArchiveArticleModel getOneArticleByID(String id) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, ParseException { ResultSet result = DB.getResultSet("SELECT * FROM archive_articles WHERE archive_articles.article_id = " + id + " AND archive_articles.article_is_delete = 0"); result.first(); ArchiveArticleModel temp = new ArchiveArticleModel(); temp.setArticle_id(result.getInt("article_id")); temp.setArticle_title_en(result.getString("article_title_EN").replace("\"", """)); temp.setArticle_title_ua(result.getString("article_title_UA").replace("\"", """)); temp.setArticle_title_hu(result.getString("article_title_HU").replace("\"", """)); temp.setArticle_title_sk(result.getString("article_title_SK").replace("\"", """)); temp.setArticle_title_ro(result.getString("article_title_RO").replace("\"", """)); temp.setArticle_text_en(result.getString("article_text_EN")); temp.setArticle_text_ua(result.getString("article_text_UA")); temp.setArticle_text_hu(result.getString("article_text_HU")); temp.setArticle_text_sk(result.getString("article_text_SK")); temp.setArticle_text_ro(result.getString("article_text_RO")); temp.setArticle_category(result.getInt("article_category")); temp.setArticle_author(result.getString("article_author")); temp.setArticle_editor(result.getString("article_editor")); temp.setArticle_add_date(result.getString("article_add_date")); temp.setArticle_edit_date(result.getString("article_edit_date")); temp.setArticle_is_edit(result.getInt("article_is_edit")); temp.setArticle_is_delete(result.getInt("article_is_delete")); temp.setArticle_is_publish(result.getInt("article_is_publish")); temp.setArticle_dir(result.getString("article_dir")); temp.setArticle_country(result.getString("article_country")); temp.setArticle_region(result.getString("article_region")); temp.setArticle_district(result.getString("article_district")); temp.setArticle_town(result.getString("article_town")); temp.setArticle_x(result.getDouble("article_x")); temp.setArticle_y(result.getDouble("article_y")); if (temp.article_x == 0) { temp.setArticle_x(50.4501);//from w w w .ja v a2 s. co m temp.setArticle_y(30.523400000000038); } DB.closeCon(); return temp; }
From source file:br.org.indt.ndg.server.client.TemporaryOpenRosaBussinessDelegate.java
public String getFormattedSurvey(String formId, String imei) { String result = null;//from ww w.j a v a 2 s .c o m PreparedStatement selectSurveyWithIdStmt = null; PreparedStatement deleteSurveyForImeiStmt = null; Connection conn = null; try { conn = getDbConnection(); selectSurveyWithIdStmt = conn.prepareStatement(SELECT_SURVEY_WITH_ID_STATEMENT, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); selectSurveyWithIdStmt.setString(1, formId); ResultSet results = selectSurveyWithIdStmt.executeQuery(); if (results.first()) { result = results.getString(SURVEY_CONTENT_COLUMN); // remove survey from available to download for this user deleteSurveyForImeiStmt = conn.prepareStatement(DELETE_SURVEYS_FOR_IMEI); deleteSurveyForImeiStmt.setString(1, formId); deleteSurveyForImeiStmt.setString(2, imei); deleteSurveyForImeiStmt.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { selectSurveyWithIdStmt.close(); conn.close(); } catch (Exception e) { } } return result; }
From source file:com.tascape.reactor.report.MySqlBaseBean.java
public void importJson(JSONObject json) throws NamingException, SQLException { JSONObject sr = json.getJSONObject("suite_result"); String srid = sr.getString(SuiteResult.SUITE_RESULT_ID); LOG.debug("srid {}", srid); try (Connection conn = this.getConnection()) { String sql = "SELECT * FROM " + SuiteResult.TABLE_NAME + " WHERE " + SuiteResult.SUITE_RESULT_ID + " = ?;"; PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setString(1, srid);// w w w.ja va 2 s. c o m ResultSet rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); if (rs.first()) { LOG.debug("already imported {}", srid); return; } rs.moveToInsertRow(); for (int col = 1; col <= rsmd.getColumnCount(); col++) { String cn = rsmd.getColumnLabel(col); rs.updateObject(cn, sr.opt(cn)); } rs.insertRow(); rs.last(); rs.updateRow(); LOG.debug("sr imported"); } try (Connection conn = this.getConnection()) { String sql = "SELECT * FROM " + SuiteProperty.TABLE_NAME + " WHERE " + SuiteProperty.SUITE_RESULT_ID + " = ?;"; PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setString(1, srid); ResultSet rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); JSONArray sps = sr.getJSONArray("suite_properties"); int len = sps.length(); for (int i = 0; i < len; i++) { rs.moveToInsertRow(); JSONObject tr = sps.getJSONObject(i); for (int col = 1; col <= rsmd.getColumnCount(); col++) { String cn = rsmd.getColumnLabel(col); if (SuiteProperty.SUITE_PROPERTY_ID.equals(cn)) { continue; } rs.updateObject(cn, tr.get(cn)); } rs.insertRow(); rs.last(); rs.updateRow(); } LOG.debug("sps imported"); } JSONArray trs = sr.getJSONArray("case_results"); int len = trs.length(); try (Connection conn = this.getConnection()) { String sql = String.format("SELECT * FROM %s WHERE %s=? AND %s=? AND %s=? AND %s=? AND %s=?;", TaskCase.TABLE_NAME, TaskCase.SUITE_CLASS, TaskCase.CASE_CLASS, TaskCase.CASE_METHOD, TaskCase.CASE_DATA_INFO, TaskCase.CASE_DATA); PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setMaxRows(1); for (int i = 0; i < len; i++) { JSONObject tr = trs.getJSONObject(i); stmt.setString(1, tr.getString(TaskCase.SUITE_CLASS)); stmt.setString(2, tr.getString(TaskCase.CASE_CLASS)); stmt.setString(3, tr.getString(TaskCase.CASE_METHOD)); stmt.setString(4, tr.getString(TaskCase.CASE_DATA_INFO)); stmt.setString(5, tr.getString(TaskCase.CASE_DATA)); ResultSet rs = stmt.executeQuery(); if (!rs.first()) { rs.moveToInsertRow(); rs.updateString(TaskCase.SUITE_CLASS, tr.getString(TaskCase.SUITE_CLASS)); rs.updateString(TaskCase.CASE_CLASS, tr.getString(TaskCase.CASE_CLASS)); rs.updateString(TaskCase.CASE_METHOD, tr.getString(TaskCase.CASE_METHOD)); rs.updateString(TaskCase.CASE_DATA_INFO, tr.getString(TaskCase.CASE_DATA_INFO)); rs.updateString(TaskCase.CASE_DATA, tr.getString(TaskCase.CASE_DATA)); rs.insertRow(); rs.last(); rs.updateRow(); rs = stmt.executeQuery(); rs.first(); } tr.put(TaskCase.TASK_CASE_ID, rs.getLong(TaskCase.TASK_CASE_ID)); } LOG.debug("tcid updated"); } try (Connection conn = this.getConnection()) { String sql = "SELECT * FROM " + CaseResult.TABLE_NAME + " WHERE " + CaseResult.SUITE_RESULT + " = ?;"; PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setString(1, srid); ResultSet rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 0; i < len; i++) { rs.moveToInsertRow(); JSONObject tr = trs.getJSONObject(i); for (int col = 1; col <= rsmd.getColumnCount(); col++) { String cn = rsmd.getColumnLabel(col); rs.updateObject(cn, tr.opt(cn)); } rs.insertRow(); rs.last(); rs.updateRow(); } LOG.debug("crs imported"); } try (Connection conn = this.getConnection()) { String sql = "SELECT * FROM " + CaseResultMetric.TABLE_NAME + ";"; PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setMaxRows(1); ResultSet rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 0; i < len; i++) { JSONArray jarr = trs.getJSONObject(i).optJSONArray("CASE_result_metrics"); if (jarr == null) { continue; } int l = jarr.length(); for (int j = 0; j < l; j++) { JSONObject trm = jarr.getJSONObject(j); rs.moveToInsertRow(); for (int col = 1; col <= rsmd.getColumnCount(); col++) { String cn = rsmd.getColumnLabel(col); if (cn.equals(CaseResultMetric.CASE_RESULT_METRIC_ID)) { continue; } rs.updateObject(cn, trm.get(cn)); } rs.insertRow(); rs.last(); rs.updateRow(); } } LOG.debug("crms imported"); } }
From source file:br.org.indt.ndg.server.client.TemporaryOpenRosaBussinessDelegate.java
public String[] getUserList() { String[] userImeis = null;/*from w w w.j a v a 2 s. c o m*/ List<String> tempResults = new ArrayList<String>(); PreparedStatement listUsersStmt = null; Connection conn = null; try { conn = getDbConnection(); listUsersStmt = conn.prepareStatement(SELECT_ALL_USERS_STATEMENT, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet surveysSet = listUsersStmt.executeQuery(); boolean isValidRow = surveysSet.first(); while (isValidRow) { tempResults.add(surveysSet.getString(IMEI_COLUMN)); isValidRow = surveysSet.next(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { listUsersStmt.close(); conn.close(); } catch (Exception e) { } } userImeis = tempResults.toArray(new String[tempResults.size()]); return userImeis; }
From source file:br.org.indt.ndg.server.client.TemporaryOpenRosaBussinessDelegate.java
public Map<String, String> getSurveyIdToUrlMap() { Map<String, String> surveyIdsToUrlMap = new HashMap<String, String>(); PreparedStatement listSurveysStmt = null; Connection conn = null;//from www . j a v a2s .com try { conn = getDbConnection(); listSurveysStmt = conn.prepareStatement(SELECT_ALL_SURVEYS_STATEMENT, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet surveysSet = listSurveysStmt.executeQuery(); boolean isValidRow = surveysSet.first(); final String FAKE_DEVICE_ID = "0"; while (isValidRow) { String surveyId = surveysSet.getString(SURVEY_ID_COLUMN); surveyIdsToUrlMap.put(surveyId, getSurveyDownloadUrl(FAKE_DEVICE_ID, surveyId)); isValidRow = surveysSet.next(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { listSurveysStmt.close(); conn.close(); } catch (Exception e) { } } return surveyIdsToUrlMap; }
From source file:sopho.Ofeloumenoi.AddOfeloumenoiController.java
public BufferedImage bfImage(String rand) { BufferedImage img = null; //Buffered image coming from database InputStream fis = null;//from w ww.j a v a2 s . c o m try { ResultSet rs; sopho.DBClass db = new sopho.DBClass(); Connection conn = db.ConnectDB(); String sql = "SELECT * FROM images WHERE photoID =?"; PreparedStatement pst = conn.prepareStatement(sql); pst.setString(1, rand); rs = pst.executeQuery(); rs.first(); fis = rs.getBinaryStream("image"); img = javax.imageio.ImageIO.read(fis); //create the BufferedImaged } catch (SQLException | IOException e) { System.err.println("error " + e); } return img; //function returns a BufferedImage object }
From source file:ua.aits.Carpath.model.ArchiveArticleModel.java
public String deleteArticle(String id) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException { ResultSet result = DB.getResultSet( "SELECT archive_articles.article_id, archive_articles.article_category, archive_articles.article_dir FROM archive_articles WHERE archive_articles.article_id = " + id + ";"); result.first(); DB.runQuery("UPDATE `archive_articles` SET `article_is_delete`= 1 WHERE article_id = " + id + ";"); String category = result.getString("article_category"); DB.closeCon();/*from w w w. j a v a 2 s. c om*/ return category; }