This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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..
Don't get me started about those stupid light bulbs.
subject: Servet and Jdbc
Similar Threads
Is there any one who can help me...Please?
Pagination in Servlets from a Resultset
jdbc and servlets
problem with my insert data page
Access Data from Database By Submitting The select Values