代码如下
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e)
{ e.printStackTrace();
}
try{String uri="jdbc:sqlserver://localhost:1433;DatabaseName=zxgw";
String user="sa";
String password="123456";
con=DriverManager.getConnection(uri, user, password);
int flag=0;
response.sendRedirect("dengluye.jsp");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM user");
String ui,upw;
ui=rs.getString(1);
upw=rs.getString(3);
String user_password1=new String(request.getParameter("user_password1").getBytes("ISO-8859-1"), "UTF-8");
String user_id1=new String(request.getParameter("user_id1").getBytes("ISO-8859-1"), "UTF-8");
if (user_id1.equals("")) {
String msg = "账号不能为空!";
int type = JOptionPane.YES_NO_OPTION;
String title = "信息提示";
JOptionPane.showMessageDialog(null, msg, title, type);
response.sendRedirect("dengluye.jsp");
}
if (user_password1.equals("")) {
String msg = "密码不能为空!";
int type = JOptionPane.YES_NO_OPTION;
String title = "信息提示";
JOptionPane.showMessageDialog(null, msg, title, type);
response.sendRedirect("dengluye.jsp");
}
if (user_id1.equals("ui")&&user_password1.equals("upw"))
{
flag=1;
response.sendRedirect("shouye.jsp");
}
else
{
response.sendRedirect("dengluye.jsp");
}
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e)
{ e.printStackTrace();
}
try{String uri="jdbc:sqlserver://localhost:1433;DatabaseName=zxgw";
String user="sa";
String password="123456";
con=DriverManager.getConnection(uri, user, password);
int flag=0;
response.sendRedirect("dengluye.jsp");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM user");
String ui,upw;
ui=rs.getString(1);
upw=rs.getString(3);
String user_password1=new String(request.getParameter("user_password1").getBytes("ISO-8859-1"), "UTF-8");
String user_id1=new String(request.getParameter("user_id1").getBytes("ISO-8859-1"), "UTF-8");
if (user_id1.equals("")) {
String msg = "账号不能为空!";
int type = JOptionPane.YES_NO_OPTION;
String title = "信息提示";
JOptionPane.showMessageDialog(null, msg, title, type);
response.sendRedirect("dengluye.jsp");
}
if (user_password1.equals("")) {
String msg = "密码不能为空!";
int type = JOptionPane.YES_NO_OPTION;
String title = "信息提示";
JOptionPane.showMessageDialog(null, msg, title, type);
response.sendRedirect("dengluye.jsp");
}
if (user_id1.equals("ui")&&user_password1.equals("upw"))
{
flag=1;
response.sendRedirect("shouye.jsp");
}
else
{
response.sendRedirect("dengluye.jsp");
}
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
而且正确的sqlserver jdbc 连接url应该是这样的:jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=zxgw你的是这样的
jdbc:sqlserver://localhost:1433;DatabaseName=zxgw
sqlserver的服务是否启动了
不行就是驱动jar包的问题了