gpt4 book ai didi

java - SQL 插入 ORA-00911 : invalid character

转载 作者:行者123 更新时间:2023-12-01 13:16:47 25 4
gpt4 key购买 nike

我正在向 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)

最佳答案

该行缺少最后一个逗号“,”:

DepartCity char(20) NOT NULL

编辑:还发现插入语句字符串包含制表符而不是空格。

关于java - SQL 插入 ORA-00911 : invalid character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22410236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com