mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
74 lines
1.9 KiB
Java
74 lines
1.9 KiB
Java
package com.alibaba.druid.sql;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource;
|
|
import com.alibaba.druid.util.JdbcUtils;
|
|
|
|
public class OnlineOracleTest3 extends TestCase {
|
|
|
|
private String jdbcUrl;
|
|
private String user;
|
|
private String password;
|
|
private DruidDataSource dataSource;
|
|
|
|
public void setUp() throws Exception {
|
|
jdbcUrl = "jdbc:oracle:thin:@10.20.149.18:1521:emdb";
|
|
user = "wardon";
|
|
password = "wardon";
|
|
|
|
dataSource = new DruidDataSource();
|
|
dataSource.setInitialSize(1);
|
|
dataSource.setUrl(jdbcUrl);
|
|
dataSource.setUsername(user);
|
|
dataSource.setPassword(password);
|
|
dataSource.setMaxActive(50);
|
|
dataSource.setPoolPreparedStatements(true);
|
|
dataSource.setMaxOpenPreparedStatements(100);
|
|
// dataSource.setFilters("wall");
|
|
}
|
|
|
|
public void test_connect() throws Exception {
|
|
executeQuery("select UID, USER FROM DUAL");
|
|
}
|
|
|
|
public void executeQuery(String sql) throws SQLException {
|
|
Connection conn = null;
|
|
Statement stmt = null;
|
|
ResultSet rs = null;
|
|
try {
|
|
conn = dataSource.getConnection();
|
|
|
|
stmt = conn.createStatement();
|
|
rs = stmt.executeQuery(sql);
|
|
|
|
JdbcUtils.printResultSet(rs);
|
|
|
|
} finally {
|
|
JdbcUtils.close(rs);
|
|
JdbcUtils.close(stmt);
|
|
JdbcUtils.close(conn);
|
|
}
|
|
}
|
|
|
|
public void execute(String sql) throws SQLException {
|
|
Connection conn = null;
|
|
Statement stmt = null;
|
|
try {
|
|
conn = dataSource.getConnection();
|
|
|
|
stmt = conn.createStatement();
|
|
stmt.execute(sql);
|
|
|
|
} finally {
|
|
JdbcUtils.close(stmt);
|
|
JdbcUtils.close(conn);
|
|
}
|
|
}
|
|
}
|