首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

为什么会有java.sql.SQLException: No suitable driver的错误?

2014-01-26 
java.sql.SQLException: No suitable driverat java.sql.DriverManager.getConnection(DriverManager.java:

java.sql.SQLException: No suitable driver
  at java.sql.DriverManager.getConnection(DriverManager.java:545)
  at java.sql.DriverManager.getConnection(DriverManager.java:171)
  at app.bean.DataBaseConnection.getConnection(DataBaseConnection.java:16)
  at app.action.RegisterBean.<init>(RegisterBean.java:14)
  at app.action.RegisterAction.execute(RegisterAction.java:25)
  at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
  at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
  at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
  at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
  at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
  at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
  at java.lang.Thread.run(Thread.java:595)
 
  我已经把3个sqlserver的驱动拷到/web-inf/lib下,在jre/lib/ext下也拷进去了,并且在java build path-library-add external jars也包含进这3个jar了。为什么还报错?开发工具是eclipse
 
  DataBaseConnection.java
  import java.sql.Connection;
  import java.sql.DriverManager;
 
  public class DataBaseConnection {
  public static Connection getConnection(){
  Connection con=null;
  String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
  String SERVANDDB="jdbc:microsoft.sqlserver://127.0.0.1:1433;DatabaseName=jspdev";
  String USER="bn";
  String PWD="bn";
 
  try{
  Class.forName(CLASSFORNAME);
  con=DriverManager.getConnection(SERVANDDB,USER,PWD);
  System.out.println("connect success");
  }catch(Exception e){
  System.out.println("connecting failded");
  e.printStackTrace();
  }
  return con;
  }
 
  }

------解决方法--------------------------------------------------------
SERVANDDB="jdbc:microsoft.sqlserver://127.0.0.1:1433;DatabaseName=jspdev";
  应该是冒号不是.
 
  SERVANDDB="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev";
 
 
 
------解决方法--------------------------------------------------------
好好检查一下,最好debug,看哪步出了问题;
 
  像这样因为一个符号而发问,应该多思考哦

        

热点排行