diff --git a/pom.xml b/pom.xml index fc5e4719668ad30a9ae7734d07d321e019044306..25771540e7aca1be6759cc9887e9afa767a903db 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,12 @@ mysql-connector-java 8.0.28 + + + org.postgresql + postgresql + 42.6.0 + cn.hutool diff --git a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java index 4ab92a91f50820ab005702c8ddc56bf2e7f198f0..b227d34ddf441364a1c885813b4fdd998099a425 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java @@ -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://:/:informixserver= - 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"); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2b2ede3bf591a1a7eacd38521aa777e4164cdabc..b540ae1e96ec7e243a23e6f5adf21107b4b4398a 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -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: