Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servet and Jdbc

 
padmshree Patil
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am usind servlet to inser 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 " + "<P>");
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 + "<P>");
out.println("Marks from database ......" + rs.getInt("Mark") + "<P>");
}
}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
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Result Sets don't like it if you try and get the same object twice. Change your code to first retrieve the value from the ResultSet, and then you can use that value as many times as you want:
int mark = rs.getInt("Mark");
out.println(mark+"");
count = count+ mark;
HTH
Brian
 
Raukutam Sandeep
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
in JDBC, u need to retrieve the value only one, u cannot retrieve it twice which throws an exception.
Instead,retrieve the value once, store it in variable, and use it..
regds,
Sandeep.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic