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

polardbx的curd测试

parent cb3b0f8e
...@@ -11,6 +11,10 @@ import java.io.*; ...@@ -11,6 +11,10 @@ import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.*; import java.sql.*;
import java.util.Properties; 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 * @author lzz
...@@ -40,16 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -40,16 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
*/ */
@Override @Override
public void doConnectJob() throws Exception{ 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 // Unknown exception: Can not find JDBC type `2005` in column type
Driver driver = getDriver(); CompletableFuture completableFuture = new CompletableFuture<>();
Connection conn = getConnection(driver); ExecutorService executorService = Executors.newFixedThreadPool(500);
insert(conn); for (int i = 0; i < 500; i++) {
// update(conn); try {
// query(conn); Driver driver = getDriver();
// delete(conn); Connection conn = getConnection(driver);
closeConnection(conn); completableFuture.runAsync(()->{
deregisterDriver(driver); 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{ private Driver getDriver() throws Exception{
// 定义informix的驱动信息 // 定义informix的驱动信息
...@@ -94,28 +126,13 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -94,28 +126,13 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
stat.executeUpdate(); stat.executeUpdate();
} }
private void query(Connection conn) throws Exception { 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); PreparedStatement stat = conn.prepareStatement(querySQL);
ResultSet resultSet = stat.executeQuery(); 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{ private void delete(Connection conn) throws Exception{
String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' "; String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' ";
conn.createStatement().executeUpdate(deleteSql); conn.createStatement().executeUpdate(deleteSql);
...@@ -125,9 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -125,9 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
Properties properties = new Properties(); Properties properties = new Properties();
// 组装连接数据库信息 // 组装连接数据库信息
// jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername> // jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername>
StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307") StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307");
.append("/") // .append("/")
.append("testdb").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); // .append("SYSDBA")
// .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true");
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
properties.put("user", "root"); properties.put("user", "root");
properties.put("password", "Apurelove9014"); properties.put("password", "Apurelove9014");
...@@ -136,4 +154,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -136,4 +154,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
private void closeConnection(Connection connection) throws Exception { private void closeConnection(Connection connection) throws Exception {
connection.close(); connection.close();
} }
} }
...@@ -17,7 +17,12 @@ import javax.annotation.Resource; ...@@ -17,7 +17,12 @@ import javax.annotation.Resource;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* @author lzz * @author lzz
...@@ -35,10 +40,22 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin ...@@ -35,10 +40,22 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
@Override @Override
@Transactional @Transactional
public void doConnectJob() throws Exception{ public void doConnectJob() throws Exception{
insertMethod(); CompletableFuture completableFuture = new CompletableFuture<>();
// updateMethod(); ExecutorService executorService = Executors.newFixedThreadPool(500);
// queryMethod(); for (int i = 0; i < 500; i++) {
// delete(); 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{ private void insertMethod() throws Exception{
Vccinfo vccinfo = new Vccinfo(); Vccinfo vccinfo = new Vccinfo();
......
spring: spring:
datasource: 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&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 # url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true
username: root username: root
# username: informix
# password: in4mix
password: Apurelove9014 password: Apurelove9014
# max-active: 20 type: com.alibaba.druid.pool.DruidDataSource
# max-wait: 60000 druid:
# initial-size: 5 max-active: 500
# connect-timeout: 30 max-wait: 60000
# min-idle: 5 initial-size: 500
# min-evictable-idle-time-millis: 300000 connect-timeout: 30
# validation-query: select 1 min-idle: 500
# test-on-borrow: false min-evictable-idle-time-millis: 300000
# test-on-return: false validation-query: select 1
# test-while-idle: false test-on-borrow: false
# time-between-eviction-runs-millis: 60000 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.informix.jdbc.IfxDriver
driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver
jpa: 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