本文整理汇总了Java中java.sql.DatabaseMetaData.getSearchStringEscape方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getSearchStringEscape方法的具体用法?Java DatabaseMetaData.getSearchStringEscape怎么用?Java DatabaseMetaData.getSearchStringEscape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.DatabaseMetaData
的用法示例。
在下文中一共展示了DatabaseMetaData.getSearchStringEscape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void create(boolean ifNotExists) {
try (Connection connection = connectionProvider.getConnection()) {
if (ifNotExists) {
DatabaseMetaData meta = connection.getMetaData();
String searchStringEscape = meta.getSearchStringEscape();
String escapedTableName = tableName.replace("_", searchStringEscape + "_").replace("%", searchStringEscape + "%");
try(ResultSet res = meta.getTables(null, null, escapedTableName, new String[]{"TABLE", "VIEW"})) {
if (res.first()) {
return;
}
}
}
try (Statement statement = connection.createStatement()) {
statement.execute("create table " + (ifNotExists ? "if not exists" : "") + " " + tableName + "(" +
"version bigint primary key, " +
"effective_timestamp datetime not null, " +
"eventType varchar(255) not null," +
"body blob not null" +
")");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例2: create
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void create(boolean ifNotExists) {
try (Connection connection = connectionProvider.getConnection()) {
if (ifNotExists) {
DatabaseMetaData meta = connection.getMetaData();
String searchStringEscape = meta.getSearchStringEscape();
String escapedTableName = tableName.replace("_", searchStringEscape + "_").replace("%", searchStringEscape + "%");
try(ResultSet res = meta.getTables(null, null, escapedTableName, new String[]{"TABLE", "VIEW"})) {
if (res.first()) {
return;
}
}
}
try (Statement statement = connection.createStatement()) {
statement.execute("create table " + (ifNotExists ? "if not exists" : "") + " " + tableName + "(" +
"position bigint primary key, " +
"timestamp datetime not null, " +
"stream_category varchar(255) not null, " +
"stream_id varchar(255) not null, " +
"event_number bigint not null, " +
"event_type varchar(255) not null," +
"data blob not null, " +
"metadata blob not null," +
"unique(stream_category, stream_id, event_number)," +
"key(stream_category, position)" +
")");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}