Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:17:15+00:00 2026-06-14T09:17:15+00:00

Basically I’m trying to loop through my database and display all of the information

  • 0

Basically I’m trying to loop through my database and display all of the information inside. I understand the concept that but my implementation is clearly wrong as Tomcat keeps giving me the the following error:

Root cause:

javax.servlet.ServletException: Operation not allowed after ResultSet closed

Any help would be much appreciated. I know the problem is with my while loop but my knowledge is limited and I cannot spot the changes I need to make. Please feel free to change the code.

<%@ page import="java.sql.*" %>

<%
String connectionURL = "jdbc:mysql://addr.to.db:3306/dbname";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<html>

<head>
<title>JSP Server Response</title>
</head>

<body>
<h1>JSP Server Response:</h1>

<!--Get information from HTML form for manipulation-->

<%
    String songName = request.getParameter("newSongName");
String artistName = request.getParameter("newArtistName");
String password = request.getParameter("pass");
String radioResults = request.getParameter("dbIO");
%>

<%

Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "userName", "password");
statement = connection.createStatement();
String query = "SELECT * FROM song_info;";
rs = statement.executeQuery(query);

//Add or Delete Information from DB

if(radioResults.equalsIgnoreCase("insert"))
{
    statement.executeUpdate("INSERT INTO song_info (songTitle, artistName) VALUES                     ('"+artistName+"','"+songName+"')");
}
else if(radioResults.equalsIgnoreCase("delete"))
{
statement.executeUpdate("DELETE FROM song_info WHERE artistName='"+songName+"'");
}
%>

<table>
<tr>
<th>Song Name</th><th>Artist Name</th>
</tr>

<% while(rs.next()){ %>
<tr>
<td align=center> <%= rs.getString("songTitle")%></td>
<td align=center> <%= rs.getString("artistName")%></td>
</tr>
<%}%>
</table>

<%
rs.close();
statement.close();
connection.close();
%>

Information Submitted to Server:

Artist Name: <%=songName%> <br />
Song Name: <%=artistName%> <br />
Password: <%=password%><br />
Radio Button Selection: <%=radioResults%><br /><br />

Password Correct: 

</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:17:16+00:00Added an answer on June 14, 2026 at 9:17 am

    The problem is that you are using the same Statement object to execute multiple queries. If you re-use the Statement, then any resources like ResultSet from a previous execution are closed.

    The solution is either to re-order the query (like you did in your own answer), or to use separate Statement objects for the query and the updates.

    Also your current code exposes you to SQL injection. Please use PreparedStatement with parametrized queries. This will protect you from most – if not all – SQL injection attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically I am creating a dynamic google map that pulls information from the database,
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically from a database I am getting data that is formatted like this nameofproject101
I am trying to loop through a bunch of documents I have to put
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, what I'm trying to create is a page of div tags, each has
Basically, I have a main page (parent page) with a link that opens up
Basically this function is meant to store the height value of the element that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.