Java 使用MYSQL的JSP中的NoSuchElementException
我不断得到以下异常:org.apache.jasper.JasperException:java.util.NoSuchElementException 你能帮我写代码吗,因为我明显遗漏了什么。非常感谢 JSP文件:Java 使用MYSQL的JSP中的NoSuchElementException,java,mysql,jsp,Java,Mysql,Jsp,我不断得到以下异常:org.apache.jasper.JasperException:java.util.NoSuchElementException 你能帮我写代码吗,因为我明显遗漏了什么。非常感谢 JSP文件: <% Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement()
<%
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
StringBuffer sb = new StringBuffer(name);
sb.deleteCharAt(0);
VoCo.Vogel.Delete(sb.toString());
}
%>
<br>
<div class="navigator">
<a href="index.jsp">Add</a>
<a id="currenttab" href="waarnemingen.jsp">Delete</a>
</div>
<br> <br> <br>
<form action="waarnemingen.jsp" method="post">
<table>
<tr>
<th>Datum</th>
<th>Tijd</th>
<th>Plaats</th>
<th>Spotternaam</th>
<th>Vogelsoort</th>
</tr>
<%
List list = VoCo.Vogel.GetWaarnemingen();
int id = 0;
String box = null;
Iterator<String> it = list.iterator();
while (it.hasNext()) {
id = Integer.parseInt(it.next());
out.print("<tr>");
for (int i = 0; i < 5; i++) {
out.print("<td>");
out.print(it.next());
out.print("</td>");
}
out.print("<td>");
box = "<input name=r" + id + " type='checkbox'>";
out.print(box);
out.print("</td>");
out.print("</tr>");
}
%>
</table>
<br>
<input type="submit" value="Delete">
</form>
资料
蒂吉德
普拉茨
斯波特纳姆
沃格尔肖特
java文件:
public class Vogel {
static final String url = "jdbc:mysql://localhost:3306/turving";
public static void Insert(String datum, String tijd, String plaats, String spotternaam, String vogelsoort) {
try {
String insert = "INSERT INTO turving(datum, tijd, plaats, spotternaam, vogelsoort)" + "VALUES (?, ?, ?, ?, ?)";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "");
PreparedStatement ps = con.prepareStatement(insert);
ps.setString(1, datum);
ps.setString(2, tijd);
ps.setString(3, plaats);
ps.setString(4, spotternaam);
ps.setString(5, vogelsoort);
ps.executeUpdate();
con.close();
} catch (Exception ex) {
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static List GetWaarnemingen() {
List<String> list = new ArrayList<String>();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "");
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM turving");
while(result.next())
{
list.add(result.getString("id"));
list.add(result.getString("datum"));
list.add(result.getString("tijd"));
list.add(result.getString("plaats"));
list.add(result.getString("spotternaam"));
list.add(result.getString("vogelsoort"));
}
con.close();
} catch (Exception ex) {
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
public static void Delete(String id) {
try {
String delete = "DELETE from turving WHERE id = ?";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "");
PreparedStatement ps = con.prepareStatement(delete);
ps.setString(1, id);
ps.executeUpdate();
con.close();
} catch (Exception ex) {
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public-class-Vogel{
静态最终字符串url=“jdbc:mysql://localhost:3306/turving";
公共静态空白插入(字符串基准、字符串tijd、字符串plaats、字符串spotternaam、字符串vogelsoort){
试一试{
字符串insert=“插入旋转(基准面、tijd、plaats、spotternaam、vogelsoort)”+“值(?,,?,?,?)”;
Class.forName(“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection(url,“根目录”,“根目录”);
编制的报表ps=合同编制报表(插入);
ps.setString(1,基准);
ps.setString(2,tijd);
ps.setString(3,plaats);
ps.setString(4,spotternaam);
ps.setString(5名,vogelsoort);
ps.executeUpdate();
con.close();
}捕获(例外情况除外){
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE,null,ex);
}
}
公共静态列表GetWaarnemingen(){
列表=新的ArrayList();
试一试{
Class.forName(“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection(url,“根目录”,“根目录”);
语句stmt=con.createStatement();
ResultSet result=stmt.executeQuery(“从turving中选择*);
while(result.next())
{
添加(result.getString(“id”);
添加(result.getString(“数据”);
添加(result.getString(“tijd”);
list.add(result.getString(“plaats”);
添加(result.getString(“spotternaam”);
添加(result.getString(“vogelsoort”);
}
con.close();
}捕获(例外情况除外){
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE,null,ex);
}
退货清单;
}
公共静态无效删除(字符串id){
试一试{
String delete=“从turving中删除,其中id=?”;
Class.forName(“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection(url,“根目录”,“根目录”);
PreparedStatement ps=con.prepareStatement(删除);
ps.setString(1,id);
ps.executeUpdate();
con.close();
}捕获(例外情况除外){
Logger.getLogger(Vogel.class.getName()).log(Level.SEVERE,null,ex);
}
}
}
问题在于:
Iterator<String> it = list.iterator();
while (it.hasNext()) {
id = Integer.parseInt(it.next());
out.print("<tr>");
for (int i = 0; i < 5; i++) {
out.print("<td>");
out.print(it.next());
out.print("</td>");
}
您应该发布异常的stacktrace
Iterator<String> it = list.iterator();
while (it.hasNext()) {
String item = (String)it.next();
id = Integer.parseInt(item);
out.print("<tr>");
for (int i = 0; i < 5; i++) {
out.print("<td>");
out.print(item);
out.print("</td>");
}