1 15 package org.apache.tapestry.contrib.jdbc; 16 17 import java.sql.Connection ; 18 import java.sql.ResultSet ; 19 import java.sql.SQLException ; 20 import java.sql.Statement ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 31 32 public class SimpleStatement implements IStatement 33 { 34 private static final Log LOG = LogFactory.getLog(SimpleStatement.class); 35 36 private String _sql; 37 private Statement _statement; 38 39 public SimpleStatement(String SQL, Connection connection) throws SQLException 40 { 41 _sql = SQL; 42 _statement = connection.createStatement(); 43 } 44 45 public SimpleStatement(String SQL, Connection connection, int resultSetType, int resultSetConcurrency) 46 throws SQLException 47 { 48 _sql = SQL; 49 _statement = connection.createStatement(resultSetType, resultSetConcurrency); 50 } 51 52 56 57 public String getSQL() 58 { 59 return _sql; 60 } 61 62 66 67 public Statement getStatement() 68 { 69 return _statement; 70 } 71 72 76 77 public void close() throws SQLException 78 { 79 _statement.close(); 80 81 _statement = null; 82 _sql = null; 83 } 84 85 89 90 public ResultSet executeQuery() throws SQLException 91 { 92 if (LOG.isDebugEnabled()) 93 LOG.debug("Executing query: " + this); 94 95 return _statement.executeQuery(_sql); 96 } 97 98 103 104 public int executeUpdate() throws SQLException 105 { 106 if (LOG.isDebugEnabled()) 107 LOG.debug("Executing update: " + this); 108 109 return _statement.executeUpdate(_sql); 110 } 111 112 public String toString() 113 { 114 StringBuffer buffer; 115 116 buffer = new StringBuffer ("SimpleStatement@"); 117 buffer.append(Integer.toHexString(hashCode())); 118 119 buffer.append("[SQL=<\n"); 120 buffer.append(_sql); 121 buffer.append("\n>]"); 122 123 return buffer.toString(); 124 } 125 126 } | Popular Tags |