Corey
Corey

Reputation: 23

java.sql.SQLException: Column not found

Pretty simple assignment here and I thought I had everything correct but apparently not :(

Basically all this jsp needs to do is display distinct values from a DB in a drop down and based on the selected value when the user presses the submit button they will be directed to another jsp where in a table it will display other values that correspond to it. I have emailed my professor and he is reluctant to responding. Any help is much appreciated! Here is my code and thanks for your time and help!

try
{
          String query3 = "SELECT DISTINCT CATEGORY FROM POEMS;";
          ResultSet rs3 = stmt3.executeQuery(query3);  
          rs3.next();
%>  
          <FORM ACTION="purcell6b.jsp" METHOD="POST">
<%
          out.println("<SELECT name='category'>");
          while (rs3.next())
          {
              String category = rs3.getString("CATEGORY");

              out.println("<OPTION value='" + category + "'>" + category);
              out.println("</OPTION>");
           } 
           out.println("</SELECT>");
%> 
           <input type = submit value="Submit">
           </form>
<%  
}
catch (Exception e)
{
   e.printStackTrace();     
}


Second JSP:

String query = "select POEMID, DESCRIPTION, TITLE, POETID " + "from POEMS WHERE CATEGORY like ?;";

try
{
    stmt.setString(1, input1);
    ResultSet rs = stmt.executeQuery();

<%
    while (rs.next())
    {
       String poemID = rs.getString("POEMID");
       String title = rs.getString("TITLE");
       String description = rs.getString("DESCRCIPTION");
       String catetgory = rs.getString("CATEGORY");
       String poetID = rs.getString("POETID");

%>
<TR>
       <TD><input type='radio' name='poemID' value='<%=poemID%>'> </TD>
       <TD><%= poemID %></TD>
       <TD><%= title %></TD>
       <TD><%= description %></TD>
       <TD><%= catetgory %></TD>
       <TD><%= poetID %></TD>

       </TR>
<%
    }
%>
    </TABLE>
    </FORM>

<% } catch (Exception e) { e.printStackTrace();
}

I know how to insert into a table its just the passing of the parameter that I'm confused on.

Thanks! Corey

Upvotes: 0

Views: 5544

Answers (4)

Mike Hurtado A
Mike Hurtado A

Reputation: 26

you need to verify en mysql

desc poems;

and verify your code if the columns in the database and the program have the same name

Upvotes: 0

emhlbmc
emhlbmc

Reputation: 258

The first answer is right and you should check your Column names and they must be consistent with the setting names. your sql:String query = "select POEMID, DESCRIPTION, TITLE, POETID " + "from POEMS WHERE CATEGORY like ?;"; your assignment statement:rs.getString("DESCRCIPTION");

Upvotes: 1

Joel Wembo
Joel Wembo

Reputation: 870

Make sure you name your column name correctly or it refer correctly what is in the database table

Upvotes: 0

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4191

Check your Code:

enter image description here

This must be rs.getString("DESCRIPTION");

Upvotes: 1

Related Questions