当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseMetaData.getSearchStringEscape方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:26,代码来源:LegacyMysqlEventStoreSetup.java

示例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);
    }
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:32,代码来源:BasicMysqlEventStoreSetup.java


注:本文中的java.sql.DatabaseMetaData.getSearchStringEscape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。