JDBC FAQs
JDBC FAQs
Class.forName (sun.jdbc.odbc.JdbcOdbcDriver);
We should establish the connection to the database from the JDBC application, so that we
can communicate with database from the java application through this established
connection.
Syntax:
We should create one Statement interface object in the JDBC application, so that we can
send the required sql commands to the database from the JDBC application through the
vendor implemented methods available in Statement interface object.
Syntax:
Statement stmt = con.createStament();
The following are the two vendor implemented methods of Statement interface object can
used to send the required sql commands as string values to the database from the JDBC
application.
1.
executeUpdate(String s);
2.
executeQuery(String s);
executeUpdate:
The executeUpdate method of Statement interface object can be used to send the sql
commands such as Create, Insert, Update, Delete as the string value to the database from
the JDBC application.
The return type of this method is integer.
executeQuery:
The executeQuery method of Statement interface object can be used to send the Select sql
command to the database as a string value to get the data from any database table into
JDBC application.
The return type of this method is ResultSet.
Resultset :
The ResultSet represents set of rows retrieved due to query execution.
PreparedStatement :
A prepared statement is an SQL statement that is precompiled by the database. Through
precompilation, prepared statements improve the performance of SQL commands that are
executed multiple times (given that the database supports prepared statements). Once
compiled, prepared statements can be customized prior to each execution by altering
predefined SQL parameters.
CallableStatement :
Callable statements are used from JDBC application to invoke stored procedures and
functions.
ResultSetMetaData :
Data about data is called metadata.
This ResultSetMetaData interface is used in the JDBC application to get the details about
the ResultSet object. Such as no.of columns available in ResultSet, Column names,
Column types e.t.c.
DatabasetMetaData:
This DatabaseMetaData interface is used in the JDBC application to get the details about
the database, where the connection is established such as database name , database
version, JDBC driver classes version, list of all keywords supported by the database e.t.c.