Академический Документы
Профессиональный Документы
Культура Документы
UNIT-2
Java Database Programming
The JDBC API consists of classes and interfaces for establishing connections with databases,
sending SQL statements to databases, processing the results of the SQL statements, and
obtaining database metadata.
SQL
Driver
Establish
Link to DB Result
(tuples)
Database
Lovely Professional University, Punjab
Loading drivers
An appropriate driver must be loaded using the statement shown below
before connecting to a database.
Class.forName("JDBCDriverClass");
Connection =
DriverManager.getConnection("jdbc:mysql://localhost/javabook", “root",
"tiger");
Lovely Professional University, Punjab
Commonly used methods of Connection interface
Executing statements
statement.executeUpdate ("create table Temp (col1 char(5), col2 char(5))");
A Statement will always proceed through the four steps above for each SQL query sent to the
database. A Prepared Statement pre-executes steps (1) - (3) in the execution process above.
Thus, when creating a Prepared Statement some pre-optimization is performed immediately.
The effect is to lessen the load on the database engine at execution time.