Possible explanation for why "SELECT" query executed from JDBC returning just the first row in the table
1
vote
0
answers
50
views
I installed OracleDB(XE - free version) and I tried to use it in Java. I have this code:
Java version: jdk 1.8.0
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);
) {
while(rs.next()){
//Display values
System.out.print(rs.getString("fam_name"));
System.out.print(" ");
System.out.print(rs.getString("giv_name"));
System.out.print(" ");
System.out.print(rs.getInt("age"));
System.out.print(" ");
System.out.print(rs.getString("email") + "\n");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
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
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.
Java version: jdk 1.8.0
Asked by Bogdan FloareČ™
(111 rep)
Sep 13, 2023, 07:22 PM