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

polardbx的curd测试

parent cb3b0f8e
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version> <version>8.0.28</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
......
...@@ -44,16 +44,16 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -44,16 +44,16 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
// 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(); Driver driver = getDriver();
Connection conn = getConnection(driver); Connection conn = getConnection(driver);
insert(conn); // insert(conn);
// update(conn); // update(conn);
// query(conn); query(conn);
// delete(conn); // delete(conn);
closeConnection(conn); closeConnection(conn);
deregisterDriver(driver); deregisterDriver(driver);
} }
private Driver getDriver() throws Exception{ private Driver getDriver() throws Exception{
// 定义informix的驱动信息 // 定义informix的驱动信息
String driverUrl = "com.mysql.cj.jdbc.Driver"; String driverUrl = "org.postgresql.Driver";
// 还需要加入informix的jdbc驱动jar包 // 还需要加入informix的jdbc驱动jar包
Class<?> driverClass = Class.forName(driverUrl); Class<?> driverClass = Class.forName(driverUrl);
return (Driver) driverClass.getConstructor().newInstance(); return (Driver) driverClass.getConstructor().newInstance();
...@@ -66,7 +66,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -66,7 +66,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
// 创建testdb数据库、my_test_create_table表 // 创建testdb数据库、my_test_create_table表
// 现在模拟插入、更新、删除、查询等sql // 现在模拟插入、更新、删除、查询等sql
// 插入 // 插入
String insertSql = "insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) values (?, ? , ?, ?, ? , ?,?,? )"; String insertSql = "insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey) values (?, ? , ?, ?, ? , ?)";
PreparedStatement stat = conn.prepareStatement(insertSql); PreparedStatement stat = conn.prepareStatement(insertSql);
stat.setObject(1, "123456"); stat.setObject(1, "123456");
stat.setObject(2, "vname"); stat.setObject(2, "vname");
...@@ -75,14 +75,14 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -75,14 +75,14 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
stat.setObject(5, 3); stat.setObject(5, 3);
stat.setObject(6, "updatekey"); stat.setObject(6, "updatekey");
String clobContent = "This is a very very long string"; String clobContent = "This is a very very long string";
// 处理clob字段 // // 处理clob字段
StringReader reader = new StringReader(clobContent); // StringReader reader = new StringReader(clobContent);
stat.setClob(7, reader, clobContent.length()); // stat.setClob(7, reader, clobContent.length());
// 处理blob字段 // 处理blob字段
Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe"); // Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
File inputStream = resource.getFile(); // File inputStream = resource.getFile();
FileInputStream fis = new FileInputStream(inputStream); // FileInputStream fis = new FileInputStream(inputStream);
stat.setBlob(8, fis); // stat.setBlob(8, fis);
stat.executeUpdate(); stat.executeUpdate();
} }
private void update(Connection conn) throws Exception{ private void update(Connection conn) throws Exception{
...@@ -94,40 +94,31 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -94,40 +94,31 @@ 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 vccid,vccname from cti_vccinfo_new where vccid = ? ";
PreparedStatement stat = conn.prepareStatement(querySQL); PreparedStatement stat = conn.prepareStatement(querySQL);
// 设置查询参数,不拓展查询
stat.setObject(1, "1", Types.OTHER);
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);
} }
/**
* 指定不用预编译语句 prepareThreshold=0
* @param driver
* @return
* @throws Exception
*/
private Connection getConnection(Driver driver) throws Exception{ private Connection getConnection(Driver driver) throws Exception{
DriverManager.registerDriver(driver); DriverManager.registerDriver(driver);
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:postgresql://localhost:3307")
.append("/") .append("/")
.append("testdb").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); .append("SYSDBA").append("?prepareThreshold=0");
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
properties.put("user", "root"); properties.put("user", "root");
properties.put("password", "Apurelove9014"); properties.put("password", "Apurelove9014");
......
...@@ -4,7 +4,7 @@ spring: ...@@ -4,7 +4,7 @@ spring:
# url: jdbc:informix-sqli://localhost:9088/testdb:INFORMIXSERVER=informix # url: jdbc:informix-sqli://localhost:9088/testdb:INFORMIXSERVER=informix
#&useServerPrepStmts=true #&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:postgresql://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 # username: informix
...@@ -22,7 +22,7 @@ spring: ...@@ -22,7 +22,7 @@ spring:
# test-while-idle: false # test-while-idle: false
# time-between-eviction-runs-millis: 60000 # 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: org.postgresql.Driver # com.mysql.cj.jdbc.Driver
jpa: jpa:
properties: properties:
hibernate: hibernate:
......
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