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

1232

parent cb3b0f8e
......@@ -69,14 +69,14 @@ public class VccinfoDaoImpl implements VccinfoDao {
// 第二步:设置jpql的参数
Query query = entityManager.createQuery(jpql);
query.setParameter(1, "赵六666999");
query.setParameter(2, "%jpa%");
query.setParameter(1, "222");
query.setParameter(2, 3);
// 第三步:执行jpql
int rows = query.executeUpdate();
System.out.println("影响的行数:" + rows);
transaction.commit();
// transaction.commit();
} catch (Exception e) {
e.printStackTrace();
// transaction.rollback();
......
......@@ -36,12 +36,13 @@ public class InformixHibernateServiceImpl implements InformixService {
@Transactional
public void doConnectJob() throws Exception{
insert();
// update();
// query();
// delete();
update(10);
query(10);
delete(10);
}
private void insert() throws Exception{
Vccinfo vccinfo = new Vccinfo();
// 主键生成策略如果声明了,这里不能再手动指定id
// vccinfo.setVId(23);
vccinfo.setEffective(1);
vccinfo.setVName("hibernate");
......@@ -71,7 +72,7 @@ public class InformixHibernateServiceImpl implements InformixService {
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)));
}
private void delete(int id) {
......
......@@ -45,9 +45,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
Driver driver = getDriver();
Connection conn = getConnection(driver);
insert(conn);
// update(conn);
// query(conn);
// delete(conn);
update(conn);
query(conn);
delete(conn);
closeConnection(conn);
deregisterDriver(driver);
}
......@@ -66,23 +66,23 @@ 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 ( vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) values ( ? , ?, ?, ? , ?,?,? )";
PreparedStatement stat = conn.prepareStatement(insertSql);
stat.setObject(1, "123456");
stat.setObject(2, "vname");
stat.setObject(3, 1);
stat.setObject(4, 2);
stat.setObject(5, 3);
stat.setObject(6, "updatekey");
String clobContent = "This is a very very long string";
// stat.setObject(1, "123456");
stat.setObject(1, "vname");
stat.setObject(2, 1);
stat.setObject(3, 2);
stat.setObject(4, 3);
stat.setObject(5, "updatekey");
String clobContent = "This is a very very long string df sdferwerqwsdasdsda";
// 处理clob字段
StringReader reader = new StringReader(clobContent);
stat.setClob(7, reader, clobContent.length());
stat.setClob(6, reader, clobContent.length());
// 处理blob字段
Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
File inputStream = resource.getFile();
FileInputStream fis = new FileInputStream(inputStream);
stat.setBlob(8, fis);
stat.setBlob(7, fis);
stat.executeUpdate();
}
private void update(Connection conn) throws Exception{
......@@ -125,9 +125,9 @@ 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:23307")
.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);
properties.put("user", "root");
properties.put("password", "Apurelove9014");
......
......@@ -42,7 +42,7 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
}
private void insertMethod() throws Exception{
Vccinfo vccinfo = new Vccinfo();
vccinfo.setVId(3);
vccinfo.setVId(22);
vccinfo.setEffective(1);
vccinfo.setVName("mybatis");
vccinfo.setIvrMax(1);
......@@ -60,7 +60,8 @@ public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccin
// insert
// 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
// 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
baseMapper.insertData(vccinfo);
// baseMapper.insertData(vccinfo);
baseMapper.insert(vccinfo);
}
private void updateMethod() throws Exception {
......
......@@ -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: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
username: root
# username: informix
......
......@@ -7,8 +7,8 @@ create table cti_vccinfo_new
agentmax INTEGER default 0 not null,
ivrmax INTEGER default 0 not null,
updatekey VARCHAR(30),
tclob clob null,
tblob blob null,
tclob text null,
tblob bytea null,
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