net.ucanaccess.jdbc.UcanaccessSQLException:找不到列:0 [英] net.ucanaccess.jdbc.UcanaccessSQLException: Column not found: 0

查看:887
本文介绍了net.ucanaccess.jdbc.UcanaccessSQLException:找不到列:0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UCanAccess的新手

I am new for 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".请帮帮我!

When I execute this code, It is showing "net.ucanaccess.jdbc.UcanaccessSQLException: Column not found: 0". Please help me!

推荐答案

您会看到此错误,因为JDBC ResultSet的数字索引值以1而不是0开头. Java教程此处:

You are seeing that error because the numeric index values for a JDBC ResultSet start with 1, not 0. Or, as they say in the "Retrieving Column Values from Rows" section of the Java Tutorial here:

ResultSet接口声明用于从当前行中检索列值的getter方法(例如,getBoolean和getLong).您可以使用列的索引号或列的别名或名称来检索值.列索引通常更有效. 列从1开始编号

(强调我的.)

这篇关于net.ucanaccess.jdbc.UcanaccessSQLException:找不到列:0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆