gpt4 book ai didi

java - 网络.ucanaccess.jdbc.UcanaccessSQLException : Column not found: 0

转载 作者:行者123 更新时间:2023-11-30 06:16:55 24 4
gpt4 key购买 nike

我是 UCanAccess 的新手

package checktpsystemdatabase;

import java.sql.*;

public class CheckTPSystemDatabase {

public static void main(String[] args) throws SQLException {
try {
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:/Java/TransactionProcessingSystem/src/transactionprocessingsystem/Resources/TPSystem.accdb");

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Product");

while (rs.next()) {
System.out.println(rs.getInt(0) + "\t" + rs.getString(1) + "\t" + rs.getString(2));
}
rs.close();

} catch (SQLException e) {
System.out.println(e);
}
}
}

当我执行这段代码时,它显示 "net.ucanaccess.jdbc.UcanaccessSQLException: Column not found: 0"。请帮助我!

最佳答案

您看到该错误是因为 JDBC 结果集的数字索引值以 1 开头,而不是 0。或者,正如他们在 Java 教程的“从行中检索列值”部分所说的那样 here :

The ResultSet interface declares getter methods (for example, getBoolean and getLong) for retrieving column values from the current row. You can retrieve values using either the index number of the column or the alias or name of the column. The column index is usually more efficient. Columns are numbered from 1

(强调我的。)

关于java - 网络.ucanaccess.jdbc.UcanaccessSQLException : Column not found: 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26527054/

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