【发布时间】:2014-12-10 19:05:33
【问题描述】:
我在使用 netbeans 中的 jsp 页面在 mysql 中查看我的数据库中的数据时遇到问题。 这是我在 jsp 页面中的代码:
<%@page import="javax.swing.JOptionPane"%>
<%@page import="java.sql.DatabaseMetaData"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.ArrayList" import="gettingItem.Item"%>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2>Home Page</h2>
<form name="myform" onsubmit="return OnSubmitForm();" method="get">
<select name="select" size="12" style = "width: 150px">
<%
String url = "jdbc:mysql://localhost:3306/itemsdb ";
String user = "admin";
String password = "admin";
String Line;
Connection Con = null;
Statement Stmt = null;
ResultSet RS = null;
try
{
Class.forName("com.mysql.jdbc.driver");
Con = DriverManager.getConnection(url, user, password);
Stmt = Con.createStatement();
Stmt.executeQuery("SELECT ItemName FROM items");
RS = Stmt.getResultSet();
while(RS.next()){%>
<Option value="<%=RS.getString("ItemName")%>">
<%=RS.getString("ItemName")%>
</Option>
</select>
<input type="submit" value="Remove" onclick="document.pressed = this.value">
<input type="submit" value="Display" onclick="document.pressed = this.value">
</form>
<form action="Add_Item.jsp" method ="get" >
<input type="submit" value="Add">
</form>
<%
}
RS.close();
Stmt.close();
Con.close();
}
catch (Exception cnfe){
System.err.println("Exception: "+cnfe);
}
%>
</body>
</html>
我想在 jsp 页面的下拉列表中查看数据,但它似乎不起作用,我不知道我的代码有什么问题?
【问题讨论】: