Reputation: 153
I need to establish a connection to a DB (f.i. MySQL, DB2) but I don't have the possibility to include JARs.
So I thought ODBC is able to connect to DBs without a DB specific driver. But every code example I found uses native drivers.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Throws an access denied exception by Java Security and if else I do get java.sql.SQLException: No suitable driver found for..
I just want to submit some simple SQL Queries - I do not get why I need native drivers.
Am I on the wrong page?
Upvotes: 2
Views: 2541
Reputation:
The JDBC/ODBC bridge also needs a driver - it needs an installed ODBC driver which is also a "native" driver.
Usually installing an ODBC driver is more hassle than just including a .jar file (JDBC driver) with your application.
With the ODBC driver you actually run in more problems. The ODBC driver must match the "bitness" of the JVM used. So if your application is running with a 32bit JVM you have to have 32bit ODBC drivers installed. If your appliction runs on a 64bit JVM you need the 64bit ODBC driver.
With a JDBC (type 4 - but all DBMS have a type 4 driver nowadays) you just include that single jar file, not installation, no worries about 32/64 bit.
On top of all that: the JDBC/ODBC bridge is buggy and probably slower than using a real JDBC driver.
Upvotes: 2
Reputation: 4393
1) Right click on your project. 2) @ Compile tab, add Library. 3) Look for Driver
Upvotes: 0
Reputation: 15844
You need those drivers. Even if you used Java's SQL API, you would still need an implementation for the particular database (Oracle, MySQL,...). So you have to add the driver to your project
Upvotes: 1