1

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?

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.