|
@@ -1,12 +1,46 @@
|
|
|
package cn.com.qmth.examcloud.bridge;
|
|
|
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+
|
|
|
+import javax.sql.DataSource;
|
|
|
+
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import com.mchange.v2.c3p0.ComboPooledDataSource;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.util.DBUtil;
|
|
|
+
|
|
|
@Component
|
|
|
public class Tester {
|
|
|
|
|
|
public void test() {
|
|
|
+ testJdbc(ComboPooledDataSource.class, "ds1");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试JDBC
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param implementation
|
|
|
+ * @param dataSourceName
|
|
|
+ */
|
|
|
+ private void testJdbc(Class<? extends DataSource> implementation, final String dataSourceName) {
|
|
|
+ try {
|
|
|
+ DataSource ds1 = DBUtil.initDataSource("ds1");
|
|
|
+ Connection conn = ds1.getConnection();
|
|
|
+ PreparedStatement ps = conn.prepareStatement("select 10 from dual");
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
|
|
|
+ while (rs.next()) {
|
|
|
+ Object object = rs.getObject(1);
|
|
|
+ System.out.println(object);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|