简体   繁体   中英

Issue with Java SQL or Database View? Confused with result

I have 2 views in SQL Developer, view1 and view2. view1 is created from table1 and view2 is created using unions between 2 other views. BOTH views show expected data on SQL Developer and have same Grants.

I tried to run Java query against view2 but am not getting any results from a "select *", however, i get results fine from view1.

String table = “view2”;

    Statement stmt = dataSource.getConnection.createStatement();
    ResultSet rs = stmt.executeQuery(“select * from “ + table);
    if(rs.next()){ //rs.next() returns true if there is a value from ResultSet
       System.out.println(“exist”);
    } else {
       System.out.println(“doesn’t exist”);
    }

If i run view1, i get "exist" and i can print out row values, with view2, i get "doesn't exist". Additional observations:

  1. Grants for both views are the same, no errors on views.
  2. No exceptions seen, Statement is not null, ResultSet is not null either so it means the query did run, just returned 0 results when there should be many.
  3. I tried other views or tables and they work fine too.

I am very lost on this... anyone can help? thanks

So it was some permission inside the SQL that is messing it up. it is fixed now! thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM