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

polardbx的curd测试

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