• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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?
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
global solutions you can do at home or in your backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!