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

1232

parent cb3b0f8e
...@@ -69,14 +69,14 @@ public class VccinfoDaoImpl implements VccinfoDao { ...@@ -69,14 +69,14 @@ public class VccinfoDaoImpl implements VccinfoDao {
// 第二步:设置jpql的参数 // 第二步:设置jpql的参数
Query query = entityManager.createQuery(jpql); Query query = entityManager.createQuery(jpql);
query.setParameter(1, "赵六666999"); query.setParameter(1, "222");
query.setParameter(2, "%jpa%"); query.setParameter(2, 3);
// 第三步:执行jpql // 第三步:执行jpql
int rows = query.executeUpdate(); int rows = query.executeUpdate();
System.out.println("影响的行数:" + rows); System.out.println("影响的行数:" + rows);
transaction.commit(); // transaction.commit();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
// transaction.rollback(); // transaction.rollback();
......
...@@ -35,13 +35,14 @@ public class InformixHibernateServiceImpl implements InformixService { ...@@ -35,13 +35,14 @@ public class InformixHibernateServiceImpl implements InformixService {
@Override @Override
@Transactional @Transactional
public void doConnectJob() throws Exception{ public void doConnectJob() throws Exception{
insert(); insert();
// update(); update(10);
// query(); query(10);
// delete(); delete(10);
} }
private void insert() throws Exception{ private void insert() throws Exception{
Vccinfo vccinfo = new Vccinfo(); Vccinfo vccinfo = new Vccinfo();
// 主键生成策略如果声明了,这里不能再手动指定id
// vccinfo.setVId(23); // vccinfo.setVId(23);
vccinfo.setEffective(1); vccinfo.setEffective(1);
vccinfo.setVName("hibernate"); vccinfo.setVName("hibernate");
...@@ -71,7 +72,7 @@ public class InformixHibernateServiceImpl implements InformixService { ...@@ -71,7 +72,7 @@ public class InformixHibernateServiceImpl implements InformixService {
List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo(); List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo();
log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo())); // log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo()));
log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id))); log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id)));
} }
private void delete(int id) { private void delete(int id) {
......
...@@ -45,9 +45,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -45,9 +45,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
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);
} }
...@@ -66,23 +66,23 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -66,23 +66,23 @@ 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 ( vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) 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(1, "vname");
stat.setObject(3, 1); stat.setObject(2, 1);
stat.setObject(4, 2); stat.setObject(3, 2);
stat.setObject(5, 3); stat.setObject(4, 3);
stat.setObject(6, "updatekey"); stat.setObject(5, "updatekey");
String clobContent = "This is a very very long string"; String clobContent = "This is a very very long string df sdferwerqwsdasdsda";
// 处理clob字段 // 处理clob字段
StringReader reader = new StringReader(clobContent); StringReader reader = new StringReader(clobContent);
stat.setClob(7, reader, clobContent.length()); stat.setClob(6, 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(7, fis);
stat.executeUpdate(); stat.executeUpdate();
} }
private void update(Connection conn) throws Exception{ private void update(Connection conn) throws Exception{
...@@ -125,9 +125,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -125,9 +125,9 @@ 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:23307")
.append("/") .append("/")
.append("testdb").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); .append("postgres").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); // useServerPrepStmts=true
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
properties.put("user", "root"); properties.put("user", "root");
properties.put("password", "Apurelove9014"); properties.put("password", "Apurelove9014");
......
...@@ -42,7 +42,7 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin ...@@ -42,7 +42,7 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
} }
private void insertMethod() throws Exception{ private void insertMethod() throws Exception{
Vccinfo vccinfo = new Vccinfo(); Vccinfo vccinfo = new Vccinfo();
vccinfo.setVId(3); vccinfo.setVId(22);
vccinfo.setEffective(1); vccinfo.setEffective(1);
vccinfo.setVName("mybatis"); vccinfo.setVName("mybatis");
vccinfo.setIvrMax(1); vccinfo.setIvrMax(1);
...@@ -60,7 +60,8 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin ...@@ -60,7 +60,8 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
// insert // insert
// 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换 // 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
// 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换 // 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
baseMapper.insertData(vccinfo); // baseMapper.insertData(vccinfo);
baseMapper.insert(vccinfo);
} }
private void updateMethod() throws Exception { private void updateMethod() throws Exception {
......
...@@ -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:mysql://localhost:23307/postgres?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
......
...@@ -7,8 +7,8 @@ create table cti_vccinfo_new ...@@ -7,8 +7,8 @@ create table cti_vccinfo_new
agentmax INTEGER default 0 not null, agentmax INTEGER default 0 not null,
ivrmax INTEGER default 0 not null, ivrmax INTEGER default 0 not null,
updatekey VARCHAR(30), updatekey VARCHAR(30),
tclob clob null, tclob text null,
tblob blob null, tblob bytea null,
primary key (vccid) constraint PK_CTI_VI_new primary key (vccid) constraint PK_CTI_VI_new
); );
......
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