我制作了一个注册表 reg1 并从 HTML 文件中存储了每个注册用户的值。现在我在 HTML 中创建了一个登录页面,用户可以在其中提供他们的用户名并查看他们输入的数据。我已经创建了一个用户“bbb”并且只想显示他的用户名。所以我制作了如下的一般 java 代码:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Check extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String username=request.getParameter("username");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:XE";
Connection con=DriverManager.getConnection(url,"system","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select uname from reg1");
while(rs.next())
{
String name=rs.getString("uname");
if(name==username)
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.println("Your User name is:"+username);
// System.out.println(""+name);
}
con.commit();
}
stmt.close();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
它给出了类似的错误java.sql.SQLException: Closed Statement: next
表格如下:
FNAME LNAME ADDR MAIL OCCU UNAME PASSWD aaa aaa aaaa aaa aaaa bbb cccc bkgkb jjv jhvjmh jjkg jvjv jvjvh bjbmb
请帮我解决这个问题!!