Assignment No 547
Assignment No 547
THEORY:
MYSQL-JDBC Connectivity:
JDBC Drivers:
When you develop JDBC applications, you need to use JDBC drivers to con-vert queries into
a form that a particular database can interpret.The JDBC driver also retrieves the result of SQL
statements and converts the result into equivalent JDBC API class objects that the Java
Application uses.
The JDBC API classes and interfaces are available in the java.sql and the javax.sql packages.
The classes and interfaces perform a number of tasks, such as establish and close a connection
With a database, send a request to a database, retrieve data from a database and update data in
database .The commonly used classes and interfaces in the JDBC API are:
1. DriverManager Class
2. Driver Interface
3. Connection Interface
4. Statement Interface
5. ResultSet Interface
6. SQLException Class
To query a database and display the result using java applications, you need to used
Following Steps:
1. Loading a Driver :
You can load the JDBC Driver using the following method call:
Class.forName("com.mysql.jdbc.Driver");
(b) Using the registerDriver() method :
You can create an instance of the Driver class to load a JDBC driver.The syntax to declare
an instance of the Driver class is :
Driver d=new <driver name>;
Once you have created the Driver object,call the registerDriver() method to register it with the
DriverManager.You can register JDBC driver using the following method call :
DriverManager.registerDriver(d);
2. Connecting to a Database :
The syntax for a JDBC URL that is passed as a parameter to the getConnection()
method is :
<protocol >:<subprotocol >:<subname>;
You need to create a statement object to send requests to and retrieve results from a
database. The connection object provides the createS-tatement() method to create a
statement object .
You can send SQL statements to a database using the statement ob-ject. The statement
interface contains the following methods to send static SQL statement to a database :
(a) ResultSet excuteQuery(String str) :
Excecute the SQL statement and returns a single object of the type,ResultSet.
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(<SQL statement>);
(b) int executeUpdate (String str) :
Executes the SQL statements and returns the number of data rows that are a
selected after processing the SQL statement.
Statement stmt = con.createStatement();
int count = stmt.executeUpdate(<SQL statement>);
(c) Boolean execute (String str ) :
Execute SQL statement and returns a boolean value. Statement stmt =
con.createSatement(); Stmt.execute(<SQL statement>);
Querying a Table :
You can retrieve data from a table using the SELECT statement. The
SELECT statement is excuted using the executeQuery() method and
returns the output in the form of a ResultSet object.
Join Operation :
Now,we have to List Branch O ces and properties that are in the
same city.This can be writen as -
The join operations that preserve those tuples that would be lost in a
join, by creating tuples in the result containing null values are called
as Outer Join operations.
The left outer join preserves tuples only in the relation named
before (to the left of) the left outer join operation.
Now,we have to List Branch O ces and properties that are in the
same city along with any unmatched branches.This can be
writen as -
The right outer join preserves tuples only in the relation named
after (to the right of) the right outer join operation.
Now,we have to List Branch O ces and properties that are in the
same city along with any unmatched property.This can be
writen as -