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.CobrandSiteUpdateHeaderQuery.java
/** * This method is not called by spring.// ww w .j a v a 2 s .com * * @param conn the connection passed to this. * @param vhostid the vhostid * @param header the header * @exception BaseDaoException */ public void run(Connection conn, String vhostid, byte[] header) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update vhosts set header=? where entryid=" + vhostid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, header); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing cobrandsiteupdatingheader query, query = " + stmt, e); } }
From source file:com.uit.anonymousidentity.Repository.Nonces.NonceJDBCTemplate.java
@Override public void store(Nonce nonce) throws SQLException { String t_sql = "insert into %s (%s, %s) values (?, ?)"; String sql = String.format(t_sql, TABLE_NAME, VALUE, SID); PreparedStatement pst = dataSource.getConnection().prepareStatement(sql); pst.setBytes(1, nonce.getByteArray()); pst.setString(2, nonce.getIssuerSid()); pst.executeUpdate(); pst.close();//from www.j a v a2 s . com }
From source file:com.adanac.module.blog.dao.RecordDao.java
public Boolean delete(Integer id) { return execute(new TransactionalOperation<Boolean>() { @Override/* www .j a v a2s . c o m*/ public Boolean doInConnection(Connection connection) { String sql = "delete from records where id=?"; try { PreparedStatement statement = connection.prepareStatement(sql); statement.setInt(1, id); int result = statement.executeUpdate(); if (result > 0) { return true; } } catch (SQLException e) { throw new RuntimeException(e); } return false; } }); }
From source file:com.product.Product.java
@DELETE @Path("{id}") @Consumes(MediaType.TEXT_PLAIN)// w w w. java 2 s. c om @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (connect == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement prepstmnt = connect.prepareStatement(query); prepstmnt.setInt(1, id); prepstmnt.executeUpdate(); return "The specified row is deleted"; } }
From source file:dao.UserCobrandUpdateFooterQuery.java
/** * This method is not called by spring./*from ww w . j a v a 2 s . c o m*/ * * @param conn the connection passed to this. * @param loginid the loginid * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String loginid, byte[] footer) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update usercobrand set footer=? where loginid=" + loginid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, footer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing usercobrand updating query, query = " + stmt, e); } }
From source file:dao.UserCobrandUpdateHeaderQuery.java
/** * This method is not called by spring./*from w ww . j a v a2 s . co m*/ * * @param conn the connection passed to this. * @param loginid the loginid * @param header the header * @exception BaseDaoException */ public void run(Connection conn, String loginid, byte[] header) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update usercobrand set header=? where loginid=" + loginid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, header); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing usercobrand updating query, query = " + stmt, e); } }
From source file:com.assignment4.productdetails.java
@DELETE @Path("{id}") @Consumes(MediaType.TEXT_PLAIN)//from w w w. j ava2 s .co m @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "Not able to connected"; } else { String query = "DELETE FROM products WHERE product_id = ?"; PreparedStatement prestmt = conn.prepareStatement(query); prestmt.setInt(1, id); prestmt.executeUpdate(); return "The specified row is deleted"; } }
From source file:dao.ColStreamBlobUpdateQuery.java
public void run(Connection conn, String entryid, String collabrumid, String zoom, String btitle, String caption) throws BaseDaoException { Integer myZoom = 100;// w w w .j a v a 2 s. com if (!RegexStrUtil.isNull(zoom)) { myZoom = new Integer(zoom); } byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } try { PreparedStatement stmt = conn.prepareStatement("update collblob set caption=?, btitle='" + btitle + "',zoom=" + myZoom + " where entryid=" + entryid + " and collabrumid=" + collabrumid + ""); stmt.setBytes(1, capBytes); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update collblob ", e); } }
From source file:com.manning.junitbook.ch14.ejbs.TestAdministratorEJB.java
/** * @see TestCase#setUp()/*from w w w.ja va2 s . com*/ */ public void setUp() throws Exception { Properties properties = new Properties(); properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces"); InitialContext ctx = new InitialContext(properties); administrator = (IAdministratorLocal) ctx .lookup("ch14-cactus-ear-cactified/" + AdministratorBean.class.getSimpleName() + "/local"); Connection conn = getConnection(); Statement s = conn.createStatement(); s.execute("DROP TABLE USERS IF EXISTS"); s.execute("CREATE TABLE USERS(ID INT, NAME VARCHAR(40))"); PreparedStatement psInsert = conn.prepareStatement("INSERT INTO USERS VALUES (?, ?)"); psInsert.setInt(1, 1); psInsert.setString(2, "User 1"); psInsert.executeUpdate(); psInsert.setInt(1, 2); psInsert.setString(2, "User 2"); psInsert.executeUpdate(); }
From source file:dao.CollabrumUpdateQuery.java
/** * This method is used update <code>Collabrum</code> bean * @param conn the connection passed to this. * @param collabrumId the collabrumId/* w ww .j a va2s. com*/ * @param desc the description * @param keywords the keywords for the directory * @exception BaseDaoException */ public void run(Connection conn, String collabrumid, String desc, String keywords) throws BaseDaoException { byte[] mydesc = { ' ' }; if (!RegexStrUtil.isNull(desc)) { mydesc = desc.getBytes(); } PreparedStatement query = null; String stmt = null; try { stmt = "update collabrum set coldesc=? where collabrumid=" + collabrumid + ""; query = conn.prepareStatement(stmt); query.setBytes(1, mydesc); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured executing directory update query + query = " + stmt, e); } }