import junit.framework.TestCase; import java.sql.*; /* * Created on 13.05.2004 by Stefan Haustein */ public class OracleTest extends TestCase { // please change the following three lines to your local needs static final String URL = "jdbc:oracle:thin:@localhost:1521"; static final String USER = "user"; static final String PASSWORD = "pwd"; Connection connection; Statement statement; public OracleTest(String s){ super(s); } public void setUp() throws Exception { DriverManager.registerDriver((Driver) Class.forName("oracle.jdbc.driver.OracleDriver") .newInstance()); connection = DriverManager.getConnection(URL, USER, PASSWORD); statement = connection.createStatement (ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); try{ statement.executeUpdate("DROP TABLE JUnit"); } catch(SQLException e){ } statement.executeUpdate("CREATE TABLE JUnit (title VARCHAR2(40), \"number\" VARCHAR2(40))" ); statement.executeUpdate("INSERT INTO Junit VALUES ('Bar Of Foo', 'five hundred')" ); statement.executeUpdate("INSERT INTO Junit VALUES ('Kitchen Sink', 'two and a half')" ); } public void tearDown() throws Exception { statement.executeUpdate("DROP TABLE JUnit"); statement.close(); connection.close(); } // works fine, just included to test the set-up public void test1() throws SQLException{ ResultSet rs = statement.executeQuery("select title from JUnit"); int count = 1; while(rs.next()){ rs.updateString("title", "test 0/"+(count++)); rs.updateRow(); } rs.close(); } // Oracle cannot handle this public void test2() throws SQLException{ ResultSet rs = statement.executeQuery("select * from JUnit"); int count = 1; while(rs.next()){ rs.updateString("title", "test 1/"+(count++)); rs.updateRow(); } rs.close(); } // Oracle cannot handle this public void test3() throws SQLException{ ResultSet rs = statement.executeQuery("select \"number\" from JUnit"); int count = 1; while(rs.next()){ rs.updateString("number", "test 2/"+(count++)); rs.updateRow(); } rs.close(); } // Oracle does not support standard SQL92 operations such as "position" public void test4() throws SQLException{ ResultSet rs = statement.executeQuery("select * from JUnit where (position('test' in title) > 0)"); rs.close(); } // Oracle does not care to implement finalization public void test5() throws SQLException{ for(int i = 0; i < 10000; i++){ if (i % 100 == 0) Runtime.getRuntime().gc(); Statement s = connection.createStatement(); ResultSet rs = s.executeQuery("select title from JUnit"); } } public static void main(String[] args) throws Exception{ new OracleTest("test1").run(); new OracleTest("test2").run(); new OracleTest("test3").run(); new OracleTest("test4").run(); new OracleTest("test5").run(); } }