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:com.aurel.track.dbase.MigrateTo37.java
private static void addLongTextFieldChange(PreparedStatement pstmtLongText, Integer fieldChangeID, Integer transactionID, String description) { try {/* www . j a va 2 s.co m*/ pstmtLongText.setInt(1, fieldChangeID); pstmtLongText.setInt(2, TFieldChangeBean.COMPOUND_HISTORY_FIELD); pstmtLongText.setInt(3, transactionID); pstmtLongText.setString(4, description); pstmtLongText.setInt(5, ValueType.LONGTEXT); pstmtLongText.setString(6, UUID.randomUUID().toString()); pstmtLongText.executeUpdate(); } catch (SQLException e) { LOGGER.error("Adding a field change for long text with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:libepg.util.db.JDBCAccessorTest.java
/** * Test of getConnection method, of class JDBCAccessor. * *//* ww w.ja v a2 s. c o m*/ @Test public void testGetCon() { try { LOG.info("getCon"); JDBCAccessor instance = JDBCAccessor.getInstance(); String url = "jdbc:sqlite::memory:"; instance.connect(url); java.sql.Connection result = instance.getConnection(); assertNotNull(result); LOG.debug("Connected."); Statement stmt = result.createStatement(); //? stmt.executeUpdate("create table test1( name string, age integer )"); LOG.debug("Made table."); //? String nameVal = "jjj888???"; int ageVal = 778; String sql1 = "insert into test1 values (?,?)"; PreparedStatement pstmt1 = result.prepareStatement(sql1); pstmt1.setString(1, nameVal); pstmt1.setInt(2, ageVal); pstmt1.executeUpdate(); LOG.debug("Inserted."); //?? String sql2 = "select * from test1 where name=? and age=?"; PreparedStatement pstmt2 = result.prepareStatement(sql2); pstmt2.setString(1, nameVal); pstmt2.setInt(2, ageVal); ResultSet rs = pstmt2.executeQuery(); while (rs.next()) { String str1 = rs.getString("name"); int int2 = rs.getInt("age"); System.out.println(str1); System.out.println(int2); assertEquals(nameVal, str1); assertEquals(ageVal, int2); } LOG.debug("Got data."); } catch (SQLException ex) { LOG.fatal(ex); fail(); } finally { JDBCAccessor.getInstance().close(); } }
From source file:com.Assignment4.Assign.java
@DELETE @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)/* w ww .j a va 2 s . co m*/ @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (connected == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement pstmt = connected.prepareStatement(query); pstmt.setInt(1, id); pstmt.executeUpdate(); return "The specified row is deleted"; } }
From source file:com.gs.obevo.dbmetadata.impl.dialects.MsSqlMetadataDialect.java
@Override public void setSchemaOnConnection(Connection conn, String schema) { PreparedStatement ps = null; try {/*w ww. jav a2 s. c o m*/ ps = conn.prepareStatement("use " + schema); ps.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } finally { DbUtils.closeQuietly(ps); } }
From source file:com.micromux.cassandra.jdbc.SpashScreenTest.java
@Test public void test() throws Exception { String query = "UPDATE Test SET a=?, b=? WHERE KEY=?"; PreparedStatement statement = con.prepareStatement(query); try {//w w w . j ava 2 s . c om statement.setLong(1, 100); statement.setLong(2, 1000); statement.setString(3, "key0"); statement.executeUpdate(); } finally { statement.close(); } }
From source file:dao.CobrandSiteUpdateFooterQuery.java
/** * This method is not called by spring.//from www . j a v a 2 s. co m * * @param conn the connection passed to this. * @param vhostid the vhostid * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String vhostid, byte[] footer) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update vhosts set footer=? where entryid=" + vhostid + " limit 1"; query = conn.prepareStatement(stmt); query.setBytes(1, footer); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing vhosts updating query, query = " + stmt, e); } }
From source file:oobbit.orm.Comments.java
/** * Removes a single comment. Please note that this is not called when a Link * is removed, the database handles the deletion of associated comments by * itself via CASCADE./*from w w w. j a va 2s . c o m*/ * * @param commentId * * @throws SQLException PreparedStatement failed to execute */ public void remove(int commentId) throws SQLException { PreparedStatement statement = getConnection() .prepareStatement("DELETE FROM `oobbit`.`comments` WHERE `comments`.`comment_id` = ?"); statement.setInt(1, commentId); statement.executeUpdate(); statement.close(); }
From source file:com.oracle.products.ProductResource.java
@DELETE @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)/*from ww w. j av a2s . c o m*/ @Produces(MediaType.TEXT_PLAIN) public String deleteProduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String query = "DELETE FROM product WHERE product_id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); pstmt.executeUpdate(); return "The specified row is deleted"; } }
From source file:oobbit.orm.Links.java
public void remove(int linkId) throws SQLException { PreparedStatement statement = getConnection() .prepareStatement("DELETE FROM `oobbit`.`links` WHERE `links`.`link_id` = ?;"); statement.setInt(1, linkId);//from ww w . j ava 2 s . c om statement.executeUpdate(); statement.close(); }
From source file:com.Assignment4.Prod.java
@DELETE @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)//from www. j ava 2 s . co m @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 prepstmt = connect.prepareStatement(query); prepstmt.setInt(1, id); prepstmt.executeUpdate(); return "The specified row is deleted"; } }