List of usage examples for java.sql ResultSet getInt
int getInt(String columnLabel) throws SQLException;
ResultSet
object as an int
in the Java programming language. From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryObjectRatingCount(Connection db, int objectId, String table, String uniqueField) throws SQLException { int count = -1; PreparedStatement pst = db/*from w ww .j a v a 2 s. c o m*/ .prepareStatement("SELECT rating_count FROM " + table + " WHERE " + uniqueField + " = ? "); pst.setInt(1, objectId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("rating_count"); } rs.close(); pst.close(); return count; }
From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryObjectRatingValue(Connection db, int objectId, String table, String uniqueField) throws SQLException { int count = -1; PreparedStatement pst = db/*from w w w. j a v a 2s . c o m*/ .prepareStatement("SELECT rating_value FROM " + table + " " + "WHERE " + uniqueField + " = ? "); pst.setInt(1, objectId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("rating_value"); } rs.close(); pst.close(); return count; }
From source file:jp.co.acroquest.endosnipe.data.dao.AbstractDao.java
/** * ?????????<br />//from w w w . ja v a 2 s. c o m * * @param database ?? * @param sequenceName ?? * @return ???????????????? <code>-1</code> * @throws SQLException SQL ????? */ protected static int createValueFromSequenceId(final String database, final String sequenceName) throws SQLException { Connection conn = null; Statement stmt = null; ResultSet rs = null; int newMeasurementItemId = -1; try { conn = getConnection(database); stmt = conn.createStatement(); String sql = ConnectionManager.getInstance().getSequenceSql(sequenceName); rs = stmt.executeQuery(sql); if (rs.next() == true) { newMeasurementItemId = rs.getInt(1); } } finally { SQLUtil.closeResultSet(rs); SQLUtil.closeStatement(stmt); SQLUtil.closeConnection(conn); } return newMeasurementItemId; }
From source file:at.becast.youploader.database.SQLite.java
public static int addUpload(File file, Video data, VideoMetadata metadata, Date startAt) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "INSERT INTO `uploads` (`account`, `file`, `lenght`, `data`,`enddir`, `metadata`, `status`,`starttime`) " + "VALUES (?,?,?,?,?,?,?,?)"; prest = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); prest.setInt(1, metadata.getAccount()); prest.setString(2, file.getAbsolutePath()); prest.setLong(3, file.length());//ww w . j a v a2s .c o m prest.setString(4, mapper.writeValueAsString(data)); prest.setString(5, metadata.getEndDirectory()); prest.setString(6, mapper.writeValueAsString(metadata)); prest.setString(7, UploadManager.Status.NOT_STARTED.toString()); if (startAt == null) { prest.setString(8, ""); } else { prest.setDate(8, new java.sql.Date(startAt.getTime())); } prest.execute(); ResultSet rs = prest.getGeneratedKeys(); prest.close(); if (rs.next()) { int id = rs.getInt(1); rs.close(); return id; } else { return -1; } }
From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryUserRating(Connection db, int userId, int objectId, String table, String uniqueField) throws SQLException { int existingVote = -1; PreparedStatement pst = db.prepareStatement( "SELECT rating FROM " + table + "_rating WHERE " + uniqueField + " = ? AND enteredby = ? "); pst.setInt(1, objectId);// w ww. j a v a 2s.c o m pst.setInt(2, userId); ResultSet rs = pst.executeQuery(); if (rs.next()) { existingVote = rs.getInt("rating"); } rs.close(); pst.close(); return existingVote; }
From source file:com.l2jserver.model.template.NPCTemplateConverter.java
private static Droplist fillDropList(final ObjectFactory factory, ResultSet npcRs, int npcId) throws SQLException { final Connection conn = npcRs.getStatement().getConnection(); final Droplist drops = factory.createNPCTemplateDroplist(); final PreparedStatement st = conn.prepareStatement("SELECT * FROM droplist WHERE mobId = ?"); st.setInt(1, npcId);//from w ww.j a va2 s . c o m st.execute(); final ResultSet rs = st.getResultSet(); while (rs.next()) { final Droplist.Item item = factory.createNPCTemplateDroplistItem(); item.setId(new ItemTemplateID(rs.getInt("itemId"), null)); item.setMin(rs.getInt("min")); item.setMax(rs.getInt("max")); item.setChance(rs.getInt("chance")); item.setCategory(getCategory(rs.getInt("category"))); drops.getItem().add(item); } if (drops.getItem().size() == 0) return null; return drops; }
From source file:com.winit.vms.base.db.mybatis.support.SQLHelp.java
/** * /*from ww w . j a v a 2 s . c om*/ * * @param sql SQL? * @param mappedStatement mapped * @param parameterObject ? * @param boundSql boundSql * @param dialect database dialect * @return * @throws java.sql.SQLException sql */ public static int getCount(final String sql, final MappedStatement mappedStatement, final Object parameterObject, final BoundSql boundSql, Dialect dialect) throws SQLException { final String count_sql = dialect.getCountString(sql); logger.debug("Total count SQL [{}] ", count_sql); logger.debug("Total count Parameters: {} ", parameterObject); DataSource dataSource = mappedStatement.getConfiguration().getEnvironment().getDataSource(); Connection connection = DataSourceUtils.getConnection(dataSource); PreparedStatement countStmt = null; ResultSet rs = null; try { countStmt = connection.prepareStatement(count_sql); //Page SQLCount SQL???boundSql DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql); handler.setParameters(countStmt); rs = countStmt.executeQuery(); int count = 0; if (rs.next()) { count = rs.getInt(1); } logger.debug("Total count: {}", count); return count; } finally { try { if (rs != null) { rs.close(); } } finally { try { if (countStmt != null) { countStmt.close(); } } finally { DataSourceUtils.releaseConnection(connection, dataSource); } } } }
From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java
public static void exemappingmodel() { boolean clean_files = false; Map<Integer, String> Master_ModelList = new HashMap<Integer, String>(); try {//from ww w . j ava2 s.co m Class.forName("org.sqlite.JDBC"); log.info("TestCase DB Location" + mp.getProperty("MODEL_DB_LOCATION")); alm_test_location = mp.getProperty("ALM_FORMAT_STORE_LOC"); Jelly_Tests_location = mp.getProperty("JELLY_TESTS_LOCATION"); CLEAN_JELLY_TESTS = mp.getProperty("CLEAN_JELLY_TESTS"); if (CLEAN_JELLY_TESTS.toLowerCase().equals("yes")) { clean_files = true; } connection = DriverManager.getConnection("jdbc:sqlite:" + mp.getProperty("MODEL_DB_LOCATION")); // int GID_int = Integer.parseInt(GID); Statement Master_statement = connection.createStatement(); ResultSet rs_master = Master_statement.executeQuery( "SELECT GID,FEATURENAME FROM DM_MASTERMODELXML_REF WHERE TESTCASE_GEN_STATUS LIKE 'COMPLETED' AND JELLYCASE_GEN_STATUS IS NULL ORDER BY GID"); while (rs_master.next()) { Master_ModelList.put(rs_master.getInt("GID"), rs_master.getString("FEATURENAME")); } rs_master = null; Master_statement = null; // connection.close(); } catch (SQLException e) { log.error("Error in getting data from DM_MASTERMODELXML_REF table to generate Jelly and ALM TESTS"); } catch (ClassNotFoundException e) { log.error("Exception in exemapping model function" + e.getMessage()); } if (Master_ModelList.isEmpty()) { log.info( "********************************************************************************************************************************************"); log.info( "Jelly Testcases are already generated for all the Models; Please check the column status \"JELLYCASE_GEN_STATUS\" in \"DM_MASTERMODELXML_REF\""); log.info( "********************************************************************************************************************************************"); throw new RuntimeException("Runtime Exception"); // System.exit(0); } for (int key : Master_ModelList.keySet()) { GenerateJellyTests.CreateJellyTestsFolder(Jelly_Tests_location, clean_files, Master_ModelList.get(key)); temp_jelly_Tests_location = Jelly_Tests_location + Master_ModelList.get(key); glb_Feature_Name = Master_ModelList.get(key); log.info("Started generating Jelly Tests for the Feature::" + glb_Feature_Name); log.info("***************************************************"); genjellyTests(String.valueOf(key), Master_ModelList.get(key)); try { DatabaseUtils.UpdateSingleValue("DM_MASTERMODELXML_REF", "COMPLETED", "JELLYCASE_GEN_STATUS", "GID", String.valueOf(key)); } catch (ClassNotFoundException e) { log.error("Exception in updating DM_MASTERMODELXML_REF table" + e.getMessage()); } log.info("End of generating Jelly Tests for the Feature::" + glb_Feature_Name); } }
From source file:module.entities.NameFinder.DB.java
/** * Starts the activity log//from w w w. j a v a 2s . co m * * @param startTime - The start time of the crawling procedure * @return - The activity's log id * @throws java.sql.SQLException */ public static int LogRegexFinder(long startTime) throws SQLException { String insertLogSql = "INSERT INTO log.activities (module_id, start_date, end_date, status_id, message) VALUES (?,?,?,?,?)"; PreparedStatement prepLogCrawlStatement = connection.prepareStatement(insertLogSql, Statement.RETURN_GENERATED_KEYS); prepLogCrawlStatement.setInt(1, 4); prepLogCrawlStatement.setTimestamp(2, new java.sql.Timestamp(startTime)); prepLogCrawlStatement.setTimestamp(3, null); prepLogCrawlStatement.setInt(4, 1); prepLogCrawlStatement.setString(5, null); prepLogCrawlStatement.executeUpdate(); ResultSet rsq = prepLogCrawlStatement.getGeneratedKeys(); int crawlerId = 0; if (rsq.next()) { crawlerId = rsq.getInt(1); } prepLogCrawlStatement.close(); return crawlerId; }
From source file:fll.db.NonNumericNominees.java
/** * Get all nominees in the specified category. * //from w w w . j a va2 s.c o m * @throws SQLException */ public static Set<Integer> getNominees(final Connection connection, final int tournamentId, final String category) throws SQLException { final Set<Integer> result = new HashSet<>(); PreparedStatement get = null; ResultSet rs = null; try { get = connection.prepareStatement( "SELECT DISTINCT team_number FROM non_numeric_nominees" + " WHERE tournament = ?" // + " AND category = ?"); get.setInt(1, tournamentId); get.setString(2, category); rs = get.executeQuery(); while (rs.next()) { final int team = rs.getInt(1); result.add(team); } } finally { SQLFunctions.close(rs); SQLFunctions.close(get); } return result; }