• Post Reply Bookmark Topic Watch Topic
  • New Topic

Registring driver with the JDBC in Tomcat 8  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day, programmers, I have a little bit silly question but it can not leave me alone. So, I have to create connection to a db using jdbc, and in jdbc version 4.0 or higher loading driver is not necessary :

In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method Class.forName. This methods required an object of type java.sql.Driver. Each JDBC driver contains one or more classes that implements the interface java.sql.Driver. The drivers for Java DB are org.apache.derby.jdbc.EmbeddedDriver and org.apache.derby.jdbc.ClientDriver, and the one for MySQL Connector/J is com.mysql.jdbc.Driver. See the documentation of your DBMS driver to obtain the name of the class that implements the interface java.sql.Driver.

Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)

  This quote is from jdbc tutorial that I have found on Oracle website.
So, if I use this approach without registering driver it works fine with console-based app. When it comes to the Tomcat 8 , there are problems. I know that .jar file of the MySQL connector should be either in classpath or in %CATALINA_HOME%/lib directory of Tomcat 8.
The problem is that, without manually registering driver app doesn't work. If I don't manually register driver I have the following issue: 
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbName .
I have also checked .jar file and found Driver class and there are :

Why using console-based approach, I mean without servlet container, I don't need to manually register driver, but with the servlet container I must do it?
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Why should you try IntelliJ IDEA ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!