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

polardbx的curd测试

parent b42edb8a
......@@ -17,39 +17,40 @@
<java.version>11</java.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.ibm.informix/jdbc -->
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.50.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<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>
<artifactId>hutool-all</artifactId>
<version>5.8.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.15</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<!-- <version>1.2.15</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
......@@ -97,6 +98,19 @@
<artifactId>mybatis-plus-core</artifactId>
<version>3.5.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18 -->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>8.1.2.192</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.dameng/Dm8JdbcDriver18 -->
<!-- <dependency>-->
<!-- <groupId>com.dameng</groupId>-->
<!-- <artifactId>Dm8JdbcDriver18</artifactId>-->
<!-- <version>8.1.1.49</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
......@@ -116,7 +130,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
......@@ -157,6 +170,14 @@
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
......@@ -2,10 +2,10 @@ package com.beagle.informix;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement(order = 2)
//@EnableTransactionManagement(order = 2)
public class BaseApplication {
public static void main(String[] args) {
......
package com.beagle.informix.entity.jpa;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Blob;
/**
* @author lzz
* date 2023/5/30
* @version 1.0
* description:
*/
@Data
@Table(name = "cti_vccinfo_new")
@Entity
public class Vccinfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
// todo 这个id自动生成方式还需测试
@Column(name = "vccid")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer vId;
@Column(name = "vccname")
private String vName;
@Column(name = "effective")
private Integer effective;
@Column(name = "agentmax")
private Integer agentMax;
@Column(name = "ivrmax")
private Integer ivrMax;
@Column(name = "updatekey")
private String updateKey;
@Column(name = "tclob")
@Basic(fetch = FetchType.LAZY)
private String tClob;
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "tblob", columnDefinition = "longblob", nullable = true)
private byte[] tBlob;
}
//package com.beagle.informix.entity.jpa;
//
//import lombok.Data;
//
//import javax.persistence.*;
//import java.io.Serializable;
//import java.sql.Blob;
//
///**
// * @author lzz
// * date 2023/5/30
// * @version 1.0
// * description:
// */
//@Data
////@、Table(name = "cti_vccinfo_new")
////@Entity
//public class Vccinfo implements Serializable {
// private static final long serialVersionUID = 1L;
// @Id
// // todo 这个id自动生成方式还需测试
// @Column(name = "vccid")
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer vId;
// @Column(name = "vccname")
// private String vName;
// @Column(name = "effective")
// private Integer effective;
// @Column(name = "agentmax")
// private Integer agentMax;
// @Column(name = "ivrmax")
// private Integer ivrMax;
// @Column(name = "updatekey")
// private String updateKey;
// @Column(name = "tclob")
// @Basic(fetch = FetchType.LAZY)
// private String tClob;
//
// @Lob
// @Basic(fetch = FetchType.LAZY)
// @Column(name = "tblob", columnDefinition = "longblob", nullable = true)
// private byte[] tBlob;
//}
package com.beagle.informix.entity.mybatis;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.sql.Blob;
/**
* @author lzz
* date 2023/5/30
* @version 1.0
* description:
*/
@Data
@TableName(value = "cti_vccinfo_new")
public class Vccinfo implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "vccid", type = IdType.AUTO )
private Integer vId;
@TableField(value = "vccname")
private String vName;
@TableField(value = "effective")
private Integer effective;
@TableField(value = "agentmax")
private Integer agentMax;
@TableField(value = "ivrmax")
private Integer ivrMax;
@TableField(value = "updatekey")
private String updateKey;
@TableField(value = "tclob")
private String tClob;
/**
* 如果是pg等数据库,字段声明为bytea,则不需要BlobTypeHandler转换,如果声明为blob,则需要转换
*/
// @TableField(value = "tblob", typeHandler = org.apache.ibatis.type.BlobTypeHandler.class)
@TableField(value = "tblob")
private byte[] tBlob;
}
//package com.beagle.informix.entity.mybatis;
//import com.baomidou.mybatisplus.annotation.IdType;
//import com.baomidou.mybatisplus.annotation.TableField;
//import com.baomidou.mybatisplus.annotation.TableId;
//import com.baomidou.mybatisplus.annotation.TableName;
//import lombok.Data;
//import java.io.Serializable;
//import java.sql.Blob;
//
///**
// * @author lzz
// * date 2023/5/30
// * @version 1.0
// * description:
// */
//@Data
//@TableName(value = "cti_vccinfo_new")
//public class Vccinfo implements Serializable {
// private static final long serialVersionUID = 1L;
// @TableId(value = "vccid", type = IdType.AUTO )
// private Integer vId;
// @TableField(value = "vccname")
// private String vName;
// @TableField(value = "effective")
// private Integer effective;
// @TableField(value = "agentmax")
// private Integer agentMax;
// @TableField(value = "ivrmax")
// private Integer ivrMax;
// @TableField(value = "updatekey")
// private String updateKey;
// @TableField(value = "tclob")
// private String tClob;
// /**
// * 如果是pg等数据库,字段声明为bytea,则不需要BlobTypeHandler转换,如果声明为blob,则需要转换
// */
//
//// @TableField(value = "tblob", typeHandler = org.apache.ibatis.type.BlobTypeHandler.class)
// @TableField(value = "tblob")
// private byte[] tBlob;
//}
package com.beagle.informix.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.beagle.informix.entity.mybatis.Vccinfo;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface VccinfoMapper extends BaseMapper<Vccinfo> {
@Results(
@Result(column = "tblob",property = "tBlobStr")
)
@Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}")
List<Vccinfo> queryList(@Param("vId") Integer vId);
/**
* 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库
* @param vccinfo
*/
void insertData(@Param("vccinfo") Vccinfo vccinfo);
}
//package com.beagle.informix.mapper;
//
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
//import com.beagle.informix.entity.mybatis.Vccinfo;
//import org.apache.ibatis.annotations.*;
//
//import java.util.List;
//
//@Mapper
//public interface VccinfoMapper extends BaseMapper<Vccinfo> {
// @Results(
// @Result(column = "tblob",property = "tBlobStr")
// )
// @Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}")
// List<Vccinfo> queryList(@Param("vId") Integer vId);
//
// /**
// * 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库
// * @param vccinfo
// */
// void insertData(@Param("vccinfo") Vccinfo vccinfo);
//}
package com.beagle.informix.repository;
import com.beagle.informix.entity.jpa.Vccinfo;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* @author lzz
* date 2023/5/30
* @version 1.0
* description:
*/
public interface VccinfoDao {
Vccinfo getVccInfoById(Integer vId);
List<Vccinfo> getAllVccInfo();
void addVccinfo(Vccinfo vccinfo);
void updateVccinfo(Vccinfo vccinfo);
void deleteVccinfo(Integer vId);
}
//package com.beagle.informix.repository;
//
////import com.beagle.informix.entity.jpa.Vccinfo;
////import org.springframework.data.repository.CrudRepository;
//
//import java.util.List;
//
///**
// * @author lzz
// * date 2023/5/30
// * @version 1.0
// * description:
// */
//public interface VccinfoDao {
// Vccinfo getVccInfoById(Integer vId);
// List<Vccinfo> getAllVccInfo();
// void addVccinfo(Vccinfo vccinfo);
// void updateVccinfo(Vccinfo vccinfo);
// void deleteVccinfo(Integer vId);
//}
package com.beagle.informix.repository.impl;
import com.beagle.informix.entity.jpa.Vccinfo;
import com.beagle.informix.repository.VccinfoDao;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;
import java.util.List;
/**
* @author lzz
* date 2023/5/30
* @version 1.0
* description:
*/
@Repository
public class VccinfoDaoImpl implements VccinfoDao {
@PersistenceContext
private EntityManager entityManager;
@Override
public Vccinfo getVccInfoById(Integer vId) {
return entityManager.find(Vccinfo.class, vId);
}
@Override
public List<Vccinfo> getAllVccInfo() {
String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective";
return (List<Vccinfo>) entityManager.createQuery(sql).getResultList();
}
@Override
public void addVccinfo(Vccinfo vccinfo) {
entityManager.persist(vccinfo);
// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" +
// " VALUES(?,?,?,?,?,?,?,?")
// .setParameter(1, vccinfo.getVId())
// .setParameter(2, vccinfo.getVName())
// .setParameter(3, vccinfo.getEffective())
// .setParameter(4, vccinfo.getAgentMax())
// .setParameter(5, vccinfo.getIvrMax())
// .setParameter(6, vccinfo.getUpdateKey())
// .setParameter(7, vccinfo.getTClob())
// .setParameter(8, vccinfo.getTBlob()).executeUpdate();
}
@Override
@Transactional
public void updateVccinfo(Vccinfo vccinfo) {
// 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value.
/*Vccinfo old = entityManager.find(Vccinfo.class, "jpa");
old.setVName("informix—name");
entityManager.merge(old);*/
// 第一步:准备好jpql
// ?1表示第一个参数,?2表示第二个参数
String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2";
EntityTransaction transaction = null;
try {
// transaction = entityManager.getTransaction();
// transaction.begin();
// 第二步:设置jpql的参数
Query query = entityManager.createQuery(jpql);
query.setParameter(1, "赵六666999");
query.setParameter(2, "%jpa%");
// 第三步:执行jpql
int rows = query.executeUpdate();
System.out.println("影响的行数:" + rows);
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
// transaction.rollback();
} finally {
entityManager.close();
}
}
@Override
public void deleteVccinfo(Integer vId) {
entityManager.remove(getVccInfoById(vId));
}
}
//package com.beagle.informix.repository.impl;
//
//import com.beagle.informix.entity.jpa.Vccinfo;
//import com.beagle.informix.repository.VccinfoDao;
//
//import org.springframework.stereotype.Repository;
//
////import javax.persistence.EntityManager;
////import javax.persistence.EntityTransaction;
////import javax.persistence.PersistenceContext;
////import javax.persistence.Query;
////import javax.transaction.Transactional;
//import java.util.List;
//
///**
// * @author lzz
// * date 2023/5/30
// * @version 1.0
// * description:
// */
//@Repository
//public class VccinfoDaoImpl implements VccinfoDao {
//// @PersistenceContext
//// private EntityManager entityManager;
//
// @Override
// public Vccinfo getVccInfoById(Integer vId) {
// return entityManager.find(Vccinfo.class, vId);
// }
//
// @Override
// public List<Vccinfo> getAllVccInfo() {
// String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective";
// return (List<Vccinfo>) entityManager.createQuery(sql).getResultList();
// }
//
// @Override
// public void addVccinfo(Vccinfo vccinfo) {
// entityManager.persist(vccinfo);
//// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" +
//// " VALUES(?,?,?,?,?,?,?,?")
//// .setParameter(1, vccinfo.getVId())
//// .setParameter(2, vccinfo.getVName())
//// .setParameter(3, vccinfo.getEffective())
//// .setParameter(4, vccinfo.getAgentMax())
//// .setParameter(5, vccinfo.getIvrMax())
//// .setParameter(6, vccinfo.getUpdateKey())
//// .setParameter(7, vccinfo.getTClob())
//// .setParameter(8, vccinfo.getTBlob()).executeUpdate();
//
// }
//
// @Override
// @Transactional
// public void updateVccinfo(Vccinfo vccinfo) {
// // 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value.
// /*Vccinfo old = entityManager.find(Vccinfo.class, "jpa");
// old.setVName("informix—name");
// entityManager.merge(old);*/
//
// // 第一步:准备好jpql
//// ?1表示第一个参数,?2表示第二个参数
// String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2";
// EntityTransaction transaction = null;
//
// try {
//// transaction = entityManager.getTransaction();
//// transaction.begin();
//
// // 第二步:设置jpql的参数
// Query query = entityManager.createQuery(jpql);
// query.setParameter(1, "赵六666999");
// query.setParameter(2, "%jpa%");
//
// // 第三步:执行jpql
// int rows = query.executeUpdate();
// System.out.println("影响的行数:" + rows);
//
// transaction.commit();
// } catch (Exception e) {
// e.printStackTrace();
//// transaction.rollback();
// } finally {
// entityManager.close();
// }
// }
//
// @Override
// public void deleteVccinfo(Integer vId) {
// entityManager.remove(getVccInfoById(vId));
// }
//}
package com.beagle.informix.service.impl;
import cn.hutool.json.JSONUtil;
import com.beagle.informix.entity.jpa.Vccinfo;
import com.beagle.informix.repository.VccinfoDao;
import com.beagle.informix.service.InformixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
/**
* Caused by: java.sql.SQLException: Transactions not supported
* ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名
*
* Code-set conversion function failed due to illegal sequence or invalid value.
* 启动失败字符集错误,暂时还未找到解决办法
* @author lzz
* date 2023/5/29
* @version 1.0
* description:
*/
@Slf4j
@Service("informixHibernateService")
public class InformixHibernateServiceImpl implements InformixService {
@Resource
private VccinfoDao vccinfoDao;
@Resource
private ResourceLoader resourceLoader;
@Override
@Transactional
public void doConnectJob() throws Exception{
insert();
// update();
// query();
// delete();
}
private void insert() throws Exception{
Vccinfo vccinfo = new Vccinfo();
// vccinfo.setVId(23);
vccinfo.setEffective(1);
vccinfo.setVName("hibernate");
vccinfo.setIvrMax(1);
vccinfo.setAgentMax(1);
vccinfo.setUpdateKey("jpa key");
// 组装clob
vccinfo.setTClob("@Ddsfsdferewr");
// 组装blob数据
// 处理blob字段
// proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常
org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc");
File inputStream = resource.getFile();
try (FileInputStream fis = new FileInputStream(inputStream)){
vccinfo.setTBlob(fis.readAllBytes());
}
// insert
vccinfoDao.addVccinfo(vccinfo);
}
private void update(int id) {
Vccinfo vccinfo = new Vccinfo();
vccinfo.setVId(id);
vccinfoDao.updateVccinfo(vccinfo);
}
private void query(int id) {
List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo();
log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo()));
log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id)));
}
private void delete(int id) {
vccinfoDao.deleteVccinfo(id);
}
}
//package com.beagle.informix.service.impl;
//
//import cn.hutool.json.JSONUtil;
////import com.beagle.informix.entity.jpa.Vccinfo;
//import com.beagle.informix.repository.VccinfoDao;
//import com.beagle.informix.service.InformixService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.io.ResourceLoader;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
////import javax.transaction.Transactional;
//import java.io.File;
//import java.io.FileInputStream;
//import java.util.List;
//
///**
// * Caused by: java.sql.SQLException: Transactions not supported
// * ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名
// *
// * Code-set conversion function failed due to illegal sequence or invalid value.
// * 启动失败字符集错误,暂时还未找到解决办法
// * @author lzz
// * date 2023/5/29
// * @version 1.0
// * description:
// */
//@Slf4j
//@Service("informixHibernateService")
//public class InformixHibernateServiceImpl implements InformixService {
// @Resource
// private VccinfoDao vccinfoDao;
// @Resource
// private ResourceLoader resourceLoader;
// @Override
//// @Transactional
// public void doConnectJob() throws Exception{
// insert();
//// update();
//// query();
//// delete();
// }
// private void insert() throws Exception{
// Vccinfo vccinfo = new Vccinfo();
//// vccinfo.setVId(23);
// vccinfo.setEffective(1);
// vccinfo.setVName("hibernate");
// vccinfo.setIvrMax(1);
// vccinfo.setAgentMax(1);
// vccinfo.setUpdateKey("jpa key");
// // 组装clob
// vccinfo.setTClob("@Ddsfsdferewr");
// // 组装blob数据
// // 处理blob字段
// // proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常
// org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc");
// File inputStream = resource.getFile();
// try (FileInputStream fis = new FileInputStream(inputStream)){
// vccinfo.setTBlob(fis.readAllBytes());
// }
// // insert
// vccinfoDao.addVccinfo(vccinfo);
// }
//
// private void update(int id) {
// Vccinfo vccinfo = new Vccinfo();
// vccinfo.setVId(id);
// vccinfoDao.updateVccinfo(vccinfo);
// }
// private void query(int id) {
//
//
// List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo();
// log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo()));
// log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id)));
// }
// private void delete(int id) {
// vccinfoDao.deleteVccinfo(id);
// }
//}
package com.beagle.informix.service.impl;
import com.beagle.informix.service.InformixService;
import org.springframework.stereotype.Service;
/**
* @author lzz
* date 2023/5/29
* @version 1.0
* description:
*/
@Service("informixIbatisService")
public class InformixIbatisServiceImpl implements InformixService {
@Override
public void doConnectJob() {
// 手写连接jdbc驱动
}
}
//package com.beagle.informix.service.impl;
//
//import com.beagle.informix.service.InformixService;
//import org.springframework.stereotype.Service;
//
///**
// * @author lzz
// * date 2023/5/29
// * @version 1.0
// * description:
// */
//@Service("informixIbatisService")
//public class InformixIbatisServiceImpl implements InformixService {
// @Override
// public void doConnectJob() {
// // 手写连接jdbc驱动
// }
//
//}
......@@ -44,44 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
*/
@Override
public void doConnectJob() throws Exception{
// // 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);
// 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);
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);
}
}
// for (int i = 0; i < 1; i++) {
// try {
// Driver driver = getDriver();
// Connection conn = getConnection(driver);
// 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的驱动信息
......@@ -98,7 +98,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 SYSDBA.cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) values (?, ? , ?, ?, ? , ?,?,? )";
PreparedStatement stat = conn.prepareStatement(insertSql);
stat.setObject(1, "123456");
stat.setObject(2, "vname");
......@@ -126,9 +126,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
stat.executeUpdate();
}
private void query(Connection conn) throws Exception {
String querySQL = "SELECT id FROM sc_test ";
PreparedStatement stat = conn.prepareStatement(querySQL);
ResultSet resultSet = stat.executeQuery();
String querySQL = "SELECT id FROM sc_test";
Statement stat = conn.createStatement();
ResultSet resultSet = stat.executeQuery(querySQL);
}
......@@ -142,10 +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");
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");
// .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");
......
......@@ -46,13 +46,40 @@ public class InformixJdbcServiceImpl implements InformixService {
public void doConnectJob() throws Exception{
Driver driver = getDriver();
Connection conn = getConnection(driver);
insert(conn);
update(conn);
query(conn);
delete(conn);
// updateTable(conn);
createTable(conn);
// insert(conn);
// update(conn);
// query(conn);
// delete(conn);
// createTable2(conn);
deregisterDriver(driver);
closeConnection(conn);
}
private void createTable(Connection connection) throws Exception{
String sql = "CREATE SEQUENCE if not exists engine_test45_id_seq INCREMENT BY 1 START WITH 1 MINVALUE 1 MAXVALUE 999999999;\nCREATE TABLE engine_test45 (id INTEGER DEFAULT engine_test44_id_seq.Nextval NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\nCOMMENT ON TABLE engine_test45 IS 'sdfadf';";
Statement statement = connection.createStatement();
statement.execute(sql);
}
// 不能执行ddl语句
private void createTable2(Connection connection) throws Exception{
String sql = "CREATE TABLE engine_test45 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\n" +
"CREATE TABLE engine_test46 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\n" +
"CREATE TABLE engine_test47 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));";
Statement statement = connection.createStatement();
statement.executeUpdate(sql);
}
// ok
private void updateTable(Connection connection) throws Exception{
String sql = "update sc_test set name = 'test' where id = 3;\n" +
"update sc_test set name = 'test' where id = 2;\n" +
"update sc_test set name = 'test' where id = 4;";
Statement statement = connection.createStatement();
statement.execute(sql);
}
private void insert(Connection conn) throws Exception{
// 创建testdb数据库、my_test_create_table表
// 现在模拟插入、更新、删除、查询等sql
......@@ -85,27 +112,11 @@ public class InformixJdbcServiceImpl implements InformixService {
stat.executeUpdate();
}
private void query(Connection conn) throws Exception {
String querySQL = "select * from cti_vccinfo_new where vccid = '123456' ";
String querySQL = "select * from cti_vccinfo_new;\n" +
"select * from engine_test14;\n" +
"select * 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' ";
......@@ -116,19 +127,16 @@ public class InformixJdbcServiceImpl implements InformixService {
Properties properties = new Properties();
// 组装连接数据库信息
// jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername>
StringBuilder jdbcBuilder = new StringBuilder("jdbc:informix-sqli://")
.append("localhost:9088")
.append("/")
.append("testdb")
.append(":INFORMIXSERVER=informix");
StringBuilder jdbcBuilder = new StringBuilder("jdbc:dm://")
.append("localhost:5236");
DriverManager.setLoginTimeout(10);
properties.put("user", "informix");
properties.put("password", "in4mix");
properties.put("user", "SYSDBA");
properties.put("password", "SYSDBA");
return DriverManager.getConnection(jdbcBuilder.toString(), properties);
}
private Driver getDriver() throws Exception{
// 定义informix的驱动信息
String driverUrl = "com.informix.jdbc.IfxDriver";
String driverUrl = "dm.jdbc.driver.DmDriver";
// 还需要加入informix的jdbc驱动jar包
Class<?> driverClass = Class.forName(driverUrl);
return (Driver) driverClass.getConstructor().newInstance();
......
package com.beagle.informix.service.impl;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.beagle.informix.entity.mybatis.Vccinfo;
import com.beagle.informix.mapper.VccinfoMapper;
import com.beagle.informix.service.InformixService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
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
* date 2023/5/29
* @version 1.0
* description:
*/
@Service("informixMybatisService")
@Slf4j
public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccinfo> implements InformixService {
@Resource
private ResourceLoader resourceLoader;
@Resource
private VccinfoMapper vccinfoMapper;
@Override
@Transactional
public void doConnectJob() throws Exception{
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();
vccinfo.setVId(3);
vccinfo.setEffective(1);
vccinfo.setVName("mybatis");
vccinfo.setIvrMax(1);
vccinfo.setAgentMax(1);
vccinfo.setUpdateKey("mybatis key");
// 组装clob
vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr");
// 组装blob数据
// 处理blob字段
org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
File inputStream = resource.getFile();
try (FileInputStream fis = new FileInputStream(inputStream)){
vccinfo.setTBlob(fis.readAllBytes());
}
// insert
// 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
// 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
baseMapper.insertData(vccinfo);
}
private void updateMethod() throws Exception {
LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Vccinfo::getVId, "ibatis");
Vccinfo vccinfo = new Vccinfo();
vccinfo.setVName("mybatis-update");
baseMapper.update(vccinfo, queryWrapper);
}
private void queryMethod() {
List<Vccinfo> vccinfoList = vccinfoMapper.queryList(1);
log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList));
}
private void delete() {
LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Vccinfo::getVId, "ibatis");
baseMapper.delete(queryWrapper);
}
}
//package com.beagle.informix.service.impl;
//
//import cn.hutool.json.JSONUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.beagle.informix.entity.mybatis.Vccinfo;
//import com.beagle.informix.mapper.VccinfoMapper;
//import com.beagle.informix.service.InformixService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.annotations.Result;
//import org.apache.ibatis.annotations.Results;
//import org.springframework.core.io.ResourceLoader;
//import org.springframework.stereotype.Service;
//
//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
// * date 2023/5/29
// * @version 1.0
// * description:
// */
//@Service("informixMybatisService")
//@Slf4j
//public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccinfo> implements InformixService {
// @Resource
// private ResourceLoader resourceLoader;
// @Resource
// private VccinfoMapper vccinfoMapper;
// @Override
// @Transactional
// public void doConnectJob() throws Exception{
// 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();
// vccinfo.setVId(3);
// vccinfo.setEffective(1);
// vccinfo.setVName("mybatis");
// vccinfo.setIvrMax(1);
// vccinfo.setAgentMax(1);
// vccinfo.setUpdateKey("mybatis key");
// // 组装clob
// vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr");
// // 组装blob数据
// // 处理blob字段
// org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
// File inputStream = resource.getFile();
// try (FileInputStream fis = new FileInputStream(inputStream)){
// vccinfo.setTBlob(fis.readAllBytes());
// }
// // insert
// // 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
// // 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
// baseMapper.insertData(vccinfo);
// }
//
// private void updateMethod() throws Exception {
// LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(Vccinfo::getVId, "ibatis");
// Vccinfo vccinfo = new Vccinfo();
// vccinfo.setVName("mybatis-update");
// baseMapper.update(vccinfo, queryWrapper);
// }
//
// private void queryMethod() {
// List<Vccinfo> vccinfoList = vccinfoMapper.queryList(1);
// log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList));
// }
// private void delete() {
// LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(Vccinfo::getVId, "ibatis");
// baseMapper.delete(queryWrapper);
// }
//
//}
spring:
datasource:
# url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&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
password: Apurelove9014
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:
properties:
hibernate:
dialect: org.hibernate.dialect.InformixDialect
format_sql: true
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
\ No newline at end of file
#spring:
# datasource:
## url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&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
# password: Apurelove9014
# 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:
# properties:
# hibernate:
# dialect: org.hibernate.dialect.InformixDialect
# format_sql: true
#mybatis-plus:
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# map-underscore-to-camel-case: true
\ No newline at end of file
......@@ -13,16 +13,16 @@ import javax.annotation.Resource;
@SpringBootTest(classes = BaseApplication.class)
class InformixServiceTest {
// @Resource(name = "informixJdbcService")
// private InformixService informixJdbcService;
@Resource(name = "informixJdbcService")
private InformixService informixJdbcService;
@Resource(name = "informixJdbcProxyService")
private InformixService informixJdbcProxyService;
@Resource(name = "informixHibernateService")
// @Resource(name = "informixHibernateService")
private InformixService informixHibernateService;
// @Resource(name = "informixIbatisService")
// private InformixService informixIbatisService;
@Resource(name = "informixMybatisService")
// @Resource(name = "informixMybatisService")
private InformixService informixMybatisService;
// @Test
// void testJdbcInfo() {
......@@ -57,4 +57,14 @@ class InformixServiceTest {
e.printStackTrace();
}
}
@Test
void testJdbcInfo() {
try {
informixJdbcService.doConnectJob();
} catch (Exception e) {
e.printStackTrace();
}
}
}
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