List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void updatePin(int pin, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update multiplepasswords set pin=? where ussdsessionid = ?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, pin); ps.setString(2, sessionId);/* ww w . ja va 2 s . c o m*/ log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:net.codjo.dataprocess.server.treatmenthelper.TreatmentHelper.java
public static void insertRepositoryContent(Connection con, int repositoryId, String content) throws SQLException, TreatmentException, TransformerException { Document doc;//w w w . j av a2 s . co m try { doc = XMLUtils.parse(content); } catch (Exception ex) { throw new TreatmentException(ex); } PreparedStatement pStmt = con.prepareStatement( "insert into PM_REPOSITORY_CONTENT (REPOSITORY_CONTENT_ID, REPOSITORY_ID, TREATMENT_ID, CONTENT) values (?, ?, ?, ?)"); try { NodeList nodes = doc.getElementsByTagName(DataProcessConstants.TREATMENT_ENTITY_XML); int nbNodes = nodes.getLength(); for (int i = 0; i < nbNodes; i++) { Node node = nodes.item(i); String treatmentId = node.getAttributes().getNamedItem("id").getNodeValue(); if (treatmentId.length() > 50) { throw new TreatmentException("La taille de l'identifiant d'un traitement ('" + treatmentId + "') dpasse 50 caractres."); } String contentNode = XMLUtils.nodeToString(node); pStmt.setInt(1, SQLUtil.getNextId(con, "PM_REPOSITORY_CONTENT", "REPOSITORY_CONTENT_ID")); pStmt.setInt(2, repositoryId); pStmt.setString(3, treatmentId); pStmt.setString(4, contentNode); pStmt.executeUpdate(); } } finally { pStmt.close(); } }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void updateMultiplePasswordNoOfAttempts(String username, int attempts) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update `multiplepasswords` set attempts=? where username=?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, attempts); ps.setString(2, username);//from w w w . ja v a 2 s .c om log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:com.ccoe.build.dal.SessionProjectJDBCTemplate.java
public int create(final int sessionID, final int projectID) { final String SQL = "insert into RBT_SESSION_PROJECT (session_id, project_id) values (?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplateObject.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" }); ps.setInt(1, sessionID); ps.setInt(2, projectID);/* w w w. j a va 2s . co m*/ return ps; } }, keyHolder); return keyHolder.getKey().intValue(); }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int[] batchInsert(final List<Plugin> plugins, final int sessionID, final int projectID) { final String SQL = "insert into RBT_RAW_DATA (plugin_id, session_id, " + "project_id, duration, event_time, plugin_key) values (?, ?, ?, ?, ?, ?)"; int[] updateCounts = jdbcTemplateObject.batchUpdate(SQL, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, plugins.get(i).getId()); ps.setInt(2, sessionID);/*from w w w.ja v a 2s . c o m*/ ps.setInt(3, projectID); ps.setLong(4, plugins.get(i).getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugins.get(i).getStartTime().getTime())); ps.setString(6, plugins.get(i).getGroupId() + ":" + plugins.get(i).getArtifactId()); } public int getBatchSize() { return plugins.size(); } }); return updateCounts; }
From source file:net.mms_projects.copy_it.api.http.pages.v1.UserProfile.java
public FullHttpResponse onGetRequest(HttpRequest request, Database database, HeaderVerifier headerVerifier) throws Exception { PreparedStatement statement = database.getConnection().prepareStatement(SELECT_USER); statement.setInt(1, headerVerifier.getUserId()); ResultSet result = statement.executeQuery(); if (result.first()) { final JSONObject json = new JSONObject(); json.put(ID, result.getInt(ID)); json.put(EMAIL, result.getString(EMAIL)); json.put(SIGNED_UP, result.getInt(SIGNED_UP)); result.close();//from w w w .jav a 2s . c o m return new DefaultFullHttpResponse(request.getProtocolVersion(), OK, Unpooled.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); } result.close(); return null; }
From source file:co.edu.unbosque.swii.PoolTest.java
@Test(threadPoolSize = 5, invocationCount = 5) public void midaTiemposParaInsertar1000RegistrosConSingleton() throws ClassNotFoundException, SQLException, Exception { long tiempo = System.currentTimeMillis(); String SQL;//from w w w.j a va 2s . co m for (int x = 0; x < 1000; x++) { FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd); ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc); Connection c = pool.borrowObject(); SQL = "INSERT INTO grupo7.RegistroHilos( registro, hilo, fecha) VALUES (?, ?, now());"; PreparedStatement parametros = c.prepareStatement(SQL); parametros.setInt(1, x); parametros.setInt(2, (int) Thread.currentThread().getId()); parametros.executeUpdate(); pool.returnObject(c); } System.out.println("Tiempo de ejecucion " + (System.currentTimeMillis() - tiempo)); }
From source file:co.edu.unbosque.swii.PoolTest.java
@Test(threadPoolSize = 5, invocationCount = 5) public void midaTiemposParaInsertar1000RegistrosConObjectPool() throws ClassNotFoundException, SQLException { long tiempo = System.currentTimeMillis(); String SQL;//from w w w .ja v a 2s. co m for (int x = 0; x < 1000; x++) { Connection conec = SingletonConnection.getConnection(); SQL = "INSERT INTO grupo7.RegistroHilos( registro, hilo, fecha) VALUES (?, ?, now());"; PreparedStatement parametros = conec.prepareStatement(SQL); parametros.setInt(1, x); parametros.setInt(2, (int) Thread.currentThread().getId()); parametros.executeUpdate(); } System.out.println("Tiempo de ejecucion " + (System.currentTimeMillis() - tiempo)); }
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); return parseResultSet(statement.executeQuery()); }
From source file:com.ccoe.build.tracking.jdbc.SessionJDBCTemplate.java
public int[] batchUpdateDuration(final List<DurationObject> durations) { int[] updateCounts = jdbcTemplateObject.batchUpdate( "update RBT_SESSION set duration_download = ?, duration_build = ? where id = ?", new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, (durations.get(i)).getDownloadDuration()); ps.setInt(2, (durations.get(i)).getBuildDuration()); ps.setInt(3, (durations.get(i)).getSessionId()); }/*from w w w. j a v a 2 s . com*/ public int getBatchSize() { return durations.size(); } }); return updateCounts; }