简体   繁体   中英

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

Check your Code:

在此处输入图片说明

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

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 ");

确保您正确命名列名,或正确引用数据库表中的内容

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM