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

39

我的代码出现了错误:

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);
}

11
有任何诊断信息(行号)吗?我猜测分号可能是问题的原因,因为Oracle驱动程序通常只支持查询语句中的一个语句。 - Caramiriel
5
问题的根源在于 - Guntram Blohm
@Caramiriel 是的,你说得对。简单的解决方案,但在我转向SO之前,我调试了30分钟。 - Tim Sanders
2个回答

103

问题是;

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

从上面的字符串中删除;


5
谢谢!很傻的是,系统没有灵活性或者没有提供清晰明确的操作说明。 - George Pligoropoulos
@Georgios 系统应该接受那个逗号! - Jarkid
1
@Jarkid,这是分号。 - Alex78191

8
我在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),它能够正常工作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接