Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc and servlets

 
padmshree Patil
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using servlet to insert values in Result database.It's working fine.But when I retrive data .It only select one record and then raise exception as No data found
code is as below..
--------------------------------------------
try
{
rs =st.executeQuery("select mark from Result");
out.println("after executing query " + "
");
while(rs.next())
{

out.println(rs.getInt("Mark"));
/** after this statement it raises exception and comes out of while and print marks obtained ststement **/

count = count+ rs.getInt("Mark");
out.println("after adding marks to count");
out.println("count " + count + "
");
out.println("Marks from database ......" + rs.getInt("Mark") + "
");
}
}catch(SQLException e)
{
out.println(e.getMessage());
}
}

out.println("marks obtained : " + count);
--------------------------------------------------
Rusult dabase has total 5 records.Why is it fetching only one record?
--
Padmashree
 
Bhupinder Dhillon
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should get the value once only. If you repeatedly try getting the same value from the same row then it throws exception.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't notice that. Also, the "Mark" must be in the same case as the "select" statement.
 
Monty Ireland
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
padmshree Patil
Try reviewing the demo jdbc examples that come with the jdk.
I think if you review some code examples.
Most of you How-To jdbc question can be resolved...
Monty
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic