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


Java SQLSyntaxErrorException类代码示例

本文整理汇总了Java中java.sql.SQLSyntaxErrorException的典型用法代码示例。如果您正苦于以下问题:Java SQLSyntaxErrorException类的具体用法?Java SQLSyntaxErrorException怎么用?Java SQLSyntaxErrorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SQLSyntaxErrorException类属于java.sql包,在下文中一共展示了SQLSyntaxErrorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test12

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLSyntaxErrorException ex = new SQLSyntaxErrorException("Exception 1", t1);
    SQLSyntaxErrorException ex1 = new SQLSyntaxErrorException("Exception 2");
    SQLSyntaxErrorException ex2 = new SQLSyntaxErrorException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:SQLSyntaxErrorExceptionTests.java

示例2: loadTableRules

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * tableRule tag:
 * <tableRule name="sharding-by-month">
 * <rule>
 * <columns>create_date</columns>
 * <algorithm>partbymonth</algorithm>
 * </rule>
 * </tableRule>
 *
 * @param root
 * @throws SQLSyntaxErrorException
 */
private void loadTableRules(Element root) throws SQLSyntaxErrorException {
    NodeList list = root.getElementsByTagName("tableRule");
    for (int i = 0, n = list.getLength(); i < n; ++i) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            if (StringUtil.isEmpty(name)) {
                throw new ConfigException("name is null or empty");
            }
            if (tableRules.containsKey(name)) {
                throw new ConfigException("table rule " + name + " duplicated!");
            }
            NodeList ruleNodes = e.getElementsByTagName("rule");
            int length = ruleNodes.getLength();
            if (length > 1) {
                throw new ConfigException("only one rule can defined :" + name);
            }
            //rule has only one element now. Maybe it will not contains one rule in feature
            //RuleConfig:rule->function
            RuleConfig rule = loadRule((Element) ruleNodes.item(0));
            tableRules.put(name, new TableRuleConfig(name, rule));
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:38,代码来源:XMLRuleLoader.java

示例3: routeSystemInfo

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
public RouteResultset routeSystemInfo(SchemaConfig schema, int sqlType,
		String stmt, RouteResultset rrs) throws SQLSyntaxErrorException {
	switch(sqlType){
	case ServerParse.SHOW:// if origSQL is like show tables
		return analyseShowSQL(schema, rrs, stmt);
	case ServerParse.SELECT://if origSQL is like select @@
		if(stmt.contains("@@")){
			return analyseDoubleAtSgin(schema, rrs, stmt);
		}
		break;
	case ServerParse.DESCRIBE:// if origSQL is meta SQL, such as describe table
		int ind = stmt.indexOf(' ');
		stmt = stmt.trim();
		return analyseDescrSQL(schema, rrs, stmt, ind + 1);
	}
	return null;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:18,代码来源:DruidMycatRouteStrategy.java

示例4: loadRule

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
private RuleConfig loadRule(Element element) throws SQLSyntaxErrorException {
    Element columnsEle = ConfigUtil.loadElement(element, "columns");
    String column = columnsEle.getTextContent();
    if (StringUtil.isEmpty(column)) {
        throw new ConfigException("no rule column is found");
    }
    String[] columns = SplitUtil.split(column, ',', true);
    if (columns.length > 1) {
        throw new ConfigException("table rule coulmns has multi values:" +
                columnsEle.getTextContent());
    }
    Element algorithmEle = ConfigUtil.loadElement(element, "algorithm");
    String algorithmName = algorithmEle.getTextContent();

    if (StringUtil.isEmpty(algorithmName)) {
        throw new ConfigException("algorithm is null or empty");
    }
    AbstractPartitionAlgorithm algorithm = functions.get(algorithmName);
    if (algorithm == null) {
        throw new ConfigException("can't find function of name :" + algorithmName);
    }
    return new RuleConfig(column.toUpperCase(), algorithmName, algorithm);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:24,代码来源:XMLRuleLoader.java

示例5: parserSQL

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
@Override
public SQLStatement parserSQL(String originSql) throws SQLSyntaxErrorException {
    SQLStatementParser parser = new MySqlStatementParser(originSql);

    /**
     * thrown SQL SyntaxError if parser error
     */
    try {
        List<SQLStatement> list = parser.parseStatementList();
        if (list.size() > 1) {
            throw new SQLSyntaxErrorException("MultiQueries is not supported,use single query instead ");
        }
        return list.get(0);
    } catch (Exception t) {
        LOGGER.info("routeNormalSqlWithAST", t);
        if (t.getMessage() != null) {
            throw new SQLSyntaxErrorException(t.getMessage());
        } else {
            throw new SQLSyntaxErrorException(t);
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:23,代码来源:DefaultRouteStrategy.java

示例6: hasIpv6_falseWhenKnownSQLState

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
@Test
public void hasIpv6_falseWhenKnownSQLState() throws SQLException {
  SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
      "Unknown column 'zipkin_annotations.endpoint_ipv6' in 'field list'",
      "42S22", 1054);
  DataSource dataSource = mock(DataSource.class);

  // cheats to lower mock count: this exception is really thrown during execution of the query
  when(dataSource.getConnection()).thenThrow(
      new DataAccessException(sqlException.getMessage(), sqlException));

  Boolean result = MySQLStorage.builder()
      .executor(Runnable::run)
      .datasource(dataSource)
      .build().hasIpv6.get();

  assertThat(result).isFalse();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:19,代码来源:MySQLStorageTest.java

示例7: hasIpv6_falseWhenUnknownSQLState

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * This returns false instead of failing when the SQLState code doesn't imply the column is
 * missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
 * The root error goes into the log in this case.
 */
@Test
public void hasIpv6_falseWhenUnknownSQLState() throws SQLException {
  SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
      "java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_annotations' doesn't exist",
      "42S02", 1146);
  DataSource dataSource = mock(DataSource.class);

  // cheats to lower mock count: this exception is really thrown during execution of the query
  when(dataSource.getConnection()).thenThrow(
      new DataAccessException(sqlException.getMessage(), sqlException));

  Boolean result = MySQLStorage.builder()
      .executor(Runnable::run)
      .datasource(dataSource)
      .build().hasIpv6.get();

  assertThat(result).isFalse();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:24,代码来源:MySQLStorageTest.java

示例8: hasDependencies_missing

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
@Test
public void hasDependencies_missing() throws SQLException {
  SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
      "SQL [select count(*) from `zipkin_dependencies`]; Table 'zipkin.zipkin_dependencies' doesn't exist\n"
          + "  Query is : select count(*) from `zipkin_dependencies`",
      "42S02", 1146);
  DataSource dataSource = mock(DataSource.class);

  // cheats to lower mock count: this exception is really thrown during execution of the query
  when(dataSource.getConnection()).thenThrow(
      new DataAccessException(sqlException.getMessage(), sqlException));

  Boolean result = MySQLStorage.builder()
      .executor(Runnable::run)
      .datasource(dataSource)
      .build().hasPreAggregatedDependencies.get();

  assertThat(result).isFalse();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:20,代码来源:MySQLStorageTest.java

示例9: execute

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
public void execute(String sql, int type) {
    if (!TimoServer.getInstance().isOnline()) {
        writeErrMessage(ErrorCode.ER_ACCESS_DENIED_ERROR, "Timo-server is offline");
        return;
    }
    Database database = checkDB();
    if (database == null) {
        return;
    }
    Outlets out = null;
    try {
        out = Router.route(database, sql, this.getCharset(), type);
    } catch (SQLSyntaxErrorException e) {
        String msg = e.getMessage();
        writeErrMessage(ErrorCode.ER_PARSE_ERROR,
                msg == null ? e.getClass().getSimpleName() : msg);
        return;
    }
    chooseSession(out, type);
    session.execute(out, type);
}
 
开发者ID:flownclouds,项目名称:Timo,代码行数:22,代码来源:ServerConnection.java

示例10: matchIdentifier

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * @return index of expected token, start from 0
 * @throws SQLSyntaxErrorException if no token is matched
 */
protected int matchIdentifier(String... expectTextUppercase) throws SQLSyntaxErrorException {
    if (expectTextUppercase == null || expectTextUppercase.length <= 0)
        throw new IllegalArgumentException("at least one expect token");
    if (lexer.token() != MySQLToken.IDENTIFIER) {
        throw err("expect an id");
    }
    String id = lexer.stringValueUppercase();
    for (int i = 0; i < expectTextUppercase.length; ++i) {
        if (id == null ? expectTextUppercase[i] == null : id.equals(expectTextUppercase[i])) {
            lexer.nextToken();
            return i;
        }
    }
    throw err("expect " + expectTextUppercase);
}
 
开发者ID:liuhuanting,项目名称:Timo-parser,代码行数:20,代码来源:MySQLParser.java

示例11: scanHexaDecimal

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * @param quoteMode if false: first <code>0x</code> has been skipped; if true: first
 *        <code>x'</code> has been skipped
 */
protected void scanHexaDecimal(boolean quoteMode) throws SQLSyntaxErrorException {
    offsetCache = curIndex;
    for (; CharTypes.isHex(ch); scanChar());

    sizeCache = curIndex - offsetCache;
    // if (sizeCache <= 0) {
    // throw err("expect at least one hexdigit");
    // }
    if (quoteMode) {
        if (ch != '\'') {
            throw err("invalid char for hex: " + ch);
        }
        scanChar();
    } else if (CharTypes.isIdentifierChar(ch)) {
        scanIdentifierFromNumber(offsetCache - 2, sizeCache + 2);
        return;
    }

    token = MySQLToken.LITERAL_HEX;
}
 
开发者ID:liuhuanting,项目名称:Timo-parser,代码行数:25,代码来源:MySQLLexer.java

示例12: scanSystemVariable

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * first <code>@@</code> is included
 */
protected void scanSystemVariable() throws SQLSyntaxErrorException {
    if (ch != '@' || sql[curIndex + 1] != '@') throw err("first char must be @@");
    offsetCache = curIndex + 2;
    sizeCache = 0;
    scanChar(2);
    if (ch == '`') {
        for (++sizeCache;; ++sizeCache) {
            if (scanChar() == '`') {
                ++sizeCache;
                if (scanChar() != '`') {
                    break;
                }
            }
        }
    } else {
        for (; CharTypes.isIdentifierChar(ch); ++sizeCache) {
            scanChar();
        }
    }
    updateStringValue(sql, offsetCache, sizeCache);
    token = MySQLToken.SYS_VAR;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:26,代码来源:MySQLLexer.java

示例13: hintList

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * @return null if there is no hint
 */
private List<IndexHint> hintList() throws SQLSyntaxErrorException {
    IndexHint hint = hint();
    if (hint == null)
        return null;
    List<IndexHint> list;
    IndexHint hint2 = hint();
    if (hint2 == null) {
        list = new ArrayList<IndexHint>(1);
        list.add(hint);
        return list;
    }
    list = new LinkedList<IndexHint>();
    list.add(hint);
    list.add(hint2);
    for (; (hint2 = hint()) != null; list.add(hint2))
        ;
    return list;
}
 
开发者ID:flownclouds,项目名称:Timo,代码行数:22,代码来源:MySQLDMLParser.java

示例14: buildUnionSelect

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
/**
 * @return argument itself if there is no union
 */
protected DMLQueryStatement buildUnionSelect(DMLSelectStatement select)
        throws SQLSyntaxErrorException {
    if (lexer.token() != KW_UNION) {
        return select;
    }
    DMLSelectUnionStatement union = new DMLSelectUnionStatement(select);
    for (; lexer.token() == KW_UNION;) {
        lexer.nextToken();
        boolean isAll = false;
        switch (lexer.token()) {
            case KW_ALL:
                isAll = true;
            case KW_DISTINCT:
                lexer.nextToken();
                break;
            default:
                break;
        }
        select = selectPrimary();
        union.addSelect(select, isAll);
    }
    union.setOrderBy(orderBy()).setLimit(limit());
    return union;
}
 
开发者ID:flownclouds,项目名称:Timo,代码行数:28,代码来源:MySQLDMLParser.java

示例15: testInsertSQLWithAutoIncrement

import java.sql.SQLSyntaxErrorException; //导入依赖的package包/类
@Test
public void testInsertSQLWithAutoIncrement() throws SQLSyntaxErrorException {
    Identifier columnAutoIncrementColumn = new Identifier(null, "id");
    String sql = null;
    SQLStatement ast = null;
    DMLInsertStatement parsInf = null;
    sql = "insert into table1(name1,name2,id)  values ('1','2',10) ";
    ast = SQLParserDelegate.parse(sql);
    parsInf = (DMLInsertStatement) (ast);
    enrichAutoIncrementColumn(columnAutoIncrementColumn, parsInf);

    StringBuilder sb = new StringBuilder();
    OutputVisitor visitor = new OutputVisitor(sb, false);
    parsInf.accept(visitor);
    System.out.println(sb.toString());
    Assert.assertEquals("table1".toUpperCase(), parsInf.getTable().getIdTextUpUnescape());
    Assert.assertNotNull(parsInf.getColumnNameList());
}
 
开发者ID:flownclouds,项目名称:Timo,代码行数:19,代码来源:TestInsertSQLAnalyser.java


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