ADBMS Lab Manual
ADBMS Lab Manual
ADBMS Lab Manual
PROGRAM 1.
Theory:-
CLOB stands for Character Large Object. It is a datatype used to store and retrieve
large amount of text data in character format. CLOB datatypes are created by using
CREATE commands. It can store Single byte and multiple byte character data. It
supports both fixed width and variable width character set.
A CLOB contains a logical pointer to a CLOB, not the CLOB itself. CLOB columns
are referred as LONG VARCHAR.
BLOB stands for Binary Large object or Basic Large Object. It is a datatype used to
store unstructured binary large objects. It is an array of bytes(byte[]) stored in the
database. It is not case sensitive Blob’s are used to hold multimedia objects.
BLOB’s fields are normally used to store graphics, audio, video, still images and so
on.
Insertb.java
Package vemana;
Import java.io.File;
Import java.io.FileInputStream;
Import java.io.IOException;
Import java.io.PrintWriter;
Import java.sql.Connection;
Import java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import java.sql.SQLException;
Import java.util.logging.Level;
Import java.util.logging.Logger;
Advances in Database Management Systems Laboratory Work 2018-2019
Import javax.servlet.ServletException;
Import javax.servlet.http.HttpServlet;
Import javax.servlet.http.HttpServletRequest;
Import javax.servlet.http.HttpServletResponse;
, "hr", "hr");
PreparedStatementps = con.prepareStatement("insert into pic values(?,?,?)
");
ps.setInt(1,3);
ps.setString(2,"Java Logo");
out.println("</html>");
}
catch(Exception e)
{
System.out.println(e);
}
finally {
out.close();
}
}
}
GetBLOB.java
Package vemana;
Import java.io.IOException;
Import java.io.InputStream;
Import java.io.OutputStream;
Import java.sql.Blob;
Import java.sql.Connection;
Import java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import java.sql.ResultSet;
Import javax.servlet.ServletException;
Import javax.servlet.http.HttpServlet;
Import javax.servlet.http.HttpServletRequest;
Import javax.servlet.http.HttpServletResponse;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connectioncon=DriverManager.getConnection("jdbc:oracle:thin:@localho
st:1521:xe", "hr", "hr");
PreparedStatementps = con.prepareStatement("select image from pic
where id = ?");
String id = request.getParameter("id");
ps.setString(1,id);
ResultSetrs = ps.executeQuery();
rs.next();
Blob b = rs.getBlob("image");
response.setContentType("image/jpeg");
response.setContentLength( (int) b.length());
InputStream is = b.getBinaryStream();
OutputStreamos = response.getOutputStream();
bytebuf[] = new byte[(int) b.length()];
is.read(buf);
os.write(buf);
os.close();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException
{
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponseresponse)
throwsServletException, IOException
{
Advances in Database Management Systems Laboratory Work 2018-2019
processRequest(request, response);
}
Bdisplay.java
packagevemana;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
while ( rs.next())
{
id=rs.getString("id");
out.println("<h4>" +id+ "</h4>");
out.println("<img width='160' height='160'
src=GetBLOB?id="+id+"></img><p/>");
}
out.println("</body>");
out.println("</html>");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}
Steps for storing and retrieving of BLOB and CLOB object:
Step 6: Storing and Retrieving of BLOB and CLOB object was displayed successfully.
Advances in Database Management Systems Laboratory Work 2018-2019
OUTPUT:
Advances in Database Management Systems Laboratory Work 2018-2019
CONCLUSION: - An application for storing and retrieving of BLOB and CLOB object
wasimplemented successfully.
Advances in Database Management Systems Laboratory Work 2018-2019
PROGRAM 2.
Develop a database application to demonstrate the representation of multivalued
attributes, and use of nested tables to represent complex objects. Write suitable
queries to demonstrate it.
Theory:-
Example:
Create a Type:
SQL> CREATE TYPE PURCHASE_ORDER AS TABLE OF VARCHAR(30);
2 /
OUTPUT
Type created.
ID COLUMN_VALUE
-----------------------------------------------
1 SUGAR
1 5
1 300
2 TEAPOWDER
2 2
2 400
3 GRAINS
3 3
3 500
9 rows selected.
PROGRAM 3.
Design and develop a suitable student database application .one of the attributes to
be maintained is the attendance of a student in each subject for which he/she has
enrolled. Using TRIGGERS, write active rules to do the following
a) Whenever the attendance is updated, check if the attendance is less than 85%, if
so notify the head of the department concerned.
b) Whenever the marks in an internal assessment test are entered, check if the
marks is less than 40%, if, so notify the head of the department concerned.
Table created.
1 row created.
SQL> /
Enter value for regno: 002
Enter value for name: JOHN
Enter value for major: CSE
Enter value for mark: 30
Enter value for attd: 70
old 1: INSERT INTO STUD_REC VALUES('®NO','&NAME','&MAJOR',&MARK,&ATTD)
new 1: INSERT INTO STUD_REC VALUES('002','JOHN','CSE',30,70)
1 row created.
SQL> /
Enter value for regno: 003
Enter value for name: ROSS
Enter value for major: CSE
Enter value for mark: 90
Enter value for attd: 95
old 1: INSERT INTO STUD_REC VALUES('®NO','&NAME','&MAJOR',&MARK,&ATTD)
new 1: INSERT INTO STUD_REC VALUES('003','ROSS','CSE',90,95)
1 row created.
SQL> /
Enter value for regno: 004
Enter value for name: RAHUL
Enter value for major: CSE
Enter value for mark: 85
Enter value for attd: 80
old 1: INSERT INTO STUD_REC VALUES('®NO','&NAME','&MAJOR',&MARK,&ATTD)
new 1: INSERT INTO STUD_REC VALUES('004','RAHUL','CSE',85,80)
1 row created.
Advances in Database Management Systems Laboratory Work 2018-2019
SQL> /
Enter value for regno: 005
Enter value for name: JOSEPH
Enter value for major: CSE
Enter value for mark: 75
Enter value for attd: 80
old 1: INSERT INTO STUD_REC VALUES('®NO','&NAME','&MAJOR',&MARK,&ATTD)
new 1: INSERT INTO STUD_REC VALUES('005','JOSEPH','CSE',75,80)
1 row created.
6 IF(:NEW.MARK<40)THEN DBMS_OUTPUT.PUT_LINE(:NEW.NAME||'BEARING
REGNO'||:NEW.REGNO||'GOT MARKS LESS THAN 40');
7 END IF;
8 END;
9 /
Trigger created.
PROGRAM 4.
Theory:-
Apriori is a classic algorithm for frequent itemset mining and association rule learning
over transactional databases. It proceeds by identifying the frequent individual items in
the database and extending them to larger and larger item sets as long as those item sets
appear sufficiently often in the database. The frequent item sets determined by Apriori
can be used to determine association rules which highlight general trends in the database:
this has applications in domains such as market basket analysis.
Steps in execution:
STEP 1: Create two notepad files and name them config.txt and transa.txt respectively.
STEP 2: In config.txt file, insert 3 lines of input
line 1 - number of items per transaction
line 2 - number of transactions
line 3 –minsup
STEP 3: In transa.txt file, which is the transaction file, where the input is separated
by space.
STEP 4: These two input files belongs to the class AprioriCalculation.Copy these
two input files in the specified path
STEP 5: Run the program in netbeans.
Advances in Database Management Systems Laboratory Work 2018-2019
package apriori;
import java.io.*;
import java.util.*;
ap.aprioriProcess();
}
}
/***************************************************************
* Class Name : AprioriCalculation
* Purpose : generate Aprioriitemsets
***************************************************************/
class AprioriCalculation
{
Vector<String> candidates=new Vector<String>(); //the current candidates
String configFile="config.txt"; //configuration file
String transaFile="transa.txt"; //transaction file
String outputFile="apriori-output.txt";//output file
intnumItems; //number of items per transaction
intnumTransactions; //number of transactions
double minSup; //minimum support for a frequent itemset
String oneVal[]; //array of value per column that will be treated as a
'1' String itemSep = " "; //the separator value for items in the database
Advances in Database Management Systems Laboratory Work 2018-2019
/***************************************************************
* Method Name : aprioriProcess
* Purpose : Generate the aprioriitemsets
* Parameters : None
* Return: None
***************************************************************/
public void aprioriProcess()
{
Date d; //date object for timing purposes
long start, end; //start and end time
intitemsetNumber=0; //the current itemset being looked at
//get config
getConfig();
//start timer
d = new Date();
start = d.getTime();
System.out.println(candidates);
}
//if there are <=1 frequent items, then its the end. This prevents reading through the
database again. When there is only one frequent itemset.
}while(candidates.size()>1);
//end timer
d = new Date();
end = d.getTime();
/***************************************************************
* Method Name : getInput
* Purpose : get user input from System.in
* Parameters : None
* Return : String value of the users input
***************************************************************/
public static String getInput()
{
String input="";
//read from System.in
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
}
return input;
}
/***************************************************************
* Method Name : getConfig
* Purpose : get the configuration information (config filename, transaction
filename)
*: configFile and transaFile will be change appropriately
* Parameters : None
* Return: None
***************************************************************/
private void getConfig()
{
FileWriterfw;
BufferedWriterfile_out;
String input="";
//ask if want to change the config
System.out.println("Default Configuration: ");
System.out.println("\tRegular transaction file with '" + itemSep + "' item
separator.");
System.out.println("\tConfig File: " + configFile);
System.out.println("\tTransa File: " + transaFile);
System.out.println("\tOutput File: " + outputFile);
System.out.println("\nPress 'C' to change the item separator, configuration file and
transaction files");
System.out.print("or any other key to continue. ");
input=getInput();
if(input.compareToIgnoreCase("c")==0)
{
System.out.print("Enter new transaction filename (return for '"+transaFile+"'):
"); input=getInput();
Advances in Database Management Systems Laboratory Work 2018-2019
if(input.compareToIgnoreCase("")!=0)
transaFile=input;
System.out.println("Filenames changed");
//number of transactions
numTransactions=Integer.valueOf(data_in.readLine()).intValue();
//minsup
minSup=(Double.valueOf(data_in.readLine()).doubleValue());
Advances in Database Management Systems Laboratory Work 2018-2019
minSup/=100.0;
else
for(inti=0; i<oneVal.length; i++)
oneVal[i]="1";
System.out.println(e);
}
}
/***************************************************************
* Method Name : generateCandidates
* Purpose : Generate all possible candidates for the n-thitemsets
* : these candidates are stored in the candidates class vector
* Parameters : n - integer value representing the current itemsets to be created
* Return: None
***************************************************************/
private void generateCandidates(int n)
{
Vector<String>tempCandidates = new Vector<String>(); //temporary
candidate string vector
String str1, str2; //strings that will be used for comparisons
StringTokenizer st1, st2; //string tokenizers for the two itemsets being compared
//if its the first set, candidates are just the numbers
if(n==1)
{
for(inti=1; i<=numItems; i++)
{
tempCandidates.add(Integer.toString(i));
}
}
else if(n==2) //second itemset is just all combinations of itemset 1
{
//add each itemset from the previous frequent itemsets
together for(inti=0; i<candidates.size(); i++) {
//if they have the same n-2 tokens, add them together
if(str2.compareToIgnoreCase(str1)==0)
tempCandidates.add((str1 + " " + st1.nextToken() + " "
+ st2.nextToken()).trim());
}
}
Advances in Database Management Systems Laboratory Work 2018-2019
}
//clear the old candidates
candidates.clear();
//set the new ones
candidates = new Vector<String>(tempCandidates);
tempCandidates.clear();
}
/***************************************************************
* Method Name : calculateFrequentItemsets
* Purpose : Determine which candidates are frequent in the n-thitemsets
* from all possible candidates
* Parameters : n - iteger representing the current itemsets being evaluated
***************************************************************/
private void calculateFrequentItemsets(int n) {
try
{
//output file
fw= new FileWriter(outputFile, true);
file_out = new BufferedWriter(fw);
//load the transaction file
Advances in Database Management Systems Laboratory Work 2018-2019
trans[j]=(stFile.nextToken().compareToIgnoreCase(oneVal[j])==0); //if
it is not a 0, assign the value to true
}
}
for(inti=0; i<candidates.size(); i++)
{
// System.out.println("Candidate: " + candidates.get(c) + " with count: " +
count + " % is: " + (count/(double)numItems));
//if the count% is larger than the minSup%, add to the candidate to
the frequent candidates
if((count[i]/(double)numTransactions)>=minSup)
{
frequentCandidates.add(candidates.get(i));
//put the frequent itemset into the output file
file_out.write(candidates.get(i) + "," + count[i]/(double)numTransactions +
"\n");
}
}
file_out.write("-\n");
file_out.close();
}
//if error at all in this process, catch it and print the error
messate catch(IOException e)
{
System.out.println(e);
}
//clear old candidates
candidates.clear();
//new candidates are the old frequent candidates
candidates = new Vector<String>(frequentCandidates);
frequentCandidates.clear();
}
}
Advances in Database Management Systems Laboratory Work 2018-2019
Input:
Advances in Database Management Systems Laboratory Work 2018-2019
Output:-