gpt4 book ai didi

java - 列索引无效

转载 作者:行者123 更新时间:2023-11-30 22:26:46 26 4
gpt4 key购买 nike

下面是我的部分代码。我的数据库部分不断出现错误。我已经在多个地方查找它们,但似乎找不到答案。有什么建议么?代码和打印为错误的内容如下所示!

public void deleteEmployee()
{
String sqlQuery;
sqlQuery = "DELETE FROM JAVAUSER.EMPLOYEE";
System.out.println(sqlQuery);
sendDBCommand(sqlQuery);
}

public void deleteAccident()
{
String sqlQuery;
sqlQuery = "DELETE FROM JAVAUSER.ACCIDENT";
System.out.println(sqlQuery);
sendDBCommand(sqlQuery);
}

public void deleteTruck()
{
String sqlQuery;
sqlQuery = "DELETE FROM JAVAUSER.TRUCK";
System.out.println(sqlQuery);
sendDBCommand(sqlQuery);
}

public void deleteHomeState()
{
String sqlQuery;
sqlQuery = "DELETE FROM JAVAUSER.HOMESTATE";
System.out.println(sqlQuery);
sendDBCommand(sqlQuery);
}

public void deleteCountry()
{
String sqlQuery;
sqlQuery = "DELETE FROM JAVAUSER.COUNTRY";
System.out.println(sqlQuery);
sendDBCommand(sqlQuery);
}

以下是不断弹出的错误:

run:
DELETE FROM JAVAUSER.HOMESTATE
java.sql.SQLException: ORA-01002: fetch out of sequence

DELETE FROM JAVAUSER.COUNTRY
java.sql.SQLException: ORA-01002: fetch out of sequence

DELETE FROM JAVAUSER.TRUCK
java.sql.SQLException: ORA-01002: fetch out of sequence

DELETE FROM JAVAUSER.ACCIDENT
java.sql.SQLException: ORA-01002: fetch out of sequence

DELETE FROM JAVAUSER.EMPLOYEE
java.sql.SQLException: ORA-01002: fetch out of sequence

此外,当我的程序按下“插入按钮”时,我会按顺序调用所有删除方法

如何摆脱这些错误信息?

这是我的 sendDBCommand:

public static void sendDBCommand(String sqlQuery)
{
String jdbcConnectionURL = "jdbc:oracle:thin:@localhost:1521:XE";
String userID = "javauser";
String userPASS = "javapass";

try
{
Connection conn = getDBConnection(jdbcConnectionURL, userID, userPASS);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rset = stmt.executeQuery(sqlQuery);

int traverse = 0;
while (rset.next())
{
System.out.println(rset.getString(1) + " " + rset.getString(2));
}
}
catch (SQLException e)
{
System.out.println(e.toString());
}
}

最佳答案

你应该包括一个计数器并打印结果,所以也许你应该有一个线索,而且,对于 delete 没有结果集,它应该是 executeUpdate。

关于java - 列索引无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34981819/

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