Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
351f8f05
Commit
351f8f05
authored
May 18, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理显示
parent
1ea210d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
DbPrintSql.java
...-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
+20
-8
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
View file @
351f8f05
...
@@ -26,20 +26,32 @@ public class DbPrintSql {
...
@@ -26,20 +26,32 @@ public class DbPrintSql {
* @return 不带参数的SQL语句
* @return 不带参数的SQL语句
*/
*/
public
String
getStringSql
(
String
sql
,
Object
...
paras
)
{
public
String
getStringSql
(
String
sql
,
Object
...
paras
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
[]
split
=
sql
.
split
(
"\\?"
);
int
pos
=
0
;
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
for
(
Object
item
:
paras
)
{
for
(
Object
item
:
paras
)
{
String
str
=
StringHelper
.
toString
(
item
);
String
str
=
StringHelper
.
toString
(
item
);
if
(
str
==
null
||
item
instanceof
Number
||
item
.
getClass
().
isEnum
()
||
item
instanceof
Boolean
)
{
String
strTo
=
str
;
if
(
str
==
null
)
{
if
(
str
==
null
)
{
sql
=
sql
.
replaceFirst
(
"\\?"
,
"null"
);
strTo
=
"null"
;
}
else
if
(
item
instanceof
Number
||
item
.
getClass
().
isEnum
()
||
item
instanceof
Boolean
)
{
// 不进行处理
}
else
{
}
else
{
sql
=
sql
.
replaceFirst
(
"\\?"
,
str
)
;
strTo
=
"'"
+
str
.
replace
(
"'"
,
"''"
)
+
"'"
;
}
}
}
else
{
sb
.
append
(
split
[
pos
]);
sql
=
sql
.
replaceFirst
(
"\\?"
,
"'"
+
str
.
replace
(
"'"
,
"''"
)
+
"'"
);
pos
++;
sb
.
append
(
strTo
);
}
}
while
(
pos
<
split
.
length
)
{
sb
.
append
(
split
[
pos
]);
pos
++;
}
}
return
s
ql
;
return
s
b
.
toString
()
;
}
}
/**
/**
...
...
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