1 package org.jboss.test.jca.ejb; 2 3 import java.rmi.RemoteException ; 4 import java.sql.Connection ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 import java.sql.Statement ; 8 9 import javax.ejb.EJBException ; 10 import javax.ejb.SessionBean ; 11 import javax.ejb.SessionContext ; 12 import javax.naming.InitialContext ; 13 import javax.naming.NamingException ; 14 import javax.sql.DataSource ; 15 16 17 28 public class JDBCComplianceBean implements SessionBean 29 { 30 34 public void ejbCreate() 35 { 36 37 } 38 public void ejbActivate() throws EJBException , RemoteException 39 { 40 41 } 42 43 public void ejbPassivate() throws EJBException , RemoteException 44 { 45 46 } 47 48 public void ejbRemove() throws EJBException , RemoteException 49 { 50 51 } 52 53 public void setSessionContext(SessionContext ctx) throws EJBException , RemoteException 54 { 55 56 } 57 58 62 public void testJdbcCloseCompliance() 63 { 64 InitialContext ctx = null; 65 DataSource ds = null; 66 Connection conn = null; 67 Statement s = null; 68 ResultSet rs = null; 69 70 try 71 { 72 ctx = new InitialContext (); 73 ds = (DataSource )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 e) 84 { 85 throw new EJBException (e.getMessage()); 86 } 87 catch (SQLException e) 88 { 89 throw new EJBException (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 e) 114 { 115 throw new EJBException (e.getMessage()); 116 } 117 } 118 119 } 120 121 122 } 123 | Popular Tags |