wtsang02
wtsang02

Reputation: 18863

com.mysql.jdbc.ResultSetMetaData; vs java.sql.ResultSetMetaData;

I am using tomcat7, java 1.6 to access a mysql db with com.mysql.jdbc.Driver. I was going to get metaData from a table like

java.sql.ResultSet set=getStuff();
ResultSetMetaData meta = set.getMetaData();

The problem is , set.getMetaData returns java.sql.ResultSetMetaData; but I am using mysql with jdbc, so shouldn't it be returning com.mysql.jdbc.ResultSetMetaData;? Did I import something wrong? If not when will com.mysql.jdbc.ResultSetMetaData; be used or whats the difference?

Upvotes: 1

Views: 1482

Answers (1)

benzonico
benzonico

Reputation: 10833

The role of the driver is actually to abstract the use of database specific code. So you just specify the driver and then interact with an api that is not database dependent.

If you have a closer look you will see that com.mysql.jdbc.ResultSetMetaData is an implementation of the interface java.sql.ResultSetMetaData.

And for sake of decoupling you are better off working with the interface (so you are not tied to a specific database in your code)

Upvotes: 3

Related Questions