ASF Bugzilla – Attachment 34224 Details for
Bug 60099
StatementCache does not check the scrollable type of result set when searching for a cached statement
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Test class
Test.java (text/x-java), 3.60 KB, created by
Mohamad ABBAS
on 2016-09-08 20:30:21 UTC
(
hide
)
Description:
Test class
Filename:
MIME Type:
Creator:
Mohamad ABBAS
Created:
2016-09-08 20:30:21 UTC
Size:
3.60 KB
patch
obsolete
>package test; > >import java.sql.Connection; >import java.sql.DriverManager; >import java.sql.PreparedStatement; >import java.sql.ResultSet; >import java.sql.Statement; > >import org.apache.tomcat.jdbc.pool.DataSource; >import org.apache.tomcat.jdbc.pool.PoolProperties; > >public class Test { > > public static void main(String[] args) throws Exception { > createAndInitDB(); > DataSource datasource = getDataSource(); > testWithForwardOnlyResultSet(datasource); > testWithInsensitiveResultSet(datasource); > } > > private static void createAndInitDB() throws Exception { > System.out.println(">>> Begin creating and initializing database"); > Connection conn = DriverManager.getConnection("jdbc:derby:memory:jdbc/test;create=true"); > System.out.println(">>> Database created"); > Statement st = conn.createStatement(); > System.out.println(">>> Create a test Table"); > st.execute("CREATE TABLE test_table (ID INT PRIMARY KEY, NAME VARCHAR(12))"); > System.out.println(">>> Test table created"); > System.out.println(">>> Inserting data into database"); > st.execute("INSERT INTO test_table values(1, 'test1')"); > st.execute("INSERT INTO test_table values(2, 'test2')"); > System.out.println(">>> Retrieving data from database:"); > ResultSet rs = st.executeQuery("SELECT * FROM test_table"); > System.out.println(">>> Found 2 rows:"); > while (rs.next()) { > System.out.println("\tID = " + rs.getString(1) + ", NAME = " + rs.getString(2)); > } > rs.close(); > st.close(); > conn.close(); > } > > private static DataSource getDataSource() { > PoolProperties p = new PoolProperties(); > p.setUrl("jdbc:derby:memory:jdbc/test"); > p.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); > p.setMaxActive(1); // to simplify test > p.setInitialSize(1); // to simplify test > p.setMaxWait(1); // to simplify test > p.setMinIdle(1); // to simplify test > p.setMaxIdle(1); // to simplify test > p.setJdbcInterceptors("StatementCache(max=10)"); // No Exception is thrown when set to 0 > return new DataSource(p); > } > > private static void testWithForwardOnlyResultSet(DataSource datasource) throws Exception { > System.out.println(">>> Begin test by creating a Prepared Statement with a FORWARD_ONLY ResultSet"); > Connection con = datasource.getConnection(); > PreparedStatement st = con.prepareStatement("SELECT * FROM test_table"); > ResultSet rs = st.executeQuery(); > System.out.println(">>> Found 2 rows in database:"); > while (rs.next()) { > System.out.println("\tID = " + rs.getString(1) + ", NAME = " + rs.getString(2)); > } > rs.close(); > st.close(); > con.close(); > } > > private static void testWithInsensitiveResultSet(DataSource datasource) throws Exception { > System.out.println(">>> Continue test by creating a Prepared Statement with a SCROLL_INSENSITIVE ResultSet."); > Connection con = datasource.getConnection(); > PreparedStatement st = con.prepareStatement("SELECT * FROM test_table", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); > ResultSet rs = st.executeQuery(); > rs.absolute(1); > System.out.println(">>> Found 1 row:"); > while (rs.next()) { > System.out.println("\tID = " + rs.getString(1) + ", NAME = " + rs.getString(2)); > } > rs.close(); > st.close(); > con.close(); > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 60099
: 34224