I am trying to make a java program program can takes just one row/line from phpMyAdmin database. what I mean is in the photo
The problem is that I couldnt figure out how to take just the first line because its always keep giving me all the id’S , dafat’s , etc. Is there any way I can get every line alone or even every data alone (jsut 1 id from the first line for example). I would appreciate who can help me with this.
Connection con = myConnection.getconnection();
try{
PreparedStatement ps = con.prepareStatement("SELECT `id`, `dafat`, `sinif`, `adet`, `price`, `type`, `total` FROM "+ff1+" WHERE 1 ");
ResultSet resultset = ps.executeQuery();
System.out.println(resultset.getString("id"));
}
catch (Exception e) {
}
3
Answers
Use the
LIMIT
clause:If you want the first
id
value (the smallest one) you can combine withORDER BY
, as in:Replace WHERE whit LIMIT
Use Rownum in your where clause like:
https://mfaisal1521.blogspot.com/2020/04/rownum-in-sql.html
And also resultset.getString(“id”) start fetch result from first index of query untill we dont move our cursor to next resultset.