Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between java.sql and mysql.jdbc

I've only learned Java last quarter of 2010. I can say the knowledge I gained as of now are not enough and there's a lot of improvement. I still do studying while developing but most of my code is snippet from other current working application. I guess my way of studying the language affect the way I know it. Instead of learning the basic first, I jump up to advanced features that affect how I understand it. (I did advanced to fulfill my previous project tasks.)

I often connect to my MySql database using import java.sql.connection etc. I'm using Eclipse IDE then when I create an instance of Connection/PreparedStatement and I haven't imported the packages. Eclipse will show related Packages that's where mysql.jdbc.* I've encountered.

All though I did some research about it still its not too clear for me. The difference of those to packages.

  • Does it have pros and cons?
  • Does it have a big significance difference with performance and security?
  • Does it use in different way?
  • Is there more things to know?

I know someone here can enlighten me more about this.

like image 585
ace Avatar asked Apr 05 '11 08:04

ace


People also ask

What is the difference between JDBC and SQL?

JDBC requires separate get and/or set call statements for each bind variable and specifies the binding by position number. SQLJ provides strong typing of query outputs and return parameters and allows type-checking on calls. JDBC passes values to and from SQL without compile-time type checking.

Is JDBC same as MySQL?

In Java, we can connect to our database(MySQL) with JDBC(Java Database Connectivity) through the Java code. JDBC is one of the standard APIs for database connectivity, using it we can easily run our query, statement, and also fetch data from the database.

What is the difference between Java and JDBC?

JDBC is a Java API for connecting to various types of RDBMS. API stands for "application programming interface." JDBC is definitely one of these, and so is HBase.

Does JDBC use SQL?

JDBC is an adapter layer from Java to SQL: it gives Java developers a common interface for connecting to a database, issuing queries and commands, and managing responses.


2 Answers

To quote from the javadoc for com.mysql.jdbc.Connection:

This interface contains methods that are considered the "vendor extension" to the JDBC API for MySQL's implementation of java.sql.Connection.

So, that class at least builds on top of JDBC to add more features. But it's still JDBC at heart - you're using this class when you use pure JDBC, you just don't see it.

I would say that if you can build your app using only the standard JDBC interfaces, do so. If you absolutely need MySQL-specific API features, then use the MySQL interfaces. I work with Oracle mostly, and in all the years i've been doing it, i've never had to fall back to any Oracle-specific interfaces; there's a huge amount you can do with JDBC.

To address your points:

  • The pro is more features; the con is less standardisation
  • I would not expect any difference with performance and security, since the two packages use the same classes under the hood (AIUI)
  • The usage should not be fundamentally different; the MySQL package should add on to the JDBC package
  • There is more to know in the MySQL package, because you need to know about JDBC to use it anyway
like image 129
Tom Anderson Avatar answered Oct 08 '22 22:10

Tom Anderson


To put it simply: Java (J2SE/J2EE) provides java.sql.* as the standard way to connect to a database. The issue is that these classes do not know really know how to connect to each specific database in the model, they are oriented to the programmer.

To connecto to each database, you need to put in its Driver. The Oracle driver will know how to connect to the Oracle database, the mysql driver will know how to connect to MySQL. java.sql. will know how to use each Driver, so by just using it you do not need to know the internals of each Driver.

like image 42
SJuan76 Avatar answered Oct 08 '22 21:10

SJuan76