File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servet and Jdbc" Watch "Servet and Jdbc" New topic
Author

Servet and Jdbc

padmshree Patil
Ranch Hand

Joined: Dec 18, 2000
Posts: 54
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

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");
out.println(mark+"");
count = count+ mark;
HTH
Brian
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servet and Jdbc