为啥我的jsp这么简单一页面都连接不上数据库?!第47行:Connection conn=DriverManager.getConnection("j
我SQLserver2005的TCP/IP开了,连接数据库包也引了,代码如下<%@pagelanguage="java"import="java.util.*,java....
我SQL server2005的TCP/IP开了,连接数据库包也引了,代码如下
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1 align="center">用户管理</h1>
<hr color="red"/>
<center>
<form name="form1" method="post" action="Login.jsp">
用户名:<input type="text" name="user"/>
<br/><br/>
密 码:<input type="password" name="password"/>
<br>
<input type="submit" value="提交">
<input type="reset" value="重置"/>
</form></center>
<hr color="red"/>
<%
String user,password;
user=request.getParameter("user");
password=request.getParameter("password");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databaseName=usertest","sa","123321");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select password from usertable where username='"+user+"'");
if(rs.next())
{
if(rs.getString(1).equals(password))
{
// request.getSession().setAttribute("userName",username);
response.sendRedirect("Welcome.jsp");
}
else
{
response.sendRedirect("Login.jsp");
}
}
else
{
response.sendRedirect("Login.jsp");
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(conn!=null)
conn.close();
%>
</body>
</html>
这是报错:
org.apache.jasper.JasperException: An exception occurred processing JSP page /Login.jsp at line 47
javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.BindException: Address already in use: connect
我的数据库是Sqlserver 2005!! 展开
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1 align="center">用户管理</h1>
<hr color="red"/>
<center>
<form name="form1" method="post" action="Login.jsp">
用户名:<input type="text" name="user"/>
<br/><br/>
密 码:<input type="password" name="password"/>
<br>
<input type="submit" value="提交">
<input type="reset" value="重置"/>
</form></center>
<hr color="red"/>
<%
String user,password;
user=request.getParameter("user");
password=request.getParameter("password");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databaseName=usertest","sa","123321");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select password from usertable where username='"+user+"'");
if(rs.next())
{
if(rs.getString(1).equals(password))
{
// request.getSession().setAttribute("userName",username);
response.sendRedirect("Welcome.jsp");
}
else
{
response.sendRedirect("Login.jsp");
}
}
else
{
response.sendRedirect("Login.jsp");
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(conn!=null)
conn.close();
%>
</body>
</html>
这是报错:
org.apache.jasper.JasperException: An exception occurred processing JSP page /Login.jsp at line 47
javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.BindException: Address already in use: connect
我的数据库是Sqlserver 2005!! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询