List of usage examples for java.sql PreparedStatement executeQuery
ResultSet executeQuery() throws SQLException;
PreparedStatement
object and returns the ResultSet
object generated by the query. From source file:com.concursive.connect.web.modules.documents.dao.FileItemList.java
/** * Returns the number of fileItems that match the module and itemid * * @param db Description of the Parameter * @param linkModuleId Description of the Parameter * @param linkItemId Description of the Parameter * @return Description of the Return Value * @throws SQLException Description of the Exception *///from w w w.j a v a2 s. c o m public static int retrieveRecordCount(Connection db, int linkModuleId, int linkItemId) throws SQLException { int count = 0; PreparedStatement pst = db.prepareStatement("SELECT COUNT(*) as filecount " + "FROM project_files pf " + "WHERE pf.link_module_id = ? and pf.link_item_id = ? "); pst.setInt(1, linkModuleId); pst.setInt(2, linkItemId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("filecount"); } rs.close(); pst.close(); return count; }
From source file:fll.db.NonNumericNominees.java
/** * Add a set of nominees to the database. If the nominee already exsts, there * is no error.//from w ww . j a va 2s. c o m * * @throws SQLException */ public static void addNominees(final Connection connection, final int tournamentId, final String category, final Set<Integer> teamNumbers) throws SQLException { PreparedStatement check = null; ResultSet checkResult = null; PreparedStatement insert = null; final boolean autoCommit = connection.getAutoCommit(); try { connection.setAutoCommit(false); check = connection.prepareStatement("SELECT team_number FROM non_numeric_nominees" // + " WHERE tournament = ?" // + " AND category = ?" // + " AND team_number = ?"); check.setInt(1, tournamentId); check.setString(2, category); insert = connection.prepareStatement("INSERT INTO non_numeric_nominees" // + " (tournament, category, team_number) VALUES(?, ?, ?)"); insert.setInt(1, tournamentId); insert.setString(2, category); for (final int teamNumber : teamNumbers) { check.setInt(3, teamNumber); insert.setInt(3, teamNumber); checkResult = check.executeQuery(); if (!checkResult.next()) { insert.executeUpdate(); } } connection.commit(); } finally { connection.setAutoCommit(autoCommit); SQLFunctions.close(checkResult); SQLFunctions.close(check); SQLFunctions.close(insert); } }
From source file:com.keybox.manage.db.ProfileDB.java
/** * method to do order by based on the sorted set object for profiles * @return list of profiles//from w w w . j ava2 s. com */ public static SortedSet getProfileSet(SortedSet sortedSet) { ArrayList<Profile> profileList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select distinct p.* from profiles p "; if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) { sql = sql + ", system_map m, system s where m.profile_id = p.id and m.system_id = s.id" + " and (lower(s.display_nm) like ? or lower(s.host) like ?)"; } else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) { sql = sql + ", user_map m, users u where m.profile_id = p.id and m.user_id = u.id" + " and (lower(u.first_nm) like ? or lower(u.last_nm) like ?" + " or lower(u.email) like ? or lower(u.username) like ?)"; } sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) { stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%"); stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%"); } else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) { stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(3, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(4, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { Profile profile = new Profile(); profile.setId(rs.getLong("id")); profile.setNm(rs.getString("nm")); profile.setDesc(rs.getString("desc")); profileList.add(profile); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } sortedSet.setItemList(profileList); return sortedSet; }
From source file:com.l2jfree.gameserver.datatables.LevelUpData.java
private LevelUpData() { _lvlTable = new FastMap<Integer, L2LvlupData>(); Connection con = null;//from ww w . j av a 2 s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement(SELECT_ALL); ResultSet rset = statement.executeQuery(); L2LvlupData lvlDat; while (rset.next()) { lvlDat = new L2LvlupData(); lvlDat.setClassid(rset.getInt(CLASS_ID)); lvlDat.setClassLvl(rset.getInt(CLASS_LVL)); lvlDat.setClassHpBase(rset.getFloat(HP_BASE)); lvlDat.setClassHpAdd(rset.getFloat(HP_ADD)); lvlDat.setClassHpModifier(rset.getFloat(HP_MOD)); lvlDat.setClassCpBase(rset.getFloat(CP_BASE)); lvlDat.setClassCpAdd(rset.getFloat(CP_ADD)); lvlDat.setClassCpModifier(rset.getFloat(CP_MOD)); lvlDat.setClassMpBase(rset.getFloat(MP_BASE)); lvlDat.setClassMpAdd(rset.getFloat(MP_ADD)); lvlDat.setClassMpModifier(rset.getFloat(MP_MOD)); _lvlTable.put(lvlDat.getClassid(), lvlDat); } rset.close(); statement.close(); _log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates."); } catch (Exception e) { _log.error("error while creating Lvl up data table ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.citrix.cpbm.custom.reports.CustomerReport.java
@Override protected ResultSet executeQuery(Statement statement) throws SQLException { PreparedStatement pstmt = (PreparedStatement) statement; return pstmt.executeQuery(); }
From source file:com.uit.anonymousidentity.Repository.IssuerKeys.IssuerJDBCTemplate.java
@Override public Issuer getIssuerBySID(String sid) throws SQLException, NoSuchAlgorithmException { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. String sql = "select * from " + TABLE_NAME + " where " + SID + " = " + "'" + sid + "'"; PreparedStatement pst = dataSource.getConnection().prepareStatement(sql); ResultSet rs = pst.executeQuery(); if (rs.next()) { BNCurve curve = BNCurve.createBNCurveFromName(rs.getString(BNCurveName)); Issuer.IssuerPublicKey ipk = new Issuer.IssuerPublicKey(curve, rs.getString(PK)); Issuer.IssuerSecretKey isk = new Issuer.IssuerSecretKey(curve, rs.getString(SK)); Issuer i = new Issuer(curve, isk, ipk); i.setSid(sid);//w ww.j a va 2 s . c o m return i; } else { return null; } }
From source file:dao.MaterialDaoImplem.java
@Override public List<Material> selectMaterials() { try (Connection connection = dataSource.getConnection()) { String query = ("select * from material m"); PreparedStatement stat = connection.prepareStatement(query); ResultSet res = stat.executeQuery(); List<Material> materials = new ArrayList<>(); while (res.next()) { Material material = new Material(); material.setId_material(res.getInt(1)); material.setName(res.getString(2)); material.setWeight(res.getInt(3)); material.setManufacturer(res.getString(4)); material.setCost(res.getInt(5)); material.setQuantity(res.getInt(6)); materials.add(material);//www . j av a 2 s . co m } return materials; } catch (Exception e) { throw new RuntimeException("Error:selectMaterials", e); } }
From source file:oobbit.orm.Categories.java
public List<Category> getAll(int limit) throws SQLException { PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM oobbit.links LIMIT ?;"); statement.setInt(1, limit);/*w ww . j ava 2 s . co m*/ return parseResultSet(statement.executeQuery()); }
From source file:mx.com.pixup.portal.dao.ArtistaGenerateDaoJdbc.java
public void generateXML() { //querys/* ww w . j av a 2s.co m*/ String sql = "select * from artista"; try { //seccion de preparacion de la query Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery(); //seccion de nodo raiz Element artistas = new Element("artistas"); this.xmlLogico.setRootElement(artistas); while (resultSet.next()) { //aqu se hace la magia para el XML Element artista = new Element("artista"); Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id"))); artista.setAttribute(id); Element nombre_artistico = new Element("nombre_artistico"); nombre_artistico.setText(resultSet.getString("nombre_artistico")); artista.addContent(nombre_artistico); Element descripcion = new Element("descripcion"); descripcion.setText(resultSet.getString("descripcion")); artista.addContent(descripcion); artistas.addContent(artista); } //se genera el xml fsico this.xmlFisico.setFormat(Format.getPrettyFormat()); this.xmlFisico.output(xmlLogico, archivoFisico); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:io.hops.metadata.ndb.dalimpl.hdfs.BlockChecksumClusterj.java
@Override public void deleteAll(int inodeId) throws StorageException { final String query = String.format("DELETE FROM block_checksum WHERE %s=%d"); try {/*from w w w. j a v a 2s . co m*/ Connection conn = mysqlConnector.obtainSession(); PreparedStatement s = conn.prepareStatement(query); s.executeQuery(); } catch (SQLException ex) { throw HopsSQLExceptionHelper.wrap(ex); } finally { mysqlConnector.closeSession(); } }