1 16 17 package org.apache.commons.dbcp; 18 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 23 import junit.framework.Test; 24 import junit.framework.TestCase; 25 import junit.framework.TestSuite; 26 27 33 public class TestOracleBasicDataSource extends TestCase { 34 public TestOracleBasicDataSource(String testName) { 35 super(testName); 36 } 37 38 public static Test suite() { 39 return new TestSuite(TestOracleBasicDataSource.class); 40 } 41 42 protected Connection getConnection() throws Exception { 43 return ds.getConnection(); 44 } 45 46 protected BasicDataSource ds = null; 47 private static String CATALOG = "test catalog"; 48 49 public void setUp() throws Exception { 50 super.setUp(); 51 ds = new BasicDataSource(); 52 ds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); 53 ds.setUrl("jdbc:oracle:thin:@localhost:1521:DEMO"); 54 ds.setMaxActive(10); 55 ds.setMaxWait(100); 56 ds.setDefaultAutoCommit(true); 57 ds.setDefaultReadOnly(true); 58 ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); 59 ds.setUsername("SCOTT"); 61 ds.setPassword("TIGER"); 62 ds.setValidationQuery("SELECT DUMMY FROM DUAL"); 63 } 64 65 public void tearDown() throws Exception { 66 super.tearDown(); 67 ds = null; 68 } 69 70 public void testSimple() throws Exception { 71 Connection conn = getConnection(); 72 assertTrue(null != conn); 73 PreparedStatement stmt = conn.prepareStatement("select * from dual"); 74 assertTrue(null != stmt); 75 ResultSet rset = stmt.executeQuery(); 76 assertTrue(null != rset); 77 assertTrue(rset.next()); 78 rset.close(); 79 stmt.close(); 80 conn.close(); 81 } 82 83 84 } 85 | Popular Tags |