Add SqlUtils.escape and SqlUtils.unescape methods, SqlUtils.ESCAPE_CHARS field
This commit is contained in:
parent
54203b58e5
commit
29872d7777
1 changed files with 18 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ import java.io.IOException;
|
|||
import java.sql.*;
|
||||
|
||||
public class SqlUtils {
|
||||
public static final char[] ESCAPE_CHARS = {'%', '_', '[', ']', '^'};
|
||||
|
||||
public static Connection createMySqlConnection(String address, String dbname, String username, String password, boolean ssl) throws SqlException {
|
||||
try {
|
||||
try {
|
||||
|
|
@ -83,4 +85,20 @@ public class SqlUtils {
|
|||
}
|
||||
}, query, args);
|
||||
}
|
||||
|
||||
public static String escape(String str) {
|
||||
return StringUtils.escape(str, ESCAPE_CHARS);
|
||||
}
|
||||
|
||||
public static String unescape(String str) {
|
||||
return StringUtils.unescape(str, ESCAPE_CHARS);
|
||||
}
|
||||
|
||||
public static String escape(String str, String escape) {
|
||||
return StringUtils.escape(str, escape, ESCAPE_CHARS);
|
||||
}
|
||||
|
||||
public static String unescape(String str, String escape) {
|
||||
return StringUtils.unescape(str, escape, ESCAPE_CHARS);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue