List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.sapienter.jbilling.tools.ConvertToBinHexa.java
private static void updateCCRow(int id, String number, String name) throws SQLException { PreparedStatement stmt = connection .prepareStatement("UPDATE credit_card set cc_number = ?, name = ? where ID = ?"); stmt.setString(1, number);/*w ww .ja v a 2s . co m*/ stmt.setString(2, name); stmt.setInt(3, id); stmt.executeUpdate(); }
From source file:com.concursive.connect.web.modules.activity.utils.ProjectHistoryUtils.java
public static int queryAdditionalCommentsCount(Connection db, ProjectHistory projectHistory) throws SQLException { int count = 0; int topId = projectHistory.getTopId(); if (topId == -1) { topId = projectHistory.getId();/*from www . j a va 2 s . com*/ } PreparedStatement pst = db.prepareStatement("SELECT count(*) AS comment_count " + "FROM project_history " + "WHERE top_id = ? AND position > ? "); pst.setInt(1, topId); pst.setInt(2, projectHistory.getPosition()); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("comment_count"); } rs.close(); pst.close(); return count; }
From source file:com.l2jfree.gameserver.model.entity.faction.FactionQuest.java
public static void deleteFactionQuest(L2Player player, int factionQuestId) { Connection con = null;//from www.j a v a 2 s. com try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement( "DELETE FROM character_faction_quests WHERE char_id=? AND faction_quest_id=?"); statement.setInt(1, player.getObjectId()); statement.setInt(2, factionQuestId); statement.executeUpdate(); statement.close(); } catch (Exception e) { _log.warn("could not delete char faction quest:", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.entity.faction.FactionQuest.java
public static void createFactionQuest(L2Player player, int factionQuestId) { Connection con = null;/*from w w w . java 2s . co m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement( "INSERT INTO character_faction_quests (char_id,faction_quest_id) VALUES (?,?)"); statement.setInt(1, player.getObjectId()); statement.setInt(2, factionQuestId); statement.executeUpdate(); statement.close(); } catch (Exception e) { _log.warn("could not insert char faction quest:", e); } finally { L2DatabaseFactory.close(con); } }
From source file:Emporium.Controle.ContrDestinatarioImporta.java
public static int inserir(int idCliente, int idDepartamento, String nome, String cpf_cnpj, String empresa, String cep, String endereco, String numero, String complemento, String bairro, String cidade, String uf, String email, String celular, String pais, String nomeBD, String tags) { Connection conn = Conexao.conectar(nomeBD); String sql = "INSERT INTO cliente_destinatario (idCliente, nome, cpf_cnpj, empresa, cep, endereco, numero, complemento, bairro, cidade, uf, email, celular, pais, tags, idDepartamento) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; //System.out.println("inserir Destinatario -----------------\n"+sql+"\n---------------"); try {/* w w w .ja va 2 s. c o m*/ PreparedStatement valores = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); valores.setInt(1, idCliente); valores.setString(2, FormataString.removeSpecialChars(nome)); valores.setString(3, cpf_cnpj); valores.setString(4, empresa); valores.setString(5, cep); valores.setString(6, FormataString.removeSpecialChars(endereco)); valores.setString(7, numero); valores.setString(8, complemento); valores.setString(9, bairro); valores.setString(10, cidade); valores.setString(11, uf); valores.setString(12, email); valores.setString(13, celular); valores.setString(14, pais); valores.setString(15, tags); valores.setInt(16, idDepartamento); valores.executeUpdate(); int autoIncrementKey = 0; ResultSet rs = valores.getGeneratedKeys(); if (rs.next()) { autoIncrementKey = rs.getInt(1); } valores.close(); return autoIncrementKey; } catch (SQLException e) { //System.out.println("ERRO > "+e); ContrErroLog.inserir("HOITO - ContrPreVendaDest.inserir", "SQLException", sql, e.toString()); return 0; } finally { Conexao.desconectar(conn); } }
From source file:Main.java
public static PreparedStatement createLayersInsertForContextual(Connection conn, int layerId, String description, String path, String name, String displayPath, double minLatitude, double minLongitude, double maxLatitude, double maxLongitude, String path_orig) throws SQLException { PreparedStatement stLayersInsert = conn.prepareStatement( "INSERT INTO layers (id, name, description, type, path, displayPath, minlatitude, minlongitude, maxlatitude, maxlongitude, enabled, displayname, uid, path_orig) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); stLayersInsert.setInt(1, layerId); stLayersInsert.setString(2, name);//from w w w . j a v a 2 s . c om stLayersInsert.setString(3, description); stLayersInsert.setString(4, CONTEXTUAL_LAYER_TYPE); stLayersInsert.setString(5, path); stLayersInsert.setString(6, displayPath); stLayersInsert.setDouble(7, minLatitude); stLayersInsert.setDouble(8, minLongitude); stLayersInsert.setDouble(9, maxLatitude); stLayersInsert.setDouble(10, maxLongitude); stLayersInsert.setBoolean(11, true); stLayersInsert.setString(12, description); stLayersInsert.setString(13, Integer.toString(layerId)); stLayersInsert.setString(14, path_orig); return stLayersInsert; }
From source file:com.sf.ddao.factory.param.ParameterHelper.java
public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz, Context context) throws SQLException { if (clazz == Integer.class || clazz == Integer.TYPE) { preparedStatement.setInt(idx, (Integer) param); } else if (clazz == String.class) { preparedStatement.setString(idx, (String) param); } else if (clazz == Long.class || clazz == Long.TYPE) { preparedStatement.setLong(idx, (Long) param); } else if (clazz == Boolean.class || clazz == Boolean.TYPE) { preparedStatement.setBoolean(idx, (Boolean) param); } else if (BigInteger.class.isAssignableFrom(clazz)) { BigInteger bi = (BigInteger) param; preparedStatement.setBigDecimal(idx, new BigDecimal(bi)); } else if (Timestamp.class.isAssignableFrom(clazz)) { preparedStatement.setTimestamp(idx, (Timestamp) param); } else if (Date.class.isAssignableFrom(clazz)) { if (!java.sql.Date.class.isAssignableFrom(clazz)) { param = new java.sql.Date(((Date) param).getTime()); }// ww w . j a v a 2s .co m preparedStatement.setDate(idx, (java.sql.Date) param); } else if (BoundParameter.class.isAssignableFrom(clazz)) { ((BoundParameter) param).bindParam(preparedStatement, idx, context); } else { throw new SQLException("Unimplemented type mapping for " + clazz); } }
From source file:com.silverpeas.notation.model.RatingDAO.java
public static void updateRaterRating(Connection con, RaterRatingPK pk, int note) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_UPDATE_RATER_RATING); try {//from w w w . j a va2s. c om prepStmt.setInt(1, note); prepStmt.setString(2, pk.getInstanceId()); prepStmt.setString(3, pk.getContributionId()); prepStmt.setString(4, pk.getContributionType()); prepStmt.setString(5, pk.getRater().getId()); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:com.sql.EMail.java
/** * Marks an email ready to file by the system. This is in place so a user * does not try to docket an email that is currently being processed. * * @param eml/*from www . j a va2s. co m*/ */ public static void setEmailReadyToFile(EmailMessageModel eml) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "UPDATE EMail SET readyToFile = ?, emailBodyFileName = ? WHERE id = ?"; ps = conn.prepareStatement(sql); ps.setInt(1, eml.getReadyToFile()); ps.setString(2, eml.getEmailBodyFileName()); ps.setInt(3, eml.getId()); ps.executeUpdate(); } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(ps); DbUtils.closeQuietly(conn); } }
From source file:com.silverpeas.notation.model.RatingDAO.java
public static void createRaterRating(Connection con, RaterRatingPK pk, int note) throws SQLException { int newId = 0; try {//from w w w .j a va 2s.c o m newId = DBUtil.getNextId(TABLE_NAME, COLUMN_ID); } catch (Exception e) { SilverTrace.warn("notation", "RatingDAO.createRaterRating", "root.EX_PK_GENERATION_FAILED", e); } PreparedStatement prepStmt = con.prepareStatement(QUERY_CREATE_RATER_RATING); try { prepStmt.setInt(1, newId); prepStmt.setString(2, pk.getInstanceId()); prepStmt.setString(3, pk.getContributionId()); prepStmt.setString(4, pk.getContributionType()); prepStmt.setString(5, pk.getRater().getId()); prepStmt.setInt(6, note); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }