[英]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. 基本上,所有这些jsp所需要做的就是在下拉列表中显示来自数据库的不同值,并且当用户按下“提交”按钮时,基于所选值,它们将被定向到另一个jsp,在表中它将显示与之相对应的其他值。它。 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: 第二个JSP:
String query = "select POEMID, DESCRIPTION, TITLE, POETID " + "from POEMS WHERE CATEGORY like ?;"; 字符串查询=“选择POEMID,DESCRIPTION,TITLE,POETID” +“从POEMS WHERE CATEGORY之类的?;”;
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(); <%} catch(异常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 科里
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 ?;"; 您的sql:String查询=“从像这样的POEMS类别中选择POEMID, DESCRIPTION ,TITLE,POETID” +“; your assignment statement:rs.getString(" DESCRCIPTION "); 您的赋值声明:rs.getString(“ DESCRCIPTION ”);
确保您正确命名列名,或正确引用数据库表中的内容
you need to verify en mysql 您需要验证mysql
desc poems;
and verify your code if the columns in the database and the program have the same name 并验证您的代码是否数据库和程序中的列具有相同的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.