my dog learned polymorphism
The moose likes Servlets and the fly likes Servet and Jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servet and Jdbc" Watch "Servet and Jdbc" New topic

Servet and Jdbc

padmshree Patil
Ranch Hand

Joined: Dec 18, 2000
Posts: 54
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..
rs =st.executeQuery("select mark from Result");
out.println("after executing query " + "<P>");

/** 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("marks obtained : " + count);
Rusult dabase has total 5 records.Why is it fetching only one record?
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
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");
count = count+ mark;
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
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..
I agree. Here's the link:
subject: Servet and Jdbc
It's not a secret anymore!