use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.
the class StatFilterExecErrorTest method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("stat");
dataSource.setTestOnBorrow(false);
dataSource.getProxyFilters().add(new FilterAdapter() {
@Override
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
throw new SQLException();
}
@Override
public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
});
dataSource.init();
}
use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.
the class DruidPooledPreparedStatementTest1 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(1);
dataSource.getProxyFilters().add(new FilterAdapter() {
@Override
public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
public void preparedStatement_clearParameters(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public ParameterMetaData preparedStatement_getParameterMetaData(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
});
}
use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.
the class DruidPooledConnectionTest_prepareError method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setFilters("stat");
dataSource.setPoolPreparedStatements(true);
dataSource.getProxyFilters().add(new FilterAdapter() {
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
throw new SQLException();
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLException();
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new SQLException();
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new SQLException();
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int[] columnIndexes) throws SQLException {
throw new SQLException();
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, String[] columnNames) throws SQLException {
throw new SQLException();
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
throw new SQLException();
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new SQLException();
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new SQLException();
}
});
}
use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.
the class PreparedStatementProxyImplTest method test_setObject.
public void test_setObject() throws Exception {
String sql = "insert t values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setObject(1, (byte) 1);
stmt.setObject(2, (short) 1);
stmt.setObject(3, (int) 1);
stmt.setObject(4, (long) 1);
stmt.setObject(5, (float) 1);
stmt.setObject(6, (double) 1);
stmt.setObject(7, new BigDecimal(1));
stmt.setObject(8, true);
stmt.setObject(9, "xxx");
stmt.setObject(10, new java.sql.Date(System.currentTimeMillis()));
stmt.setObject(11, new java.util.Date(System.currentTimeMillis()));
stmt.setObject(12, new java.sql.Timestamp(System.currentTimeMillis()));
stmt.setObject(13, new java.sql.Time(System.currentTimeMillis()));
stmt.execute();
PreparedStatementProxy stmtProxy = stmt.unwrap(PreparedStatementProxy.class);
Assert.assertNotNull(stmtProxy);
Assert.assertEquals(Types.TINYINT, stmtProxy.getParameter(0).getSqlType());
Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameter(1).getSqlType());
Assert.assertEquals(Types.INTEGER, stmtProxy.getParameter(2).getSqlType());
Assert.assertEquals(Types.BIGINT, stmtProxy.getParameter(3).getSqlType());
Assert.assertEquals(Types.FLOAT, stmtProxy.getParameter(4).getSqlType());
Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameter(5).getSqlType());
Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameter(6).getSqlType());
Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameter(7).getSqlType());
Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameter(8).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameter(9).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameter(10).getSqlType());
Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameter(11).getSqlType());
Assert.assertEquals(Types.TIME, stmtProxy.getParameter(12).getSqlType());
stmt.close();
conn.close();
}
use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.
the class WallFilter method connection_prepareStatement.
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int autoGeneratedKeys) throws SQLException {
String dbType = connection.getDirectDataSource().getDbType();
WallContext.create(dbType);
try {
sql = check(sql);
PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, autoGeneratedKeys);
setSqlStatAttribute(stmt);
return stmt;
} finally {
WallContext.clearContext();
}
}
Aggregations