日期:2014-05-20  浏览次数:20867 次

myelipse课程设计,链接数据库不行啊
<body>
  <%
  //验证用户信息
  String u=request.getParameter("username");
  String p=request.getParameter("passwd");
   
  //到数据库中验证用户
  //1.加载驱动
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  //2.得到链接
  Connection ct=DriverManager.getConnection("jdbc:microsoft:sqlserver//127.0.0.1:1433;databaseName=spdb1","sa","");
  //3.创建statement
  Statement sm=ct.createStatement();
  //4.查询
  ResultSet rs=sm.executeQuery("select passwd form users where username='"+u+"'");
  //根据结果判断
  if(rs.next()){
  //用户存在
  if(rs.getString(1).equals(p)){
  //合法
  response.sendRedirect("wel.jsp?user="+u);
  }
  else{
  //密码错误
  response.sendRedirect("index.jsp");
  }
  }else{
  //用户名不存在
  response.sendRedirect("index.jsp");
  }
  %>
  </body>




在账号密码都正确的情况下,出现错误HTTP Status 500 

严重: Servlet.service() for servlet jsp threw exception
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver//127.0.0.1:1433;databaseName=spdb1
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.apache.jsp.loginCl_jsp._jspService(loginCl_jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:662)


我搞了一天都不知道什么回事,请求大家指点

------解决方案--------------------
看来数据库链接很容易出问题啊,今天我都回答两个了。楼主你看看项目目录中Referenced Libraries 下有sqljdbc.jar包吗(数据库为SQL server2005以下版本,其他的也是同样道理)?没有的话在Referenced Libraries上右键选择build path然后选择Confrgure Build Path 打开一个页面在上面选择Libraries,最后选择Add JARs添加jar包。有的话检查jar版本是否符合,再者同一个项目下不允许有两个sqljdbc.jar否则也会报这个错误