KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > vendor > SybaseValidConnectionChecker


1 package org.jboss.resource.adapter.jdbc.vendor;
2
3 import java.io.Serializable JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.sql.Statement JavaDoc;
8
9 import org.jboss.logging.Logger;
10 import org.jboss.resource.adapter.jdbc.ValidConnectionChecker;
11
12 /**
13  * A SybaseValidConnectionChecker.
14  *
15  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
16  * @version $Revision: 1.1 $
17  */

18 public class SybaseValidConnectionChecker implements ValidConnectionChecker, Serializable JavaDoc
19 {
20    private static final Logger log = Logger.getLogger(SybaseValidConnectionChecker.class);
21    
22    /** The serialVersionUID */
23    private static final long serialVersionUID = 4179707462244257791L;
24    
25    /** The VALID_QUERY */
26    private static final String JavaDoc VALID_QUERY = "SELECT getdate()";
27    
28    
29    public SQLException JavaDoc isValidConnection(Connection JavaDoc c)
30    {
31       SQLException JavaDoc sqe = null;
32       Statement JavaDoc s = null;
33       ResultSet JavaDoc rs = null;
34       
35          try
36          {
37             s = c.createStatement();
38             rs = s.executeQuery(VALID_QUERY);
39             
40          }catch (SQLException JavaDoc e)
41          {
42                    
43             sqe = e;
44             
45          }finally
46          {
47             
48             try
49             {
50                if(s != null)
51                {
52                   s.close();
53                   
54                }
55             }
56             
57             catch (SQLException JavaDoc ignore)
58             {
59                log.warn("JDBC resource for " + this + " could not be closed");
60                
61             }
62          
63             try
64             {
65                if(rs != null)
66                {
67                   rs.close();
68                }
69             }
70             
71             catch (SQLException JavaDoc ignore)
72             {
73                log.warn("JDBC resource for " + this + " could not be closed");
74             }
75          }
76                   
77       
78       return sqe;
79    }
80
81 }
82
Popular Tags