Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java - SQL Package:: Statement Interface

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

java.

sql package:

The java.sql package contains API for the following:

 Making a connection with a database


o DriverManager class –
o Driver interface -
o DriverPropertyInfo class - provides properties for a JDBC driver; not used by the general user
 Sending SQL statements to a database
o Statement - used to send basic SQL statements
o PreparedStatement - used to send prepared statements with parameters or basic SQL
statements (derived from Statement)
o CallableStatement - used to call database stored procedures (derived from
PreparedStatement)
o Connection interface - provides methods for creating statements and managing connections
and their properties
o Savepoint - provides savepoints in a transaction
 Retrieving and updating the results of a query
o ResultSet interface
 Metadata
o DatabaseMetaData interface -- provides information about the database
o ResultSetMetaData interface - provides information about the columns of a ResultSet object
o ParameterMetaData interface - provides information about the parameters to
PreparedStatement commands
 Exceptions
o SQLException -- thrown by most methods when there is a problem accessing data and by
some methods for other reasons
o SQLWarning -- thrown to indicate a warning
o DataTruncation -- thrown to indicate that data may have been truncated

Statement Interface

Statement objects are returned by the createStatement() method of Connection. The execute(),
executeUpdate(), and executeQuery() methods each take a Stringparameter that contains a SQL statement.
execute() returns a boolean value that indicates whether a ResultSet is available. The ResultSet can then be
retrieved with getResultSet(). executeUpdate() returns an update count and is used for INSERT, UPDATE,
DELETE, and other data manipulation statements. executeQuery() is used for SELECTstatements, so it
returns a ResultSet. There can be only one ResultSet active per query; the current ResultSet is closed when a
new SQL statement of any kind is executed

ResultSet Interface

ResultSet objects are usually generated by the executeQuery() methods of Statement and PreparedStatement.
ResultSet allows you to scroll navigate through the data once from beginning to end, iterating through rows
using the next() method and retrieving individual fields using the getXXX() methods. The getMetaData()
method returns a ResultSetMetaData object that describes the structure of the underlying data.

You might also like