日期:2014-05-18  浏览次数:20866 次

Servlet连接SQL Server2000 连接不上,请大家帮帮忙!,谢谢。!
OS:XP sp2
Tomcat 6.0


SQL sp4补丁已经加上,

下面是我的代码请大家看一下:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*; 

/**
 * The simplest possible servlet.
 *
 * @author Haix Hsu
 */

public class Hello extends HttpServlet {



  public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException
  {
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind";  
String userName = "sa";
String userPwd = "";
Connection dbConn;


  response.setContentType("text/html");
  PrintWriter out = response.getWriter();

  out.println("<html>");
  out.println("<head>");

String title = "Hello World";

out.println("<title>" + title + "</title>");
  out.println("</head>");
  out.println("<body bgcolor=\"white\">");
  out.println("<h1>" + title + "</h1>");

try
{
Class.forName(driverName);
out.println("<p>" + driverName + "</p>");
dbConn = DriverManager.getConnection(dbURL); 
out.println("Connection Successful!"); 

catch(Exception e) 

out.println("<p>Connection Failed</p>"); 
}  


  out.println("</body>");
  out.println("</html>");
  }
}






------解决方案--------------------
sql server三个包放到指定路径了吗??
------解决方案--------------------
注意SQL服务器打开了没有?