I installed OracleDB(XE - free version) and I tried to use it in Java. I have this code:

       static final String DB_URL = "jdbc:oracle:thin:@localhost:1521/XE";
       static final String USER = "AdministratorPDB1";
       static final String PASS = "admin.admin";
       static final String QUERY = "SELECT * FROM TestTable";

       public static void main(String[] args) {

          try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery(QUERY);
          ) {             
                //Display values
                System.out.print("          ");
                System.out.print("          ");
                System.out.print("          ");
                System.out.print(rs.getString("email") + "\n");
          } catch (SQLException e) {

For some reason, the program seems to print just the first row from the table. I can confirm the fact that there are more entries in that table if I open Windows Command Prompt, connect using sqlplus command, and run the SELECT * FROM TestTable;, query, all three rows are printed in the command line.

I also tried to loop over the rows like this:

ResultSetMetaData metaData = resultSet.getMetaData();
int numCols = metaData.getColumnCount();

while (resultSet.next()) {
    for (int i = 1; i <= numCols; i++) {
        String colName = metaData.getColumnName(i);
        String colValue = resultSet.getString(i);
        System.out.println(colName + ": " + colValue);

The same problem. Just the first entry is displayed. It seems to have something to do with resultSet.next().

Now, I know I might have not given enough information for a solve, but this is all I got. This is a hard problem to debug.

OracleDB version: 21c
Java version: jdk 1.8.0
  • "This is a hard problem to debug" -- I don't think it is, but have you done any debugging? Like, actually using a debugger?
    – mustaccio
    Sep 13 at 19:42
  • WDYM? What debugging I can do. I just call a method from a library, how should I get low-level access to what's happeing behind the scenes with the .next() method? Sep 13 at 19:46
  • 1
    Fire up your favourite debugger, step into next(), and enjoy the magic show. However, I suspect that, whatever is happening, is happening outside next().
    – mustaccio
    Sep 13 at 19:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.