0
I’m trying to return the amount of record of a table, in this table I currently have 6 records but my Query returns only one, as if there were only one record. I need you to return the full amount, 6 records.
Query I used in SQL and worked
SELECT COUNT ([num_item])
FROM tb_temp_prod;
Query in JAVA
Connection conn = null;
Statement stmt = null;
Class.forName(JDBC_DRIVER).newInstance();
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT COUNT(*) AS num_item FROM tb_temp_prod");
while(result.next()){
result.getInt("num_item");
//result.getInt(1); Já tentei assim também e não deu certo.
}
System.out.println("Total: " + result);
Result: Total: Sqlserverresultset:1
The treatment
result.getInt(1);
is unnecessary.– Augusto Vasques
Perfect, thank you. I tested it here and it worked without. TKS @Augustovasques
– Ronison Matos