17

What is the difference between javax.sql and java.sql I understand that javax.sql is for JavaEE. or am I wrong.

I am struggling with understanding this difference. And their usage scenarios.

2

4 Answers 4

27

What is the difference between javax.sql and java.sql I understand that javax.sql is for JavaEE.

It used to be that javax.sql was for JDBC extensions that were in Java EE and not Java SE, but this changed as of JDBC 3.

Now both packages are part of JDBC in Java SE, and the fact that there are two packages is now just a historical anomaly. The two packages continue to exist because removing one would cause backwards compatibility problems.


And their usage scenarios.

You basically use whichever package provides the part of the JDBC API that you need. Or more likely, you use both of them. Relevant scenarios can be deduced from the JDBC documentation and the javadocs.

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

Comments

2

Java.sql

Provides the API for accessing and processing data stored in a data source (usually a relational database) using the JavaTM programming language.

. This API includes a framework whereby different drivers can be installed dynamically to access different data sources. Although the JDBCTM API is mainly geared to passing SQL statements to a database, it provides for reading and writing data from any data source with a tabular format. The reader/writer facility, available through the javax.sql.RowSet group of interfaces, can be customized to use and update data from a spread sheet, flat file, or any other tabular data source.

Javax.sql

Provides the API for server side data source access and processing from the JavaTM programming language. This package supplements the java.sql package and, as of the version 1.4 release, is included in the Java Platform, Standard Edition (Java SETM). It remains an essential part of the Java Platform, Enterprise Edition (Java EETM).

4 Comments

Also historically, the classes in javax.sql were defined in an optional extension to JDBC 2, but in JDBC 3 they became part of the normal JDBC standard.
Those two seem similar. So what is the difference? One is for accessing data in a data source, and the other is for...accessing data in a data source?? WTF?
@Arkadiy In my opinion the essence is included in the answer. It could be better, but still it has some value.
The answer simply quotes links, without adding anything to explain the difference or highlight it. In general, this form of answer could be satisfactory. But in context of this question it's not. That being said, the question itself should likely be closed as opinion-based.
-1

java.sql.* --> This package is used for the basic JDBC connections.

javax.sql.* --> This package provides advance JDBC features such as connection pooling, distributed transaction, disconnected row sets

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-2

java.sql Interface Connection public interface Connection extends WrapperWrapper A connection (session) with a specific database. SQL statements are executed and results are returned within the context of a connection. A Connection object's database is able to provide information describing its tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, and so on. This information is obtained with the getMetaData method.

Connection property inspector getCatalog StringString getCatalog() throws SQLExceptionSQLException Retrieves this Connection object's current catalog name. Returns: the current catalog name or null if there is none Throws: SQLExceptionSQLException - if a database access error occurs or this method is called on a closed connection

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This is not apropos to the Question.

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.