View Javadoc

1   /*
2    * Created on 05-Nov-2004
3    */
4   package org.jdiagnose.library.db;
5   
6   import java.sql.Connection;
7   import java.sql.Statement;
8   
9   import javax.sql.DataSource;
10  
11  import org.jdiagnose.DiagnosticUnit;
12  
13  /***
14   * @author jmccrindle
15   */
16  public class DataSourceDiagnostic extends DiagnosticUnit {
17      
18      /***
19       * Default Constructor
20       */
21      public DataSourceDiagnostic() {
22          super();
23      }
24      /***
25       * @param name
26       */
27      public DataSourceDiagnostic(String name) {
28          super(name);
29      }
30      private DataSource dataSource = null;
31      private String sql = null;
32      
33      public void diagnoseSql() throws Exception {
34          Connection connection = null;
35          try {
36              connection = dataSource.getConnection();
37              Statement statement = connection.createStatement();
38              statement.execute(sql);
39          } finally {
40              if(connection != null) {
41                  connection.close();
42              }
43          }
44      }
45      
46      public DataSource getDataSource() {
47          return dataSource;
48      }
49      
50      public void setDataSource(DataSource dataSource) {
51          this.dataSource = dataSource;
52      }
53      
54      public String getSql() {
55          return sql;
56      }
57      
58      public void setSql(String sql) {
59          this.sql = sql;
60      }
61  }