Java Code Examples for com.mysql.jdbc.StringUtils#indexOfIgnoreCase()

The following examples show how to use com.mysql.jdbc.StringUtils#indexOfIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbUtils.java    From das with Apache License 2.0 5 votes vote down vote up
public static List<AbstractParameterHost> getSelectFieldHosts(Long db_id, String sql,
                                                              DalResultSetExtractor<List<AbstractParameterHost>> extractor) throws Exception {
    List<AbstractParameterHost> list = null;
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    List<Parameter> parameters = new ArrayList<>();
    String testSql = sql;
    int whereIndex = StringUtils.indexOfIgnoreCase(testSql, "where");
    if (whereIndex > 0) {
        testSql = sql.substring(0, whereIndex);
    }
    if (isMySqlServer(db_id)) {
        testSql = testSql + " limit 1";
    } else {
        testSql = testSql.replace("select", "select top(1)");
    }
    try {
        connection = DataSourceUtil.getConnection(db_id);
        preparedStatement = statementCreator.createPreparedStatement(connection, testSql, parameters, Hints.hints());
        resultSet = preparedStatement.executeQuery();
        list = extractor.extract(resultSet);
    } catch (Throwable e) {
        throw e;
    } finally {
        DbUtil.close(resultSet);
        DbUtil.close(preparedStatement);
        DbUtil.close(connection);
    }
    return list;
}
 
Example 2
Source File: DbUtils.java    From dal with Apache License 2.0 5 votes vote down vote up
public static List<AbstractParameterHost> getSelectFieldHosts(String allInOneName, String sql,
        DalResultSetExtractor<List<AbstractParameterHost>> extractor) throws Exception {
    List<AbstractParameterHost> list = null;
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    StatementParameters parameters = new StatementParameters();
    DalHints hints = DalHints.createIfAbsent(null);
    String testSql = sql;
    int whereIndex = StringUtils.indexOfIgnoreCase(testSql, "where");
    if (whereIndex > 0)
        testSql = sql.substring(0, whereIndex);
    if (isMySqlServer(allInOneName)) {
        testSql = testSql + " limit 1";
    } else {
        testSql = testSql.replace("select", "select top(1)");
    }
    try {
        connection = DataSourceUtil.getConnection(allInOneName);
        preparedStatement = statementCreator.createPreparedStatement(connection, testSql, parameters, hints);
        resultSet = preparedStatement.executeQuery();
        list = extractor.extract(resultSet);
    } catch (Throwable e) {
        throw e;
    } finally {
        ResourceUtils.close(resultSet);
        ResourceUtils.close(preparedStatement);
        ResourceUtils.close(connection);
    }
    return list;
}
 
Example 3
Source File: ServerController.java    From r-course with MIT License 2 votes vote down vote up
/**
 * Is this ServerController running on a Windows operating system?
 * 
 * @return boolean if this ServerController is running on Windows
 */
private boolean runningOnWindows() {
    return StringUtils.indexOfIgnoreCase(getSystemProperties().getProperty("os.name"), "WINDOWS") != -1;
}
 
Example 4
Source File: ServerController.java    From Komondor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Is this ServerController running on a Windows operating system?
 * 
 * @return boolean if this ServerController is running on Windows
 */
private boolean runningOnWindows() {
    return StringUtils.indexOfIgnoreCase(getSystemProperties().getProperty("os.name"), "WINDOWS") != -1;
}