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

I have the following java code for inserting values to the database

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

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 ;. i.e. link 1 , link 2, link 3 which does not seem to help me

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. In MySQL, an unquoted identifier may begin with a digit, and double quotation marks are allowed in a quoted identifier; however, neither of these is allowed in an Oracle identifier. In MySQL, the quote character is the backtick (`). If the SQL mode ANSI_QUOTES is set, double quotes can also be used to quote the identifiers. In Oracle, identifiers are quoted using double quotation marks.

try;

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值