Introduction To JDBC
Introduction To JDBC
Introduction To JDBC
Steps
• Load the driver
• Define the connection URL & Establish the connection
• Create a Statement object
• Execute a query using the Statement
• Process the result
• Close the connection
Statement interface defines methods that are used to interact with database via the execution of
SQL statements. The Statement class has three methods for executing statements:
executeQuery(), executeUpdate(), and execute(). For a SELECT statement, the method to use is
executeQuery . For statements that create or modify tables, the method to use is executeUpdate.
Note: Statements that create a table, alter a table, or drop a table are all examples of DDL
statements and are executed with the method executeUpdate. execute() executes an SQL
statement that is written as String object.
ResultSet provides access to a table of data generated by executing a Statement. The table rows
are retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data. The
next() method is used to successively step through the rows of the tabular results.
ResultSetMetaData Interface holds information on the types and properties of the columns in a
ResultSet. It is constructed from the Connection object.