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.fufang.testcase.orgmanager.warnset.SaveOrUpdate.java
@AfterTest public void deleteUser() throws SQLException { System.out.println("------aftertest------"); SqlUtils c = new SqlUtils(); con = c.sqlSConnection(dbUrl, dbName, dbUserName, dbPassword); try {/*www. j a va 2 s . c o m*/ String deleteSql = "DELETE FROM [dbo].[t_warn] WHERE id =" + id; PreparedStatement pStatement = con.prepareStatement(deleteSql); pStatement.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } try { Statement statement = con.createStatement(); String querySqlU = "SELECT * FROM [dbo].[t_warn] WHERE id =" + id; ResultSet resultSetU = statement.executeQuery(querySqlU); while (resultSetU.next()) { int deleteId = resultSetU.getInt("id"); System.out.println(deleteId); Assert.assertEquals("123" + "", deleteId); } /*if(resultSetU == null){ System.out.println("delete success"); }else{ System.out.println("delete fail"); }*/ } catch (Exception e) { e.printStackTrace(); } }
From source file:dao.DirectoryAddBlockQuery.java
public void run(Connection conn, String directoryid, String loginid) throws BaseDaoException { PreparedStatement query = null; try {// ww w .j a v a2 s. c o m String stmt = "insert into dirblock values(" + directoryid + ", " + loginid + ")"; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing dirblock addquery", e); throw new BaseDaoException("Error occured while executing dirblock addquery", e); } }
From source file:dao.PblogTopicFreezeQuery.java
/** * This method is not called by spring.//from w w w. jav a 2 s .c o m * @param conn the connection passed to this. * @param tid the tid * @param freeze - freeze (0 or 1) * @exception BaseDaoException */ public void run(Connection conn, String tid, String freeze) throws BaseDaoException { PreparedStatement query = null; try { query = conn .prepareStatement("update pblogtopics set freeze=" + freeze + " where tid=" + tid + " limit 1"); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error executing update pblogtopics update freeze= " + freeze + " where tid=" + tid, e); } }
From source file:dao.HdprofileUpdateQuery.java
public void run(Connection conn, int pm, int bb, int fd, String loginid) throws BaseDaoException { Long myloginid = new Long(loginid); try {/*from ww w . j a va2s.com*/ PreparedStatement stmt = conn.prepareStatement("update hdprofile set informpm=" + pm + ", informbb=" + bb + ", informfd=" + fd + " where loginid=" + myloginid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing hdprofile update query ", e); throw new BaseDaoException("Error occured while executing hdprofile update query ", e); } }
From source file:dao.DirBlobTagsUpdateQuery.java
/** * This method is not called by spring.// ww w .j a va 2s. co m * * @param conn the connection is passed to this method * @param entryid the entryid * @param directoryid the directoryid * @param usertags the usertags * @param entryid */ public void run(Connection conn, String entryid, String directoryid, String usertags) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement("update dirblobtags set usertags='" + usertags + "' where entryid=" + entryid + " and directoryid=" + directoryid + ""); stmt.executeUpdate(); } catch (Exception e) { String myquery = "update dirblobtags set usertags='" + usertags + "' where entryid=" + entryid + " and directoryid=" + directoryid + ""; throw new BaseDaoException("Error while executing update dirblobtags " + myquery, e); } }
From source file:com.softberries.klerk.dao.DocumentItemDao.java
public void deleteAll(Connection conn) throws SQLException { PreparedStatement st = conn.prepareStatement(SQL_DELETE_ALL_DOCUMENTITEMS); int i = st.executeUpdate(); System.out.println("i: " + i); if (i == -1) { System.out.println("db error : " + SQL_DELETE_ALL_DOCUMENTITEMS); }/*w ww. ja v a2 s.c om*/ }
From source file:dao.CollBlobTagsUpdateQuery.java
/** * This method is not called by spring.//from w w w .j ava 2s. c o m * * @param conn the connection is passed to this method * @param entryid * @param collabrumid collabrumid * @param usertags usertags */ public void run(Connection conn, String entryid, String collabrumid, String usertags) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement("update collblobtags set usertags='" + usertags + "' where entryid=" + entryid + " and collabrumid=" + collabrumid + ""); stmt.executeUpdate(); String myquery = "update collblobtags set usertags='" + usertags + "' where entryid=" + entryid + " and collabrumid=" + collabrumid + ""; logger.info("myquery = " + myquery); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update collblobtags ", e); } }
From source file:dao.ColTopicIncrementHitsQuery.java
/** * This method is not called by spring.//from w w w . j a va2 s . co m * * @param conn the connection passed to this. * @param tid the tid * @param ownerid the ownerid of this collabrum or network blog topic * @param isAdmin the diary administrator (true if this is diaryAdmin) * @exception BaseDaoException */ public void run(Connection conn, String tid) throws BaseDaoException { PreparedStatement query = null; try { query = conn.prepareStatement( "update low_priority colltopics set hits=hits+1 where tid=" + tid + " limit 1"); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured executing colltopics update hits", e); } }
From source file:dao.PblogTopicAddQuery.java
/** * This method is executed by PblogTopicDao. * @param conn - the connection// w w w . j av a 2 s . co m * @param message - the message * @param topic - the topic * @param myownerid - the owner id * @throws BaseDaoException **/ public void run(Connection conn, String myownerid, String message, String topic) throws BaseDaoException { /* Long myownerid = new Long(ownerid); */ byte[] msg = { ' ' }; if (!RegexStrUtil.isNull(message)) { msg = message.getBytes(); } byte[] mytopic = { ' ' }; if (!RegexStrUtil.isNull(topic)) { mytopic = topic.getBytes(); } String stmt = "insert into pblogtopics values(0, " + myownerid + ", CURRENT_TIMESTAMP(), ?, ?, 0, 0, CURRENT_TIMESTAMP())"; try { // String stmt = "insert into pblogtopics values(tid="+0+", pblogid="+myownerid+", entrydate=CURRENT_TIMESTAMP(), createdate=CURRENT_TIMESTAMP(), topic=?, message=?, freeze=0, screen=0)"; PreparedStatement query = null; query = conn.prepareStatement(stmt); query.setBytes(1, mytopic); query.setBytes(2, msg); query.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing pblogtopics addquery" + stmt, e); throw new BaseDaoException("Error occured while executing pblogtopics addquery" + stmt, e); } }
From source file:dao.PblogTopicScreenQuery.java
/** * This method is not called by spring.//from www. j a v a 2 s.com * * @param conn the connection passed to this. * @param tid the tid * @param screen the screening of this personal blog * @exception BaseDaoException */ public void run(Connection conn, String tid, String screen) throws BaseDaoException { PreparedStatement query = null; String stmt = "update pblogtopics set screen=" + screen + " where tid=" + tid + " limit 1"; try { query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error in pblogtopics update screen=1, stmt" + stmt, e); } }