ssh项目中对抛出java.sql.SQLException: No suitable driver异常的处理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Javanjg/article/details/51114345

弄了一下午的ssh项目(当然,是初学者,嘿嘿),发现了一个很棘手的问题,那就是在登录这一快总报java.sql.SQLException: No suitable drive异常。不过华了几个小时终于看出了其中的端倪,也是醉了。原来是因为在用myeclipse自动生成spring配置文件applicationContext.xml时,myeclipse没有把driverClassName这个属性给加进去,致使抛出找不到合适的驱动异常。


异常信息如下:

Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://localhost:3306/myssh'
java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:278)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81............................................

解决办法:

把属性driverClassName加进去就ok了。

<bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url"
            value="jdbc:mysql://localhost:3306/myssh">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="1195726908"></property>
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver">
        </property>

    </bean>


这个棘手的问题就这么呵呵的解决了。

阅读更多

java.sql.SQLException: No suitable driver问题~~~~~

06-18

我用的是MyEclipse+SQLServer2005+Tomcat6.0 rndriver都倒了 用的是sqljdbc1.2的 rn可还是出现这个问题 rnjava.sql.SQLException: No suitable driver rnat java.sql.DriverManager.getConnection(DriverManager.java:545) rnat java.sql.DriverManager.getConnection(DriverManager.java:171) rnat y2ssh.epai.xmal3.dao.jdbcimpl.BaseJdbcDao.openConn(BaseJdbcDao.java:23) rnat y2ssh.epai.xmal3.dao.jdbcimpl.UserDAOJdbcImpl.search(UserDAOJdbcImpl.java:42) rnat y2ssh.epai.xmal3.biz.impl.UserBizImpl.isExists(UserBizImpl.java:17) rnat y2ssh.epai.xmal3.web.action.UserAction.doAdd(UserAction.java:40) rnat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) rnat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) rnat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) rnat java.lang.reflect.Method.invoke(Method.java:585) rnat org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270) rnat org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187) rnat org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) rnat org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) rnat org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) rnat org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:710) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:803) rnat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) rnat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) rnat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) rnat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) rnat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) rnat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) rnat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) rnat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) rnat org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) rnat org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) rnat org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) rnat java.lang.Thread.run(Thread.java:595) rn2008-6-18 20:15:44 org.apache.catalina.core.StandardWrapperValve invoke rn严重: Servlet.service() for servlet action threw exception rnjava.lang.NullPointerException rnat y2ssh.epai.xmal3.dao.jdbcimpl.UserDAOJdbcImpl.search(UserDAOJdbcImpl.java:44) rnat y2ssh.epai.xmal3.biz.impl.UserBizImpl.isExists(UserBizImpl.java:17) rnat y2ssh.epai.xmal3.web.action.UserAction.doAdd(UserAction.java:40) rnat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) rnat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) rnat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) rnat java.lang.reflect.Method.invoke(Method.java:585) rnat org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270) rnat org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187) rnat org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) rnat org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) rnat org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) rnat org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:710) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:803) rnat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) rnat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) rnat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) rnat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) rnat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) rnat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) rnat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) rnat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) rnat org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) rnat org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) rnat org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) rnat java.lang.Thread.run(Thread.java:595) rn高手支招咋解决啊 就连我们老师也趴窝了 看网好多人问就是没有解决方法

java.sql.SQLException: No suitable driver

10-09

import java.sql.*;rnimport com.mysql.jdbc.ResultSet;rnimport com.mysql.jdbc.Statement;rnimport com.mysql.jdbc.Driver;rnrn/**rn *rn * @author Administratorrn */rnpublic class SelectDB rn rn /** Creates a new instance of SelectDB */rn public static void main(String[] args) rn tryrn rn Class.forName(" com.mysql.jdbc.Driver");rn rn catch (java.lang.ClassNotFoundException e)rn rn System.out.print("Class not found exception occur. Message is:");rn System.out.print(e.getMessage());rn rn tryrn rn Statement stmt;rn ResultSet rs;rn rn String url = "jdbc:mysql://localhost:3306/DWDM";rn rn String user = "root";rn String passwordofDB = "lm";rn Connection conn = null;rn rn tryrn rn conn = DriverManager.getConnection(url,user,passwordofDB);rn rn catch(Exception ex)rn rn ex.printStackTrace();rn rn rn stmt =(Statement) conn.createStatement();rn rs = (ResultSet) stmt.executeQuery("select* from user");rn rn while (rs.next())rn rn String id =rs.getString(1);rn String password = rs.getString(2);rn int access=rs.getInt(3);rn String introduction= rs.getString(4);rn rn System.out.println("id:"+id);rn System.out.println("password:"+password);rn System.out.println("access:"+access);rn System.out.println("introduction:"+introduction);rn rn rn rs.close();rn stmt.close();rn conn.close();rn rn catch(SQLException e)rn rn System.out.print("SQL Exception occur.Message is:");rn System.out.print(e.getMessage());rn rn rn rnrn我mysql的版本是4.1,驱动安装了mysql-connector-java 3.1.7.jar,并且在NetBeans中用数据库管理界面已经连接成功,说明驱动没有错,在类路径中已经.jar文件怎么还会报下面错呢,希望大牛们能指点,跪谢!rnjava.sql.SQLException: No suitable driverrnrn at java.sql.DriverManager.getConnection(DriverManager.java:532)rnrn at java.sql.DriverManager.getConnection(DriverManager.java:171)rnrn at SelectDB.main(SelectDB.java:44)rnrnjava.lang.NullPointerExceptionrnrn at SelectDB.main(SelectDB.java:51)rnrnException in thread "main" rnrnClass not found exception occur. Message is: com/mysql/jdbc/Driverrn

java.sql.SQLException: No suitable driver 错误

03-24

rnjava.sql.SQLException: No suitable driverrn at java.sql.DriverManager.getDriver(DriverManager.java:243)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)rn at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)rn at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)rn at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)rn at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)rn at org.hibernate.loader.Loader.doQuery(Loader.java:390)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)rn at org.hibernate.loader.Loader.doList(Loader.java:1593)rn at org.hibernate.loader.Loader.list(Loader.java:1577)rn at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322)rn at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)rn at org.springframework.orm.hibernate3.HibernateTemplate$38.doInHibernate(HibernateTemplate.java:1012)rn at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)rn at org.springframework.orm.hibernate3.HibernateTemplate.findByExample(HibernateTemplate.java:1001)rn at org.springframework.orm.hibernate3.HibernateTemplate.findByExample(HibernateTemplate.java:994)rn at dao.UserDAO.findByExample(UserDAO.java:67)rn at service.Service.isValid(Service.java:16)rn at web.action.LoginAction.execute(LoginAction.java:54)rn at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)rn at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)rn at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173)rn at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)rn at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274)rn at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)rn at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:520)rn at com.caucho.util.ThreadPool.run(ThreadPool.java:442)rn at java.lang.Thread.run(Thread.java:595)rnrn用myeclipse做的SSH,报的这个错误rnUserDAO.java代码是直接生成的rnapplicationContext.xmlrn[code=XML]rnrnrnrnrnrn rn rn com.mysql.jdbc.Driverrn rn rn rn jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBKrn rn rn rn rootrn rn rn eetrustrn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn rn rn rn rn vo/User.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn [/code]rn刚学spring不知道那里错了,大家帮忙看看rn

没有更多推荐了,返回首页