List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.l2jfree.gameserver.communitybbs.bb.Post.java
/** * @param t/* ww w . j a va2 s . co m*/ */ private void load(Topic t) { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC"); statement.setInt(1, t.getForumID()); statement.setInt(2, t.getID()); ResultSet result = statement.executeQuery(); while (result.next()) { CPost cp = new CPost(); cp.postId = result.getInt("post_id"); cp.postOwner = result.getString("post_owner_name"); cp.postOwnerId = result.getInt("post_ownerid"); cp.postDate = result.getLong("post_date"); cp.postTopicId = result.getInt("post_topic_id"); cp.postForumId = result.getInt("post_forum_id"); cp.postTxt = result.getString("post_txt"); _post.add(cp); } result.close(); statement.close(); } catch (Exception e) { _log.warn("data error on Post " + t.getForumID() + "/" + t.getID() + " : ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.ShortCuts.java
public synchronized void restore() { _shortCuts.clear();//from w w w. j av a 2s. c om Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT slot, page, type, shortcut_id, level FROM character_shortcuts WHERE charId=? AND class_index=?"); statement.setInt(1, _owner.getObjectId()); statement.setInt(2, _owner.getClassIndex()); ResultSet rset = statement.executeQuery(); while (rset.next()) { int slot = rset.getInt("slot"); int page = rset.getInt("page"); int type = rset.getInt("type"); int id = rset.getInt("shortcut_id"); int level = rset.getInt("level"); _shortCuts.put(slot + page * 12, new L2ShortCut(slot, page, type, id, level, 1)); } rset.close(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } for (L2ShortCut sc : _shortCuts.values()) if (sc.getType() == L2ShortCut.TYPE_ITEM) if (_owner.getInventory().getItemByObjectId(sc.getId()) == null) deleteShortCut(sc.getSlot(), sc.getPage()); }
From source file:com.theserverlabs.maven.utplsq.SureFireReport.java
/** * Given the run_id of a test package run, create a report in surefire XML format. * //from ww w . jav a2 s. co m * @param conn * the connection to the database * @param runId * the test run ID * @param suiteOrPackageName * the suite or package name * @param duration * time in msecs taken to run the suite/package * * @throws SQLException * if there was a problem getting the report data from the database * @throws IOException * if there was a problem outputting the report to the filesystem * @throws SplitterException * if there was a problem generating the report * * @return retrieved results */ public TestResults build(Connection conn, int runId, String suiteOrPackageName, long duration) throws SQLException, IOException, SplitterException { // Fetch the utPLSQL results from the db // test run. PreparedStatement stmt = conn.prepareStatement( "select status, description from utr_outcome where run_id = ? order by outcome_id DESC"); stmt.setInt(1, runId); ResultSet rs = stmt.executeQuery(); DescContainer dc; TestResults testResult = new TestResults(); while (rs.next()) { // The description is a miss mash of output separated by ':' which we attempt to format // into a logical format! String desc = rs.getString("description"); String status = rs.getString("status"); // use the ResultSpitter to get the various data elements // contained in the description // (the utPLSQL schema doesn't seem to be well normalised ;-) ) dc = ResultSplitter.split(desc); addTestResults(status, dc, testResult); } writeXML(testResult, suiteOrPackageName, duration); return testResult; }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Prepare a statement for iteration given a query string, fetch size * and some args.//www . j a v a2s.co m * * NB: the provided connection is not closed. * * @param c a Database connection * @param fetchSize hint to JDBC driver on number of results to cache * @param query a query string (must not be null or empty) * @param args some args to insert into this query string (must not be null) * @return a prepared statement * @throws SQLException If unable to prepare a statement * @throws ArgumentNotValid If unable to handle type of one the args, or * the arguments are either null or an empty String. */ public static PreparedStatement prepareStatement(Connection c, int fetchSize, String query, Object... args) throws SQLException { ArgumentNotValid.checkNotNull(c, "Connection c"); ArgumentNotValid.checkPositive(fetchSize, "int fetchSize"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); c.setAutoCommit(false); PreparedStatement s = c.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); s.setFetchSize(fetchSize); int i = 1; for (Object arg : args) { if (arg instanceof String) { s.setString(i, (String) arg); } else if (arg instanceof Integer) { s.setInt(i, (Integer) arg); } else if (arg instanceof Long) { s.setLong(i, (Long) arg); } else if (arg instanceof Boolean) { s.setBoolean(i, (Boolean) arg); } else if (arg instanceof Date) { s.setTimestamp(i, new Timestamp(((Date) arg).getTime())); } else { throw new ArgumentNotValid("Cannot handle type '" + arg.getClass().getName() + "'. We can only handle string, " + "int, long, date or boolean args for query: " + query); } i++; } return s; }
From source file:com.l2jfree.gameserver.gameobjects.skills.PlayerSkills.java
public void deleteSkills(Connection con, int classIndex) throws SQLException { PreparedStatement statement = con .prepareStatement("DELETE FROM character_skills WHERE charId=? AND class_index=?"); statement.setInt(1, getOwner().getObjectId()); statement.setInt(2, classIndex);/* www. j ava2s . c o m*/ statement.execute(); statement.close(); _storedSkills.remove(classIndex); }
From source file:dao.CarryonBlobUpdate.java
/** * This method is used to add blobstreams for a user. <code>Userpage</code> * @param blob - the blob stream/*from w ww .j a v a2 s.c o m*/ * @param category - the blob type (1 - photos, 2-music, 3-video 4 - documents, 5 - archives) * @param mimeType - the mime type (image/jpeg, application/octet-stream) * @param btitle - the title for this blob * @param loginId - the loginId * @param bsize - the size of the blob * @param zoom - the zoom for the blob (used for displaying for image/jpeg) * @throws Dao Exception - when an error or exception occurs while inserting this blob in DB. * **/ public void run(Connection conn, byte[] blob, int category, String mimeType, String btitle, String loginId, long bsize, int zoom, String caption) throws BaseDaoException { byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } //long dt = System.currentTimeMillis(); // Connection conn = null; String stmt = "insert into carryon values(?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?, ?)"; PreparedStatement s = null; try { // conn = dataSource.getConnection(); s = conn.prepareStatement(stmt); s.setLong(1, 0); // entryid s.setLong(2, new Long(loginId)); // loginid s.setInt(3, new Integer(category)); // category s.setString(4, mimeType); // mimetype s.setString(5, btitle); // btitle // s.setDate(6, new Date(dt)); // s.setDate(6, CURRENT_TIMESTAMP()); s.setBytes(6, blob); s.setLong(7, bsize); s.setInt(8, new Integer(zoom)); s.setInt(9, 0); // hits s.setBytes(10, capBytes); // caption s.executeUpdate(); } catch (SQLException e) { logger.error("Error adding a blob.", e); throw new BaseDaoException("Error adding a blob " + e.getMessage(), e); } }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public int deleteAllStarmark(final int tid, final String uid) { return this.getJdbcTemplate().update(new PreparedStatementCreator() { @Override/*from www . jav a 2 s . c om*/ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = null; ps = conn.prepareStatement(SQL_DELETE_ALL); int i = 0; ps.setInt(++i, tid); ps.setString(++i, uid); return ps; } }); }
From source file:com.microsoftopentechnologies.azchat.web.dao.UserPreferenceDAOImpl.java
/** * This method populates Prepared Statement from userPreferenceEntity * object.//ww w .j a v a 2s .c o m * * @param preparedStatement * @param userPreferenceEntity * @return * @throws SQLException */ public PreparedStatement generatePreparedStatement(PreparedStatement preparedStatement, UserPreferenceEntity userPreferenceEntity) throws SQLException { preparedStatement.setInt(1, userPreferenceEntity.getUserId()); preparedStatement.setInt(2, userPreferenceEntity.getPreferenceId()); preparedStatement.setDate(3, new Date(userPreferenceEntity.getDateCreated().getTime())); preparedStatement.setDate(4, new Date(userPreferenceEntity.getCreatedBy().getTime())); preparedStatement.setDate(5, new Date(userPreferenceEntity.getDateModified().getTime())); preparedStatement.setDate(6, new Date(userPreferenceEntity.getModifiedBy().getTime())); return preparedStatement; }
From source file:de.klemp.middleware.controller.Controller.java
/** * This method is for the GUI. It returns all the methods of a class. It is * used to add the options in the select lists. * /*www . ja va 2 s . c o m*/ * @param component * 1 or 2 * @param classes * names of the classes the methods should be returned * @return a String with the names of the methods. They are separated by a * ",". */ public static synchronized String getMethods(int component, String classes) { String methods = new String(); createDBConnection(); try { PreparedStatement st = conn .prepareStatement("select method from \"Classes\" where component=? and class=?;"); st.setInt(1, component); st.setString(2, classes); ResultSet result = st.executeQuery(); while (result.next()) { if (!result.isLast()) { methods = methods + result.getString(1) + ","; } else { methods = methods + result.getString(1); } } } catch (SQLException e) { logger.error("SQL Exception", e); } closeDBConnection(); return methods; }
From source file:com.imagelake.control.CreditsDAOImp.java
public boolean removeSliceImage(int id) { boolean ok = false; try {// w w w.ja va2 s . c o m String sql = "UPDATE slice_image SET status='2' WHERE id=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, id); int i = ps.executeUpdate(); if (i > 0) { ok = true; } } catch (Exception e) { e.printStackTrace(); } return ok; }