1. Registering a Driver -statically load driver Class.forName(“foo.bar.MyDriver”);
Connection c = DriverManager.getConnection(...);
-or use the jdbc.drivers system property2. JDBC URLs -jdbc:subprotocol:source each driver has its own subprotocol and each subprotocol has its own syntax
3. DriverManager Connects to given JDBC URL with given user name and password
Throws java.sql.SQLException
returns a Connection object
1. StatementA Statement object is used for executing a static SQL statement and obtaining the results produced by it.
Statement MethodsResultSet executeQuery(String) Execute a SQL statement that returns a single ResultSet.
int executeUpdate(String) Execute a SQL INSERT, UPDATE or DELETE statement. Returns the number of rows changed.
boolean execute(String) Execute a SQL statement that may return multiple results.
2. The PreparedStatement Interface• The prepareStatement() method of Connection interface returns a PreparedStatement object
• Useful for frequently executed SQL statements
• An SQL statement is pre-compiled and gets executed more efficiently than a plain statement
For example: the statement “INSERT INTO Table1 VALUES (?, ?)” can be used to add multiple records, with a different values each time. Where ‘?’ acts as a placeholder
3. The CallableStatement Interface• A CallableStatement object is created by calling the prepareCall() method on a Connection object
• The object provides a way to call stored procedures in a standard way for all DBMS
• CallableStatement inherits Statement methods, which deal with SQL statements in general, and it also inherits PreparedStatement methods, which deal with IN parameters
• All methods defined in the CallableStatement deal with OUT parameters or the output aspect of INOUT parameters
• Syntax for a stored procedure without parameters is:
{call procedure_name}• Syntax for procedure call with two parameters:
{call procedure_name[(?, ?)] }