Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: servlet refresh problem after database query

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default servlet refresh problem after database query

    Hi,

    I am calling a stored procedure to receive data in a results set, I loop through the results set and create hidden fields with the results. The data is coming back correctly and everthing is fine until I run the same servlet again, it doesnt work unless I hit the refresh button, can someone clarify if am closing the DB connections correctly or if there is some other issue, see code below. If I take out the db query and just hardcode the input fields it works every time I run.
    CallableStatement cstmt = null;
     
    			this.getDbManager().closeDbStatement();
     
    		try {
    			this.getDbManager().createDbStatement();
    			cstmt = this.getDbManager().getDbConnection().prepareCall("{call  myproc(?,?,?,?,?)}");
     
    			cstmt.setDouble(1,Double.parseDouble(this.getRequest().getParameter("xBl")));
    			cstmt.setDouble(2,Double.parseDouble(this.getRequest().getParameter("yBl")));
    			cstmt.setDouble(3,Double.parseDouble(this.getRequest().getParameter("xTr"))); 
    			cstmt.setDouble(4,Double.parseDouble(this.getRequest().getParameter("yTr")));
    			cstmt.registerOutParameter(5, OracleTypes.CURSOR);
    			cstmt.execute(); 
     
    			ResultSet rs = (ResultSet) cstmt.getObject(5);
     
    			String f_num = new String();
    			int i = 1;
    			String p_num = new String();
    			int p = 1;
    			while (rs.next()) {
    				f_num = rs.getString("f");
    				p_num = rs.getString("p");
    				out.println("\t\t<INPUT TYPE=HIDDEN NAME=\"f_id" + i
    						+ "\" VALUE=\"" + f_num + "\">\n");
    				out.println("\t\t<INPUT TYPE=HIDDEN NAME=\"p_id" + p
    						+ "\" VALUE=\"" + p_num + "\">\n");
     
    				p++;
    				i++;
    						      }
    				rs.close();
    		      cstmt.close();
     
    		      this.getDbManager().closeDbStatement();
    		      this.getDbManager().closeDbConnection();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			exceptionErrorLog(e, this.getClass().getName() + "debug1 " + e.toString());
    		} finally{
    		      //finally block used to close resources
    		      try{
    		         if(cstmt!=null)
    		            cstmt.close();
    		      }catch(SQLException se2){
    		      }// nothing we can do
     
    		}
    		}
    Last edited by copeg; January 12th, 2012 at 01:27 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: servlet refresh problem after database query

    For future reference, please wrap your code in the code tags

    What do you mean by 'run the servlet again'? To me, this equates to reloading. If you are accessing this via a browser, does your browser cache the webpage? Try accessing the servlet using a non-cachable route

Similar Threads

  1. how to searching data from database using servlet??
    By mr.nash in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: December 21st, 2011, 03:09 PM
  2. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  3. Problem with Java/MySQL query...
    By RiskyShenanigan in forum JDBC & Databases
    Replies: 2
    Last Post: March 28th, 2011, 03:50 AM
  4. Access database SQL query help
    By mjpam in forum JDBC & Databases
    Replies: 3
    Last Post: September 8th, 2010, 08:48 AM
  5. GUI - refresh problem
    By Shnkc in forum AWT / Java Swing
    Replies: 5
    Last Post: April 2nd, 2010, 06:11 AM