39

I have error for code:

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);
}
user3425433
  • 391
  • 1
  • 3
  • 3

2 Answers2

103

The problem is ;

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

Remove the ; from above string.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Abhishek
  • 1,031
  • 1
  • 7
  • 3
8

I have also received same problem in myBatis.

Error:

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

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

Solution:

select * from tableName where id= '123';

after removing ";" from Where clause(Mybatis Mapper xml), its working.

Anantha Raju C
  • 1,780
  • 12
  • 25
  • 35