KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > ejb > JDBCComplianceBean


1 package org.jboss.test.jca.ejb;
2
3 import java.rmi.RemoteException 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 javax.ejb.EJBException JavaDoc;
10 import javax.ejb.SessionBean JavaDoc;
11 import javax.ejb.SessionContext JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13 import javax.naming.NamingException JavaDoc;
14 import javax.sql.DataSource JavaDoc;
15
16
17 /**
18  * A JDBCComplianceBean.
19  *
20  * @ejb.bean
21  * name="JDBCComplianceBean"
22  * view-type="remote"
23  * type="Stateless"
24  *
25  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
26  * @version $Revision: 1.1 $
27  */

28 public class JDBCComplianceBean implements SessionBean JavaDoc
29 {
30    /**
31     * @throws javax.ejb.CreateException Description of Exception
32     * @ejb.create-method
33     */

34    public void ejbCreate()
35    {
36       
37    }
38    public void ejbActivate() throws EJBException JavaDoc, RemoteException JavaDoc
39    {
40       
41    }
42
43    public void ejbPassivate() throws EJBException JavaDoc, RemoteException JavaDoc
44    {
45       
46    }
47
48    public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc
49    {
50       
51    }
52
53    public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc, RemoteException JavaDoc
54    {
55       
56    }
57    
58    /**
59     * @ejb.interface-method
60     * @ejb.transaction type="Supports"
61     */

62    public void testJdbcCloseCompliance()
63    {
64       InitialContext JavaDoc ctx = null;
65       DataSource JavaDoc ds = null;
66       Connection JavaDoc conn = null;
67       Statement JavaDoc s = null;
68       ResultSet JavaDoc rs = null;
69       
70       try
71       {
72          ctx = new InitialContext JavaDoc();
73          ds = (DataSource JavaDoc)ctx.lookup("java:/ComplianceDS");
74          conn = ds.getConnection("sa", "");
75          s = conn.createStatement();
76          s.execute("CREATE TABLE DUMMY (id int, dummy varchar(10))");
77          rs = s.executeQuery("SELECT * FROM DUMMY");
78          s.execute("DROP TABLE DUMMY");
79          rs.close();
80          s.close();
81          conn.close();
82       }
83       catch (NamingException JavaDoc e)
84       {
85          throw new EJBException JavaDoc(e.getMessage());
86       }
87       catch (SQLException JavaDoc e)
88       {
89          throw new EJBException JavaDoc(e.getMessage());
90
91       }finally
92       {
93          
94          try
95          {
96             if(rs != null)
97             {
98                rs.close();
99                
100             }
101             
102             if(s != null)
103             {
104                s.close();
105             }
106             
107             if(conn != null)
108             {
109                conn.close();
110                
111             }
112          }
113          catch (SQLException JavaDoc e)
114          {
115             throw new EJBException JavaDoc(e.getMessage());
116          }
117       }
118       
119    }
120
121    
122 }
123
Popular Tags