Midnight Blue
Midnight Blue

Reputation: 5141

DB2 JDBC: "Same" query gives different results

I've been assigned to develop a small Java application to process some data from a DB2 database(used for logging business transactions), and I know a little about the internal settings of the datbase. Currently, I am struggling to find out why a query executed on my application(through JDBC) gives a different result set from a direct query executed on my Quest Central for DB2 client.

    String query = "SELECT DISTINCT SYSTEM_NME FROM MISUSER.USAGE_LOGGER";

    try {
        Connection conn = DB2Connect.getDB2Connection();
        Statement stmt = conn.createStatement();

        ResultSet rs = stmt.executeQuery(query);
        while(rs.next()){
            retval.add(rs.getString(this.code.column_name));
        }

    } catch (SQLException e) {...

The above code returns a ResultSet object with 7 rows, while the same query executed on my db2 client returns more than 30 rows. As mentioned earlier, I have minimal experience working with database, and I need some sort of idea how the same query can generate two different results.

Upvotes: 3

Views: 3022

Answers (1)

BalusC
BalusC

Reputation: 1109422

Several causes.

  • It's not the same DB and/or schema.
  • The table has row-level security (DB2 has this feature) and the logged-in JDBC user hasn't sufficient rights for the ones which aren't returned.
  • Those lot of rows were inserted and selected within the same transaction which wasn't committed.

Upvotes: 4

Related Questions