简体   繁体   English

java.sql.SQLSyntaxErrorException:ORA-00911:无效字符

[英]java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

I have the following java code for inserting values to the database 我有以下用于将值插入数据库的Java代码

When i try the code below it works 当我尝试下面的代码时

st.executeUpdate("INSERT INTO USERT " +  "VALUES ('1', 'Simpson', 'Mr', 'Springfield', '2001')");

But when i try the code below i get an error 但是当我尝试下面的代码时,我得到一个错误

java.sql.SQLSyntaxErrorException: ORA-00911: invalid character java.sql.SQLSyntaxErrorException:ORA-00911:无效字符

st.executeUpdate("INSERT INTO USERT (`USERID`, `FIRSTNAME`,`LASTNAME`,`EMAIL`,`PHONE`) VALUES ('2', 'james', 'john', 'myemail', 'myphone')");

Most of the answers provided here at stack overflow refer to a character misplacement of a semicolon ; 堆栈溢出时,此处提供的大多数答案都涉及分号的字符错位; . ie link 1 , link 2 , link 3 which does not seem to help me 链接1链接2链接3似乎没有帮助我

Here is the full code of my class 这是我班上的完整代码

package dbproject;

import java.sql.*;

public class jdbcconnection {

    public static void main(String[] args) {
        try{

        Class.forName("oracle.jdbc.driver.OracleDriver");
        java.sql.Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","data1","mypass");
        Statement st=con.createStatement();

        st.executeUpdate("INSERT INTO USERT (`USERID`, `FIRSTNAME`,`LASTNAME`,`EMAIL`,`PHONE`) VALUES ('2', 'james', 'john', 'myemail', 'myphone')");

        //st.executeUpdate("INSERT INTO USERT " +  "VALUES ('1', 'Simpson', 'Mr', 'Springfield', '2001')");

        con.close();

        }
        catch(Exception e){

                System.out.println(e);

        }
    }
}

What could be wrong with my execute query and what else could lead to the error? 我的执行查询可能有什么问题,还有什么可能导致错误?

MySQL and Oracle have some minor differences in their definition of an identifier. MySQL和Oracle在标识符定义方面有一些细微的差别。 In MySQL, an unquoted identifier may begin with a digit, and double quotation marks are allowed in a quoted identifier; 在MySQL中,未加引号的标识符可以以数字开头,并且在加引号的标识符中允许使用双引号。 however, neither of these is allowed in an Oracle identifier. 但是,Oracle标识符中均不允许使用这些方法。 In MySQL, the quote character is the backtick (`). 在MySQL中,引号字符是backtick (`)。 If the SQL mode ANSI_QUOTES is set, double quotes can also be used to quote the identifiers. 如果设置了SQL模式ANSI_QUOTES,则也可以使用双引号将标识符引起来。 In Oracle, identifiers are quoted using double quotation marks. 在Oracle中,标识符使用双引号引起来。

https://docs.oracle.com/cd/E12151_01/doc.150/e12155/oracle_mysql_compared.htm#i1026354 https://docs.oracle.com/cd/E12151_01/doc.150/e12155/oracle_mysql_compared.htm#i1026354

try; 尝试;

   st.executeUpdate("INSERT INTO USERT (USERID, FIRSTNAME,LASTNAME,EMAIL,PHONE) VALUES ('2', 'james', 'john', 'myemail', 'myphone')");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.eclipse.persistence.exceptions.DatabaseException内部异常:java.sql.SQLSyntaxErrorException:ORA-00911:无效字符 - org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character SQLSyntaxErrorException:ORA-00911:无效字符 - SQLSyntaxErrorException: ORA-00911: invalid character 带ORA-00911的SQL插入:无效字符 - SQL Insert with ORA-00911: invalid character java存储过程导致ORA-00911:无效字符 - java stored procedure cause ORA-00911: invalid character 插入错误:java.sql.SQLException:ORA-00911:无效字符 - Insertion error : java.sql.SQLException: ORA-00911: invalid character Oracle:ORA-00911:无效字符 - Oracle: ORA-00911: invalid character java.sql.SQLSyntaxErrorException:ORA-00903:表名无效 - java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name java.sql.SQLSyntaxErrorException:ORA-00904:“columnName”:无效标识符 - java.sql.SQLSyntaxErrorException: ORA-00904: “columnName”: invalid identifier 错误 --> java.sql.SQLSyntaxErrorException: ORA-01722: 无效号码 - ERROR --> java.sql.SQLSyntaxErrorException: ORA-01722: invalid number java.sql.SQLSyntaxErrorException:ORA-00922:缺少或无效的选项 - java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM