带ORA-00911的SQL插入:无效字符

时间:2014-03-14 16:07:48

标签: java sql oracle jdbc

我在Oracle数据库的表“flight”中添加了一些新记录。但是,我遇到了一个在有​​效字符中调用的错误。任何人都可以帮助我从插入声明中找出错误。

我的表创建声明如下。

 create table flight(
       FlightID integer NOT NULL,
       Airline char(20) NOT NULL,
       DepartCity char(20) NOT NULL,
       ArrivalCity char(20) NOT NULL,
       DepartTime timestamp NOT NULL,
       ArrivalTime timestamp NOT NULL,
       Class2Price integer NOT NULL,
       Class1Price integer NOT NULL,
       Class2Seats integer NOT NULL,
       Class1Seats integer NOT NULL,
       primary key (FlightID));

我的插入如下

insert into flight(FlightID, Airline, DepartCity, ArrivalCity, DepartTime, ArrivalTime,         Class2Price, Class1Price, Class2Seats, Class1Seats)
Values(2,'Pacific Airlines','Taipei','Osaka',to_timestamp('2014-12-01 08:15','yyyy-mm-dd HH24:MI'),to_timestamp('2014-12-01 13:15','yyyy-mm-dd HH24:MI'),4500,6000,2,6);

我的JDBC JavaCode如下

stmt.execute("insert into flight(FlightID, Airline, DepartCity, ArrivalCity, DepartTime, ArrivalTime, Class2Price, Class1Price, Class2Seats, Class1Seats)"
                +"values("+ values+")");

其中值为

   values =2,'Pacific Airlines','Taipei','Osaka',to_timestamp('2014-12-01 08:15','yyyy-mm-dd HH24:MI'),to_timestamp('2014-12-01 13:15','yyyy-mm-dd HH24:MI'),4500,6000,2,6

错误代码如下

 3月 15, 2014 12:45:06 上午 database.application.DatabaseApplication load_data

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

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:183)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:936)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1770)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1739)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:298)
at database.application.DatabaseApplication.load_data(DatabaseApplication.java:282)
at database.application.DatabaseApplication.Data_mani_menu(DatabaseApplication.java:106)
at database.application.DatabaseApplication.main_menu(DatabaseApplication.java:55)
at database.application.DatabaseApplication.main(DatabaseApplication.java:28)

1 个答案:

答案 0 :(得分:1)

这一行缺少最后一个逗号' ,':

  

DepartCity char(20)NOT NULL

编辑:事实证明,插入语句字符串包含制表符而不是空格。