[Solved] Why do we use * in the end of java.sql.* package [closed]


By doing import java.sql.* you import all classes from the package java.sql at once, so that you don’t have to import them one by one. It’s more convenient to write when you’re importing many classes from some package.

For example, instead of:

import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
// ...etc.

you can just write:

import java.sql.*;

Note that importing everything in a package can also have a disadvantage: you might be importing classes that you didn’t want. For example, the packages java.util and java.sql both contain a class named Date. If you do this:

import java.sql.*;
import java.util.*;

then, when you use Date in your source file, the compiler will complain because it doesn’t know if you mean java.sql.Date or java.util.Date.

1

solved Why do we use * in the end of java.sql.* package [closed]