錯誤如下:
com.microsoft.sqlserver.jdbc.SQLServerException: “null”附近有語法錯誤。
代碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=bank";
String userName = "team";
String userPwd = "123456";
try {
Class.forName(driverName);
Connection dbConn = DriverManager.getConnection(dbURL, userName,
userPwd);
String s = request.getParameter("IDNum");
session.setAttribute("IDNum",s);
String IDNum = request.getParameter("IDNum");
String UserPassword = request.getParameter("UserPassword");
String a = request.getParameter("UserName");
session.setAttribute("UserName",a);
String UserName = request.getParameter("UserName");
//byte b[] = UserName.getBytes("UTF-8");
//UserName = new String(b); //防止出現亂碼
Statement stmt = dbConn.createStatement();
String sql = "select * from hello where IDNum'" + s
+ "' and UserPassword='" + UserPassword
+ "'and UserName='" + a + "'";
//RS.execute();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
out.println("歡迎您回來");
//reSsponse.sendRedirect("Business.jsp");
} else {
out.println("對不起您的用戶ID或者密碼錯誤");
%> 返回首頁<%
}
}
catch (Exception e) {
e.printStackTrace();
}
%>
初哥新手盼大神回復解答,盡快。謝謝!
把你的sql語句String sql 打印出來看看,這個有語法錯誤。你可以放到數據庫中執行試試