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);
}
}
}
When I execute this code, It is showing "net.ucanaccess.jdbc.UcanaccessSQLException: Column not found: 0"
. Please help me!
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:
(Emphasis mine.)
simply
the ResultSet rs begins with index 1 not 0 so you should write rs.getInt(1) or rs.getObject(1)