List of usage examples for java.sql PreparedStatement executeUpdate
int executeUpdate() throws SQLException;
PreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or DELETE
; or an SQL statement that returns nothing, such as a DDL statement. From source file:dao.PblogTopicNpUpdateQuery.java
/** * Method updates the entry in pblogtopics_np * @param conn - the connection//from ww w . j a v a2 s .c o m * @param pblogid - pblogid * @param tid - tid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String pblogid, String tid) throws BaseDaoException { try { PreparedStatement stmt = conn .prepareStatement("update pblogtopics_np set entrydate=CURRENT_TIMESTAMP() where pblogid=" + pblogid + " and tid=" + tid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error executing update pblogtopics_np ", e); throw new BaseDaoException("Error update pblogtopics_np ", e); } }
From source file:net.sf.jdbcwrappers.nulltype.NullTypeTest.java
@Test public void testSetNull() throws SQLException { Connection connection = dataSource.getConnection(); try {//from ww w.j ava 2 s . c o m PreparedStatement statement = connection.prepareStatement("UPDATE TEST SET CHAR_COL=?"); try { statement.setNull(1, Types.NULL); statement.executeUpdate(); } finally { statement.close(); } } finally { connection.close(); } }
From source file:net.sf.jdbcwrappers.nulltype.NullTypeTest.java
@Test(expected = SQLException.class) public void crossCheckDerbyBehaviour() throws SQLException { Connection rawConnection = rawDataSource.getConnection(); try {//from www .j a v a 2s. c om PreparedStatement statement = rawConnection.prepareStatement("UPDATE TEST SET CHAR_COL=?"); try { statement.setNull(1, Types.NULL); statement.executeUpdate(); } finally { statement.close(); } } finally { rawConnection.close(); } }
From source file:com.stratelia.webactiv.util.DBUtil.java
/** * Update query executor.//from ww w .ja va 2 s . co m * @param con * @param updateQuery * @param parameters * @throws SQLException */ @SuppressWarnings("unchecked") public static long executeUpdate(Connection con, String updateQuery, Object parameters) throws SQLException { PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(updateQuery); final Collection<Object> sqlParams; if (parameters instanceof Object[]) { sqlParams = Arrays.asList((Object[]) parameters); } else if (parameters instanceof Collection) { sqlParams = (Collection) parameters; } else { sqlParams = Arrays.asList(parameters); } DBUtil.setParameters(prepStmt, sqlParams); return prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
From source file:adept.kbapi.sql.QuickJDBC.java
/** * retrieve connection instance/*from w w w. j a v a2 s. co m*/ */ public Connection getConnection() throws SQLException { Connection connection = connectionPool.getConnection(); if (defaultSchema != null) { PreparedStatement setSearchPathPreparedStmt = connection .prepareStatement("SET search_path TO " + defaultSchema); setSearchPathPreparedStmt.executeUpdate(); setSearchPathPreparedStmt.close(); } return connection; }
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;// www.j a v a2 s.com 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 . java 2 s . c o 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:dao.DirCollAddQuery.java
/** * This method is not called by spring.// ww w . j av a2 s .c o m * * @param conn the connection passed to this. * @param collabrumid the collabrum id * @param parentid the parent id (directory id) that this collabrum belongs to * @exception BaseDaoException */ public void run(Connection conn, String collabrumid, String parentid) throws BaseDaoException { PreparedStatement stmt = null; String query = null; try { query = "insert into dircoll values (" + collabrumid + ", " + parentid + ")"; stmt = conn.prepareStatement(query); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error executing DirCollAddQuery = " + query, e); } }
From source file:dao.ContactTagAddQuery.java
public void run(Connection conn, String contactid, String usertags) throws BaseDaoException { byte[] mytags = { ' ' }; if (!RegexStrUtil.isNull(usertags)) { mytags = usertags.getBytes();/*from w w w . j ava 2 s. c om*/ } PreparedStatement query = null; String stmt = "insert into contactstag values(" + contactid + ",?)"; try { query = conn.prepareStatement(stmt); query.setBytes(1, mytags); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing contactstag addquery" + stmt, e); } }
From source file:com.softberries.klerk.dao.AddressDao.java
public void delete(Long id, Connection conn) throws SQLException { PreparedStatement st = conn.prepareStatement(SQL_DELETE_ADDRESS); st.setLong(1, id);/*w w w . ja v a 2 s . c om*/ // run the query int i = st.executeUpdate(); System.out.println("i: " + i); if (i == -1) { System.out.println("db error : " + SQL_DELETE_ADDRESS); } }