错误java.sql.SQLException:ORA-00911:无效字符

时间:2014-03-16 10:34:30

标签: sql oracle jdbc

我的代码有错误:

String sql = "CREATE USER ken IDENTIFIED BY 11;";

try {
    Class.forName("oracle.jdbc.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "kenilyas");
    System.out.println("1111111111111");
    System.out.println("222222");
    pst = con.prepareStatement(sql);
    System.out.println("333333");
    try {
        System.out.println("333333");
        pst.execute();
        System.out.println("creating");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
} catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
}

2 个答案:

答案 0 :(得分:84)

问题是;

sql = "CREATE USER ken IDENTIFIED BY 11;";

从字符串上方删除;

答案 1 :(得分:3)

我在myBatis也收到了同样的问题。

错误:

### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

    ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

<强>解决方案:

select * from tableName where id= '123';

从Where子句(Mybatis Mapper xml)中删除";"后,它正在工作。