View Javadoc

1   /*
2    * Created on 18-Apr-2005
3    */
4   package ca.spaz.sql;
5   
6   import java.sql.*;
7   
8   import org.apache.log4j.Logger;
9   
10  /***
11   * Conveniently produces simple SQL DELETE statements
12   *
13   * @author Aaron Davidson
14   */
15  public class SQLDelete extends SQLSelectableStatement {
16      /***
17       * Logger for this class
18       */
19      private static final Logger logger = Logger.getLogger(SQLDelete.class);
20  
21     /***
22      * Create a new SQLUpdate command for the given table
23      * @param tableName the name of the table to update on
24      */
25     public SQLDelete(String tableName) {
26        super(tableName, true, false, true);
27     }
28     
29     /*** 
30      * Overrides execute() and calls executeUpdate()
31      */
32     protected void doExecute(Connection con) throws SQLException {
33        Statement stmt = con.createStatement();      
34        String query = this.getQueryString();
35        if (logger.isDebugEnabled()) {
36            logger.debug("executeQuery() - Statement to be executed: " + query);
37        }
38       
39       stmt.execute(query);
40     }
41  
42     /***
43      * Generate the SQL string for an DELETE command.
44      */
45     protected String getQueryString() {
46        StringBuffer sb = new StringBuffer();
47        sb.append("DELETE FROM ");
48        sb.append(getTableName());
49        sb.append(getWhere());
50        return sb.toString();
51     }
52  }