Commit b42edb8a authored by 李振振's avatar 李振振

polardbx的curd测试

parent cb3b0f8e
......@@ -11,6 +11,10 @@ import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author lzz
......@@ -40,16 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
*/
@Override
public void doConnectJob() throws Exception{
// todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题
// // todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题
// // Unknown exception: Can not find JDBC type `2005` in column type
// Driver driver = getDriver();
// Connection conn = getConnection(driver);
// insert(conn);
//// update(conn);
//// query(conn);
//// delete(conn);
// closeConnection(conn);
// deregisterDriver(driver);
// Unknown exception: Can not find JDBC type `2005` in column type
CompletableFuture completableFuture = new CompletableFuture<>();
ExecutorService executorService = Executors.newFixedThreadPool(500);
for (int i = 0; i < 500; i++) {
try {
Driver driver = getDriver();
Connection conn = getConnection(driver);
insert(conn);
// update(conn);
// query(conn);
// delete(conn);
completableFuture.runAsync(()->{
try {
query(conn);
}catch (Exception ee) {
ee.printStackTrace();
}
}, executorService).whenComplete((v, e) -> {
if (e != null) {
e.printStackTrace();
}
try {
closeConnection(conn);
deregisterDriver(driver);
}catch (Exception ex) {
ex.printStackTrace();
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
private Driver getDriver() throws Exception{
// 定义informix的驱动信息
......@@ -94,28 +126,13 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
stat.executeUpdate();
}
private void query(Connection conn) throws Exception {
String querySQL = "select * from cti_vccinfo_new where vccid = '123456' ";
String querySQL = "SELECT id FROM sc_test ";
PreparedStatement stat = conn.prepareStatement(querySQL);
ResultSet resultSet = stat.executeQuery();
if (resultSet != null) {
while (resultSet.next()) {
log.info("vccid =>" + resultSet.getString("vccid"));
Clob clob = resultSet.getClob("tclob");
BufferedReader reader = new BufferedReader(clob.getCharacterStream());
String clobStr = "";
String finalClobStr = "";
while ((clobStr = reader.readLine())!= null) {
finalClobStr += clobStr;
}
log.info("tclob =>" + finalClobStr);
Blob blob = resultSet.getBlob("tblob");
BufferedInputStream bins= new BufferedInputStream(blob.getBinaryStream());
byte [] bytes = bins.readAllBytes();
String blobStr= new String(bytes, StandardCharsets.UTF_8);
log.info("tblob =>" + blobStr);
}
}
}
private void delete(Connection conn) throws Exception{
String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' ";
conn.createStatement().executeUpdate(deleteSql);
......@@ -125,9 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
Properties properties = new Properties();
// 组装连接数据库信息
// jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername>
StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307")
.append("/")
.append("testdb").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true");
StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307");
// .append("/")
// .append("SYSDBA")
// .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true");
DriverManager.setLoginTimeout(10);
properties.put("user", "root");
properties.put("password", "Apurelove9014");
......@@ -136,4 +154,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
private void closeConnection(Connection connection) throws Exception {
connection.close();
}
}
......@@ -17,7 +17,12 @@ import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author lzz
......@@ -35,10 +40,22 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
@Override
@Transactional
public void doConnectJob() throws Exception{
insertMethod();
// updateMethod();
// queryMethod();
// delete();
CompletableFuture completableFuture = new CompletableFuture<>();
ExecutorService executorService = Executors.newFixedThreadPool(500);
for (int i = 0; i < 500; i++) {
try {
completableFuture.runAsync(()->{
queryMethod();
}, executorService).whenComplete((v, e) -> {
if (e != null) {
e.printStackTrace();
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
private void insertMethod() throws Exception{
Vccinfo vccinfo = new Vccinfo();
......
spring:
datasource:
druid:
# url: jdbc:informix-sqli://localhost:9088/testdb:INFORMIXSERVER=informix
#&useServerPrepStmts=true
# url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
url: jdbc:mysql://localhost:3307
# url: jdbc:mysql://localhost:3307/SYSDBA?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
# url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true
username: root
# username: informix
# password: in4mix
password: Apurelove9014
# max-active: 20
# max-wait: 60000
# initial-size: 5
# connect-timeout: 30
# min-idle: 5
# min-evictable-idle-time-millis: 300000
# validation-query: select 1
# test-on-borrow: false
# test-on-return: false
# test-while-idle: false
# time-between-eviction-runs-millis: 60000
type: com.alibaba.druid.pool.DruidDataSource
druid:
max-active: 500
max-wait: 60000
initial-size: 500
connect-timeout: 30
min-idle: 500
min-evictable-idle-time-millis: 300000
validation-query: select 1
test-on-borrow: false
test-on-return: false
test-while-idle: false
time-between-eviction-runs-millis: 60000
# driver-class-name: com.informix.jdbc.IfxDriver
driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver
jpa:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment