git-svn-id: http://code.alibabatech.com/svn/druid/trunk@2 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-05-11 01:35:21 +00:00
parent 239363b62e
commit 0e60b7d988
524 changed files with 67045 additions and 0 deletions
@@ -0,0 +1,78 @@
package com.alibaba.druid.bvt.proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.util.JdbcUtils;
public class StatementTest extends TestCase {
private static String create_url = "jdbc:wrap-jdbc:filters=default,commonLogging,log4j:name=statementTest:jdbc:derby:memory:statementTest;create=true";
protected void setUp() throws Exception {
Class.forName("com.alibaba.druid.proxy.DruidDriver");
Connection conn = DriverManager.getConnection(create_url);
createTable();
conn.close();
}
private void createTable() throws SQLException {
Connection conn = DriverManager.getConnection(create_url);
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE T_PRE_STMT_TEST (ID INTEGER GENERATED BY DEFAULT AS IDENTITY, NAME VARCHAR(50), BIRTHDATE TIMESTAMP)");
stmt.close();
conn.close();
}
private void dropTable() throws SQLException {
Connection conn = DriverManager.getConnection(create_url);
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE T_PRE_STMT_TEST");
stmt.close();
conn.close();
}
protected void tearDown() throws Exception {
dropTable();
}
public void test_stmt() throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(create_url);
stmt = conn.createStatement();
stmt.execute("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (1, 'A', NULL)");
stmt.execute("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (11, 'A1', NULL)", Statement.NO_GENERATED_KEYS);
stmt.execute("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (12, 'A2', NULL)", new int[] {1});
stmt.execute("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (12, 'A3', NULL)", new String[] {"ID"});
stmt.executeUpdate("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (2, 'B', NULL)");
stmt.executeUpdate("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (3, 'C', NULL)", Statement.NO_GENERATED_KEYS);
stmt.executeUpdate("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (4, 'D', NULL)", new int[] {1});
stmt.executeUpdate("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (5, 'E', NULL)", new String[] {"ID"});
try {stmt.cancel(); } catch (SQLFeatureNotSupportedException ex) {}
stmt.execute("SELECT * FROM T_PRE_STMT_TEST");
Assert.assertFalse(stmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
JdbcUtils.close(conn);
}
}
}