0

the problem i am facing is that my result set is only returning one row value while there are three. and i could not found where the problem is:

  public void eventInfo() throws SQLException
    {
     openConnection();
    PreparedStatement ps1=null;

    String query1="select * from events";

    try {
        ps1 = con.prepareStatement(query1);
    } catch (SQLException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    }





            EventData e= new EventData();
            e.edata.clear();
            Events obj = new Events();

    ResultSet s=ps1.executeQuery();
    int i=0;

            System.out.println(s);

    if(s.next())
    {
//                        obj.setId(s.getInt("id"));
//          obj.setTitle(s.getString("title"));
//          obj.setDescription(s.getString("description"));
//          
//          obj.setType(s.getString("type"));
//          obj.setOrganization(s.getString("organization"));
 //         obj.setPlace(s.getString("place"));
 //         obj.setTime(s.getString("time"));
 //         obj.setDate(s.getString("date"));
 //         obj.setRepetetion(s.getString("repetetion"));
 //         obj.setParticipants(s.getInt("participants"));
 //         obj.setLimit(s.getInt("elimit"));

                    System.out.println(i);
                    System.out.println(s.getString("title"));
                    i++;

                 //   e.edata.add(obj);


    }


    if(con!=null)
    {
        con.close();
    }

    }

the database tables like enter image description here

the output looks like enter image description here

can anyone help me with that?

2 Answers 2

3

It should not surprise you that

if(s.next())

is not a loop but rather a condition. If you want to continuously access the result set you have to use a loop

while (s.next())
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much...i just ignored that... thank you so much
1
while (s.next()) {...}

...should do it for you. This will iterate through all rows.

1 Comment

Thank sir ... i got the result now

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.