List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.adanac.module.blog.dao.CommentDao.java
public List<Map<String, String>> getComments(final Integer articleId) { return execute(new Operation<List<Map<String, String>>>() { @Override/*from w ww . j av a2s .c o m*/ public List<Map<String, String>> doInConnection(Connection connection) { List<Map<String, String>> comments = new ArrayList<Map<String, String>>(); try { PreparedStatement statement = connection .prepareStatement("select * from comments where article_id=? order by create_date"); statement.setInt(1, articleId); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { comments.add(transfer(resultSet, null)); } } catch (SQLException e) { error("get comments for article[" + articleId + "] failed ...", e); } return comments; } }); }
From source file:com.imagelake.control.CreditsDAOImp.java
@Override public List<SliceImage> getTypeSliceList(int type, int state) { List<SliceImage> li = new ArrayList<SliceImage>(); try {//from w w w. j a va 2s. co m String sql = "SELECT * FROM slice_image WHERE type_id=? AND status=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, type); ps.setInt(2, state); ResultSet rs = ps.executeQuery(); while (rs.next()) { SliceImage sl = new SliceImage(); sl.setId(rs.getInt(1)); sl.setCredit_id(rs.getInt(2)); sl.setType_id(rs.getInt(3)); sl.setStatus(rs.getInt(4)); li.add(sl); } } catch (Exception e) { e.printStackTrace(); } return li; }
From source file:com.imagelake.control.CreditsDAOImp.java
@Override public boolean updateCredits(Credits c) { boolean ok = false; try {/*www .j av a 2 s .c o m*/ String sql = "UPDATE credits SET credits=?,size=?,width=?,height=?,state=? WHERE credit_id=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, c.getCredits()); ps.setString(2, c.getSize()); ps.setInt(3, c.getWidth()); ps.setInt(4, c.getHeight()); ps.setInt(5, c.getState()); ps.setInt(6, c.getCredit_id()); int i = ps.executeUpdate(); if (i > 0) { ok = true; } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:oobbit.orm.LinkConnections.java
public void update(LinkConnection linkConnection) throws SQLException { PreparedStatement statement = getConnection().prepareStatement( "UPDATE `oobbit`.`connections` SET `title` = ? WHERE `connections`.`source_link_id` = ? AND `connections`.`destination_link_id` = ?;"); statement.setString(1, linkConnection.getTitle()); statement.setInt(2, linkConnection.getSourceLinkId()); statement.setInt(3, linkConnection.getDestinationLinkId()); statement.executeUpdate();//from w w w . j a va 2s . c om statement.close(); }
From source file:com.adanac.module.blog.dao.AnswerDao.java
public boolean updateCount(final int id, final String column, final int count) { return execute(new TransactionalOperation<Boolean>() { @Override/*w w w . j av a2 s . c o m*/ public Boolean doInConnection(Connection connection) { int finalCount = count; if (count <= 0) { finalCount = 1; } try { PreparedStatement preparedStatement = connection.prepareStatement( "update answers set " + column + " = " + column + " + " + finalCount + " where id = ?"); preparedStatement.setInt(1, id); int number = preparedStatement.executeUpdate(); return number > 0; } catch (SQLException e) { throw new RuntimeException(e); } } }); }
From source file:fll.web.playoff.Playoff.java
/** * Get the list of team numbers that are in the specified playoff bracket. * The bracket may not be initialized yet. * /*from ww w .java 2 s. c o m*/ * @throws SQLException */ public static List<Integer> getTeamNumbersForPlayoffBracket(final Connection connection, final int tournamentId, final String bracketName) throws SQLException { final List<Integer> teams = new LinkedList<>(); PreparedStatement prep = null; ResultSet rs = null; try { prep = connection.prepareStatement("SELECT team_number" // + " FROM playoff_bracket_teams" // + " WHERE tournament_id = ?" // + " AND bracket_name = ?"); prep.setInt(1, tournamentId); prep.setString(2, bracketName); rs = prep.executeQuery(); while (rs.next()) { final int teamNumber = rs.getInt(1); teams.add(teamNumber); } } finally { SQLFunctions.close(rs); SQLFunctions.close(prep); } return teams; }
From source file:com.imagelake.control.CreditsDAOImp.java
public boolean insertSliceImage(int cid, int typeid, int sta) { boolean ok = false; try {/*ww w . j a v a 2 s . c o m*/ boolean check = checkSliceImage(cid, typeid); if (!check) { String sql = "INSERT INTO slice_image(credit_id,type_id,status) VALUES(?,?,?)"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, cid); ps.setInt(2, typeid); ps.setInt(3, sta); int i = ps.executeUpdate(); if (i > 0) { ok = true; } } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public int batchCreate(final String uid, final int tid, final List<Long> rids) { this.getJdbcTemplate().batchUpdate(SQL_CREATE, new BatchPreparedStatementSetter() { @Override//w w w.java2 s . co m public int getBatchSize() { return (null == rids || rids.isEmpty()) ? 0 : rids.size(); } @Override public void setValues(PreparedStatement ps, int index) throws SQLException { int i = 0; long rid = rids.get(index); ps.setInt(++i, (int) rid); ps.setInt(++i, tid); ps.setString(++i, uid); ps.setTimestamp(++i, new Timestamp((new Date()).getTime())); } }); return 1; }
From source file:com.l2jfree.gameserver.instancemanager.RecommendationManager.java
/** * <B>Create an entry in `character_recommend_data`</B>.<BR> * Called just after character creation, but may be also called when restoring player's * evaluation data and the entry is missing. * @param player The newly created player *///from w w w.j a va 2 s . c o m public void onCreate(L2Player player) { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement ps = con.prepareStatement(ADD_RECOMMENDATION_INFO); ps.setInt(1, player.getObjectId()); ps.setLong(2, nextUpdate - DAY); ps.executeUpdate(); ps.close(); } catch (SQLException e) { _log.error("Failed creating recommendation data for " + player.getName() + "!", e); } finally { L2DatabaseFactory.close(con); } }
From source file:org.ala.dao.DocumentDAOImpl.java
@Override public void changeInfosourceIdByDocumentId(final int documentId, final int infosourceId) { getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn .prepareStatement("update document set " + "infosource_id=? " + "where id=?"); ps.setInt(1, infosourceId); ps.setInt(2, documentId);/*from w w w .j a v a 2 s . c o m*/ return ps; } }); }