Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes problem with resultset in reference with my previous post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with resultset in reference with my previous post" Watch "problem with resultset in reference with my previous post" New topic
Author

problem with resultset in reference with my previous post

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
Hi All!!
Thanks for ur concern in solving out my query.
as u asked for the code, i don't know how best i can represent it to u, as it's very easy easy to get confused with the project specific intricacies & database details.
one or two three things i would like to tell u
1. i don't what do u mean by thread safe sevlet or jsp page for that metter (and i only know that web server takes care of it by itself.)
2. i haven't closed my resultset object anywhere in the whole file as if i go about doing that then tomcat causes even more problem.
i mean i haven't used the folowing code anywhere in the file
resultset1.close();
resultset2.close();
statement1.close();
statement1.close();
conn.close();
now here is my code sample............................
ur help is very much required....
Thanks in advance
lusha

<%response.setContentType("text/html");<br /> response.setDateHeader("Expires",0);<br /> response.setHeader("Cache-Control","no-cache");<br /> response.setHeader("Pragma","no-cache");<br /> %>

<%@ page language='java' import='java.sql.*,javax.servlet.*,javax.servlet.http.*,java.io.*,java.sql.*,java.util.*' %><br /> <HTML><br /> <HEAD><br /> </HEAD><br /> <%<br /> HttpSession mysession=request.getSession(true);<br /> String user_type= (String)mysession.getValue("ut");<br /> //the following code checks for the vaidity of session<br /> if(mysession.isNew()| |(user_type==null))<br /> {<br /> //if invalid print "u have already logged out" on the terminal<br /> %><br /> <body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF"><br /> <br /> <br /> <center><h4>You have already logged out !</h4></center><br /> </body><br /> </html><br /> <%<br /> mysession.invalidate();<br /> }<br /> else<br /> {<br /> //if valid session do the folowing procesing<br /> %><br /> <body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF"><br /> <FORM name="frm" METHOD=POST ACTION="/ExamEngine/eval_paper.jsp"><br /> <%! <br /> //database objects declarations<br /> Connection conn=null;<br /> ResultSet resultset1=null;<br /> ResultSet resultset2=null;<br /> Statement statement1=null;<br /> Statement statement2=null;<br /> //other instance variable declarations such as<br /> String exam_cand_id;<br /> %><br /> <%<br /> //get value from session variable such as<br /> exam_cand_id = (String)mysession.getValue("exam_cand_id");<br /> %><br /> <br /> <%<br /> //database connection code<br /> <br /> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br /> conn=DriverManager.getConnection("jdbc dbc:ex_eng", "sa", "");<br /> statement1=conn.createStatement();<br /> statement2=conn.createStatement();<br /> <br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some select query statemnt with "statement2","resultset2"<br /> //value retrieval from "resultset2"<br /> <br /> <br /> %><br /> <%<br /> }//end of else<br /> %>
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

lusha:
I could see your code when I went to reply to you. To make your code visible you have to take the html stuff out and just post the java code. I think I see your problem. you are using the jdbc dbc bridge. There are some restrictions when you use this driver. One of them is that you can only have one statement per connection. I see that you have 2 statements for 1 connection. When you open the second statement, you are implicitly closing the first statement(and again implicitly closing any associated resultsets to the first statement). You are limited to one statement per connection, so you need to open another connection to exececute the second statement.
Jamie
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

here are some jdbc dbc FAQ's: http://java.sun.com/products/jdbc/faq.html

and specifically for your problem: http://java.sun.com/products/jdbc/faq.html#21
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with resultset in reference with my previous post
 
Similar Threads
frames
problem with resultset in reference with my previous post
thread safety issue.......
No margins in Netscape?
problem with result set,if multiple users access the application