
In java.sql package majority are interfaces only, how instance will be created for these interfaces?

Hi, in jdbc we are using some jar files like for oracle ds we are using ojdbc14.jar. These jar files contain the classes which provides the implemtation to java.sql interfaces. For example the ojdbc14.jar file contain the class like OracleDatabaseMetaData class which provide the implemtation to java.sql.DatabaseMetaData interface. Hence
connection.getMetaData() contain the code to creat the object to OracleDatabaseMetaData.

In java.sql package, there are several interfaces. These interfaces have been used in connection database with the java code.
import java.sql.*;
public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.