Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
data-computing-proxy-test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李振振
data-computing-proxy-test
Commits
fa0863e7
You need to sign in or sign up before continuing.
Commit
fa0863e7
authored
Sep 03, 2023
by
李振振
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polardbx的curd测试
parent
cb3b0f8e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
34 deletions
+31
-34
pom.xml
pom.xml
+6
-0
src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java
...e/informix/service/impl/InformixJdbcProxyServiceImpl.java
+23
-32
src/main/resources/application.yaml
src/main/resources/application.yaml
+2
-2
No files found.
pom.xml
View file @
fa0863e7
...
...
@@ -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>
...
...
src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java
View file @
fa0863e7
...
...
@@ -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:
my
sql://localhost:3307"
)
StringBuilder
jdbcBuilder
=
new
StringBuilder
(
"jdbc:
postgre
sql://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"
);
...
...
src/main/resources/application.yaml
View file @
fa0863e7
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment