0
votes

I run a web application on tomcat 7. My Web application use connector mysql to connect db. It connect to mysql and query ok. But when I run it for 3 - 4 hours it occur error with get connection and the log I get in tomcat is

"java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/mydb?autoReconnectForPools=true&useUnicode=true&characterEncoding=utf-8 at java.sql.DriverManager.getConnection(DriverManager.java:596) at java.sql.DriverManager.getConnection(DriverManager.java:215)"

2
do Class.forName("com.mysql.jdbc.Driver"); before you start your connection - Ferrybig
Do you have the jar in your classpath? - soorapadman
Of Course I have use this comment.I have add in tomcat lib. note that it run ok the first after for along time it occur exception. I think may be tomcat leak memory and restrict register mysql driver. - user2504004

2 Answers

0
votes

This is probably a result of Tomcat service provider mechanism memory leaks prevention efforts. A workaround suggested is to register the driver manually in your controller:

@PostConstruct
public void init() {
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    } catch (ClassNotFoundException ex) {
        throw new RuntimeException(ex);
    }
}
-1
votes

You're missing the jar with the MySQL driver. If it's not under /WEB-INF/lib then drop it in /lib/ext