当前位置:编程学习 > JSP >>

JSP、SQL Server环境下编码关于rs的问题,怎么也看不明白

<%@ page language="java" import="java.util.*,java.sql.*,com.dao.*,com.en.*" pageEncoding="utf-8"%> <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Student"; String uid = "sa"; String pwd = "123456"; Connection conn = DriverManager.getConnection(url,uid,pwd); PreparedStatement pstmt; String name = request.getParameter("Name"); String pd = request.getParameter("Password"); String sqlTemp = "select * from Stu where name=" + name; pstmt = conn.prepareStatement(sqlTemp); ResultSet rs=pstmt.executeQuery(sqlTemp); //这两句 if(rs.next()==true)out.print("<script type='text/javascript'>alert('用户名已存在');window.location='home.jsp'</script>"); // String sql = "insert into Stu(name,password) values (?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1,name); pstmt.setString(2,pd); pstmt.execute(); conn.commit(); pstmt.close(); conn.close(); out.print("<script type='text/javascript'>alert('添加成功');window.location='home.jsp'</script>"); %> 不加标识的两句运行没有什么问题,一加上就不对了(想做一个判断),没有语病啊,为什么,本人初学,请各位指教一下,万谢!数据库Student中Stu表有id,name,password三列,id主键自动增 错误提示:org.apache.jasper.JasperException: An exception occurred processing JSP page /add.jsp at line 17(标识的第一行)
补充:String sqlTemp = "select * from Stu where name='" + name+"'";
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlTemp);
if (rs.next()) {out.print("<script type='text/javascript'>alert('名字已存在');window.location='userhome.jsp'</script>");return;}
这样好了,谢谢好心的人
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,