0

While developing java apps that connects to database, it seems like we have two options:

  • Use the standard java.sql classes
  • Use the vendor specific classes (like we have com.mysql.jdbc.Connection and we also have java.sql.Connection).

Which one is the recommended to use? Say I am currently using mysql. But in the future I might switch to oracle. Is there any performance bonus for using the vendor specific implementation?

1
  • With JDBC you always 'use' the vendor implementation, because JDBC is only a set of interfaces. That said: in general only use the interfaces defined in java.sql and javax.sql for best portability. Commented Jan 4, 2013 at 9:12

2 Answers 2

2

In most cases, you won't notice a performance difference.

The java.sql package represents a most common denominator between different databases, while the vendor-specific packages also expose some features which are exclusive to the database backend. But when you want to keep the option open to switch the database backend later, you should avoid these anyway, because it is possible that the new database got no equivalent functionality and you need to solve the problem in a completely different way, which could in the end require some large-scale refactoring of your entire application.

tl;dr: When you want to keep the option open to switch to Oracle or any other SQL database, use java.sql.

Or even better: use an object-relational mapping framework like Hibernate to do the database abstraction for you. They need a while to get used to, but afterwards you will be able to implement database functionality with a lot less man-hours and switching the database backend will be a one-line change in a configuration file.

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

Comments

2

Never go for vendor specific code, always use standard api(JDBC) and later on it will be easy to maintain and also easily portable across databases. Performance advantage of vendor specific code is negligible, you can better do with optimized queries, indexes, cacheing etc.

1 Comment

I agree. I've been on projects where team assumes that only database x will be used. Later, another database y is added and developers must remove all database x code or write another interface for database y.

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.