本人编写个servlet的小程序《登陆界面的》,然后连接seqserver2000数据库,在数据库验证姓名和密码。。不过出现了上面的错误,不知怎么回事! 在网上搜索有的答案是:SqlServer2000的数据库没有打补丁,不过我打了SP4的补丁后依然不行,请各位前辈给点“良方”。小弟实在被搞得头大。。
本人编写个servlet的小程序《登陆界面的》,然后连接seqserver2000数据库,在数据库验证姓名和密码。。不过出现了上面的错误,不知怎么回事! 在网上搜索有的答案是:SqlServer2000的数据库没有打补丁,不过我打了SP4的补丁后依然不行,请各位前辈给点“良方”。小弟实在被搞得头大。。
依然是:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis
hing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Sou
rce)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown S
ource)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at loginpage.LoginCl.doGet(LoginCl.java:23)
at loginpage.LoginCl.doPost(LoginCl.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:45
4)
at java.lang.Thread.run(Unknown Source)
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;public class LoginCl extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res){
//业务逻辑
Connection ct=null;
Statement sm=null;
ResultSet rs=null;
try{
//用session对象来传值
//接受用户名和密码
String u=req.getParameter("Username");
String p=req.getParameter("Password");
//=====================连接数据库===========================
//连接数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//得到连接
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=LoginPage","sa","sa");
//创建Statement
sm=ct.createStatement();
rs=sm.executeQuery("select top 1 * from users where username='"+u+"' and passwd='"+p+"'");
if(rs.next()){
//得到session
HttpSession hs =req.getSession(true);
//修改session的存在时间
//hs.setMaxInactiveInter(30);
//hs.setAttribute("pass","ok");
//跳转
res.sendRedirect("Wel?uname="+u+"&upassword="+p);
//res.sendRedirect("Wel");
}
else{
res.sendRedirect("Login");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
}
if(sm!=null){
sm.close();
}
if(ct!=null){
ct.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
} public void doPost(HttpServletRequest req,HttpServletResponse res){
this.doGet(req,res);
}}
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;public class LoginCl extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res){
//业务逻辑
Connection ct=null;
Statement sm=null;
ResultSet rs=null;
try{
//用session对象来传值
//接受用户名和密码
String u=req.getParameter("Username");
String p=req.getParameter("Password");
//=====================连接数据库===========================
//连接数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//得到连接
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;
DatabaseName=LoginPage","sa","sa");
//创建Statement
sm=ct.createStatement();
rs=sm.executeQuery("select top 1 * from users where username='"+u+"'
and passwd='"+p+"'");
if(rs.next()){
//得到session
HttpSession hs =req.getSession(true);
//修改session的存在时间
//hs.setMaxInactiveInter(30);
//hs.setAttribute("pass","ok");
//跳转
res.sendRedirect("Wel?uname="+u+"&upassword="+p);
//res.sendRedirect("Wel");
}
else{
res.sendRedirect("Login");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
}
if(sm!=null){
sm.close();
}
if(ct!=null){
ct.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
} public void doPost(HttpServletRequest req,HttpServletResponse res){
this.doGet(req,res);
}}
2,数据库的tcp/ip协议启动了没有
3,jar包导入了没有