-6

Which TYPE of driver it is? (Type 1,2,3,4) if i write -

Connection con = null;
Statement stmt = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/");
stmt =con.CreateStatement();
}
catch(Exception e)
{
e.printstacktrace();
}

And how to recognize various *TYPE of drivers if code snippet is written? Yes it's MySQL Database driver! But, I mean how to recognize the TYPE in JDBC? like we have- Type1:JDBC-ODBC bridge. Type2:Native-API/Partially Java Driver. Type3:Net-Protocol/ All- Java driver. Type4:Native-Protocol/All- Java driver.*

Jay Jain
  • 73
  • 1
  • 8
  • what do you mean by driver in this case? – John Woo Feb 01 '13 at 05:20
  • This code is absolutely baffling. Why on earth would you create an instance of a JDBC driver (a) using `Class.forName` (even IF you need reflection, never EVER use `Class.forName`), and then (b) discard the result! – Chris Eberle Feb 01 '13 at 05:20
  • @Chris: Actually I see tons of examples using it that way. I didn't even know it was bad. It's in a lot of tutorials. [Here it is for postgresql](http://jdbc.postgresql.org/documentation/91/load.html). But you're right about creating the instance, I don't see a reason to do that. – Daniel Kaplan Feb 01 '13 at 05:27
  • I mean WHAT IS THE TYPE? like we have - Type1:JDBC-ODBC bridge. Type2:Native-API/Partially Java Driver. Type3:Net-Protocol/ All- Java driver. Type4:Native-Protocol/All- Java driver. – Jay Jain Feb 01 '13 at 06:03
  • @Chris : then I expect downvotes for the answer given here http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql "the answer with 5 voteups" – Bhavik Shah Feb 01 '13 at 06:05
  • @BhavikShah just because a piece of code works and is copied around a few times doesn't make it good code. I see now that instantiating it does some kind of initialization work, but even so in that form it's ugly and unintuitive. – Chris Eberle Feb 01 '13 at 16:42
  • @Chris : Don't get me wrong. I am saying that answer needs some moderation if its not a good code that's it. I agree with you – Bhavik Shah Feb 01 '13 at 20:02

4 Answers4

1

According to the documentation, MySQL's Connector/J driver is a JDBC Type-4 Driver:

MySQL Connector/J is a JDBC Type 4 driver. Different versions are available that are compatible with the JDBC 3.0 and JDBC 4.0 specifications. The Type 4 designation means that the driver is a pure Java implementation of the MySQL protocol and does not rely on the MySQL client libraries.

You know that it's Connector/J because the reference manual also states that

The name of the class that implements java.sql.Driver in MySQL Connector/J is com.mysql.jdbc.Driver.

Edit: (in response to the edit of the question) The only way to "recognize" the driver type is to read the documentation that came with the driver.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

Check the manifest file inside the driver jar. It will have content like this :-

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_30-b03 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle Corporation
Implementation-Title: JDBC
Implementation-Version: 11.2.0.3.0
Repository-Id: JAVAVM_11.2.0.3.0_LINUX_110823
Specification-Vendor: Sun Microsystems Inc.
Specification-Title: JDBC
Specification-Version: 4.0
Main-Class: oracle.jdbc.OracleDriver
Anshuman
  • 11
  • 2
0

Well since the driver says "mysql" in it, it's the driver for MySQL. You can find out more about how to use this driver from this link: http://dev.mysql.com/doc/refman/5.1/en/connector-j.html

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • Yes, i know it's MySQL Database driver! i means WHAT IS THE TYPE IT IS ? like we have - Type1:JDBC-ODBC bridge. Type2:Native-API/Partially Java Driver. Type3:Net-Protocol/ All- Java driver. Type4:Native-Protocol/All- Java driver. – Jay Jain Feb 01 '13 at 06:08
0

This is an older looking piece of code, however I think the answer you're looking for is MySQL. It is a MySQL Database driver.

http://dev.mysql.com/downloads/connector/j/

Hope that helps!

jspacek
  • 1,895
  • 3
  • 13
  • 16
  • Yes, i know it's MySQL Database driver! i means WHAT IS THE TYPE IT IS ? like we have - Type1:JDBC-ODBC bridge. Type2:Native-API/Partially Java Driver. Type3:Net-Protocol/ All- Java driver. Type4:Native-Protocol/All- Java driver.* – Jay Jain Feb 01 '13 at 06:01