mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
user clearDefines optimize Oracle PrepareStatement Cache memoery use
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import oracle.jdbc.driver.OraclePreparedStatement;
|
||||
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class TestOraclePreparedStatement extends TestCase {
|
||||
|
||||
private String jdbcUrl;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
jdbcUrl = "jdbc:oracle:thin:@10.20.149.85:1521:ocnauto";
|
||||
// jdbcUrl = "jdbc:oracle:thin:@20.20.149.85:1521:ocnauto"; // error url
|
||||
user = "alibaba";
|
||||
password = "ccbuauto";
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
Class.forName(JdbcUtils.getDriverClassName(jdbcUrl));
|
||||
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
||||
// ResultSet metaRs = conn.getMetaData().getTables(null, "ALIBABA", null, new String[] {"TABLE"});
|
||||
// JdbcUtils.printResultSet(metaRs);
|
||||
// metaRs.close();
|
||||
|
||||
OraclePreparedStatement oracleStmt = null;
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT ? FROM DUAL");
|
||||
oracleStmt = (OraclePreparedStatement) stmt;
|
||||
{
|
||||
|
||||
stmt.setString(1, "aaa");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
rs.close();
|
||||
|
||||
oracleStmt.clearDefines();
|
||||
}
|
||||
{
|
||||
stmt.setString(1, "bbb");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class TestOracle_DruidDataSource extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
final String SQL = "SELECT SYSDATE FROM DUAL";
|
||||
final DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
Reference in New Issue
Block a user