Code
Code
Create different types that include attributes and methods. Define tables for
these types by adding at least 10 tuples. Demonstrate insert, update and
delete operations on these tables. Fire at least 5 queries on them.
addr AddrType,
branches BranchType);
we may create a type that is a nested table of objects of this type by:
Now one can define a relation of publishers that will nest their branches
inside:
[email protected]
PRACTICALS 3
(3) Insertion of tuples into books can be done using following format:
BOOKS(title, year, published_by: ref<PUBLISHERS>, authors:
list of ref AUTHOR )
QUERIES:
(3) List all of the authors that have the same address as their publisher:
Publishers authors
addr addr, name(?)
(4) List all of the authors that have the same pincode as their
publisher:
SQL> select *
from books b
where 1 < ( select count(*)
from table(b.authors));
(6) List the title of the book that has the most authors:
[email protected]
PRACTICALS 4
group by title
having count(*)=
(select max(count(*))
from books b, table(b.authors)
group by title);
P
Prraaccttiiccaall :: M
Muullttiim
meed
diiaa d
daattaab
baasseess
import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
class TestImage implements ActionListener
{
JFrame f;
JLabel l;
JLabel l2;
JLabel l3;
JTextField tf1;
JTextField tf2;
JButton b1;
TestImage()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =
DriverManager.getConnection("jdbc:odbc:Ora","scott","tiger");
Statement s = c.createStatement();
File file = new File("lgsunlogo.gif");
FileInputStream fis = new
FileInputStream(file);
int itemnumber = 5;
/* PreparedStatement pstmt =
c.prepareStatement("insert into UDCS values(?,?,?)");
pstmt.setInt(1, itemnumber);
pstmt.setString(2,"lgsunlogo");
pstmt.setBinaryStream(3, fis,
(int)file.length());
pstmt.executeUpdate();
System.out.println("Inserted");*/
[email protected]
PRACTICALS 5
}
ImageIcon auctionimage = new
ImageIcon(imageBytes);
int width =auctionimage.getIconWidth();
int height =auctionimage.getIconHeight();
f = new JFrame("My Frame");
l = new JLabel(auctionimage);
l2 = new JLabel("ID");
l3 = new JLabel("NAME");
tf1 = new JTextField(25);
tf2 = new JTextField(25);
b1 = new JButton("SHOW IMAGE");
tf1.setText(str);
tf2.setText(str1);
f.getContentPane().setLayout(new
FlowLayout());
f.getContentPane().add(b1);
f.getContentPane().add(l2);
f.getContentPane().add(tf1);
f.getContentPane().add(l3);
f.getContentPane().add(tf2);
f.getContentPane().add(l);
b1.addActionListener(this);
l.setVisible(false);
l2.setVisible(false);
l3.setVisible(false);
tf1.setVisible(false);
tf2.setVisible(false);
f.setVisible(true);
f.setSize(600,600);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b1)
{
l.setVisible(true);
l2.setVisible(true);
[email protected]
PRACTICALS 6
l3.setVisible(true);
tf1.setVisible(true);
tf2.setVisible(true);
}
}
public static void main(String[] args)
{
new TestImage();
}
}
P
Prraaccttiiccaall :: A
Accttiivvee d
daattaab
baasseess
Consider the following relations:
[email protected]
PRACTICALS 7
Creating a Trigger :
Begin
UPDATE Project1
SET Thrs = Thrs + :NEW.Hrs
Where Pno = :NEW.Pno;
end;
[email protected]
PRACTICALS 8
Creating Trigger
BEGIN
UPDATE Project1
SET thrs=thrs+NEW.hrs-OLD.hrs
WHERE Pno=NEW.Pno;
END;
BEGIN
UPDATE Project
SET thrs = thrs + NEW.hrs
WHERE pno = NEW.pno;
UPDATE Project
SET thrs = thrs - OLD.hrs
WHERE pno = NEW.pno;
END;