You are on page 1of 56

EX.

No 1)
College.html
<html>
<head>
<title>USE of INTERNAL and EXTERNAL STYLESHEETS
</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid{font-family:verdana;font-style:italic;color:red;text-align:center}
.ani{font-family:tahoma;font-style:italic;font-size:20;text-align:center;}
font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<center><p style="font-size:20pt;color:purple">Shree Motilal Kanhaiyalal Fomra
Institute Of Technology</br>
<p style="font-size:12pt;color:purple">Approved by AICTE, New Delhi & Affilated
to ANNA UNIVERSITY, Chennai</h4></br>
<p style="font-size:12pt;color:purple">Old Mahabalipuram Road, (I.T Highway),
Near Kelambakkam,Chennai - 603 103.</br>
<img src="clg.jpg"></center>
<h2 class="vid"><a href="home.html">HOME</h2>
<h2 class="vid"><a href="department.html">DEPARTMENT</h2>
<h2 class="vid"><a href="result.html">RESULT</h2>
<h2 class="vid"><a href="home.html">CONTACT US</h2>
</body>
</html>

Department.html
<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body>
<h3>Departments</h3>
<font>
<ol style="list-style-type:lower-alpha">
<li>COMPUTER SCIENCE AND ENGINEERING
<li>INFORMATION TECHNOLOGY
<li>BIO MEDICAL ENGINEERING
<li>INFORMATION TECHNOLOGY
<li>ELECTRONICS AND COMMUNICATION ENGINEERING
<li>ELECTRICAL AND ELECTRONICS ENGINEERING
<li>MECHANICAL ENGINEERING
<LI>CIVIL ENGINEERING
</ol>
<font>
</body>
</html>
Home.html
<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>

<body bgcolor="pink">
<h3>MOTILAL KANHAIYALAL FOMRA CHARITABLE TRUST</h2>
<p>Greetings to all. We, Shree Motilal Kanhaiyalal Fomra Institute of
Technology,</br> welcomes you to this great institution.</br> The Motilal
Kanhaiyalal Fomra Charitable Trust was founded during the year 1995 by Late
Shree Kanhaiyalalji F</br>omra, with a view to promote the cause of education
and to help the economically and socially under privileged students.<br> This is
an ISO 9001:2008 certified institution.
</body>
</html>

Result.html

<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body>
<h3>Results of cse students</h3>
<table width="100%" cellspacing="2" cellpadding="2" border="5">
<tr>
<th>S.NAME</th>
<th>MARKS</th>
<th>RESULT</th>
</tr>
<tr>
<td align="center">Dinesh</td>

<td align="center">100</td>

<td align="center">pass</td>
</tr>
<tr>
<td align="center">Bala</td>
<td align="center">99</td>
<td align="center">pass</td>
</tr>
<tr>
<td align="center">Gopi</td>
<td align="center">98</td>
<td align="center">pass</td>
</tr>
</table>
</body>
</html>

Xyz.html

h3{font-family:arial;font-size:20;color:cyan}
table{border-color:green}
td{font-size:20pt;color:magenta}

EX.No 2: Create a web page containing details about the placement cell in
your college using cascading style sheets.
Program
Placementcell.html
<html>
<head>
<title>SMK FOMRA PLACEMENT CELL
</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid{font-family:verdana;font-style:italic;color:red;text-align:center}
.ani{font-family:tahoma;font-style:italic;font-size:20;text-align:center;}
font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<center><p style="font-size:20pt;color:red">SMK FOMRA PLACEMENT
CELL</br>
<p style="font-size:12pt;color:purple">Approved by AICTE, New Delhi &
Affilated to ANNA UNIVERSITY, Chennai</h4></br>
<p style="font-size:12pt;color:purple">Old Mahabalipuram Road, (I.T
Highway), Near Kelambakkam,Chennai - 603 103.</br>
<img src="clg.jpg"></center>
<h2 class="vid"><a href="placed.html">PLACED STUDENTS
DETAIL</h2>
<h2 class="vid"><a href="companies.html">COMPANIES VIITED</h2>
<h2 class="vid"><a href="schedule.html">PLACEMENT SCHEDULE</h2>
<h2 class="vid"><a href="gallary.html">GALLARY</h2>

<h2 class="vid"><a href="visitors.html">VISITORS</h2>


</body>
</html>

Placed .html
<html>
<head>
<title>SMK FOMRA PLACEMENT CELL</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid{font-family:verdana;font-style:italic;color:red;text-align:center}
.ani{font-family:tahoma;font-style:italic;font-size:20;text-align:center;}
font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<center><p style="font-size:20pt;color:red">SMK FOMRA PLACEMENT
CELL</br>
<p style="font-size:12pt;color:purple">Approved by AICTE, New Delhi &
Affilated to ANNA UNIVERSITY, Chennai</h4></br>
<p style="font-size:12pt;color:purple">Old Mahabalipuram Road, (I.T
Highway), Near Kelambakkam,Chennai - 603 103.</br>
<img src="clg.jpg"></center>
<h2 class="vid"><a href="placed.html">PLACED STUDENTS
DETAIL</h2>
<h2 class="vid"><a href="companies.html">COMPANIES VIITED</h2>
<h2 class="vid"><a href="schedule.html">PLACEMENT SCHEDULE</h2>

<h2 class="vid"><a href="gallary.html">GALLARY</h2>


<h2 class="vid"><a href="visitors.html">VISITORS</h2>
</body>
</html>

Companies.html
<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body>
<h3>COMPANIES VISITED</h3>
<font>
ON CAMPUS DETAILS</br>
<ol style="list-style-type:lower-alpha">
<li>HCL TECHNOLOGIS
<li>COGNIZANT TECHNOLOGIES
<li>WIPRO
<li>VIRTUSA
<li>HP
<li>MPHASIS
<li>SAINT GOBAIN
</ol>
<font>
OFF CAMPUS DETAILS</br>
<ol style="list-style-type:lower-alpha">

<li>INFOSYS
<li>ATHENA HEALTH CARE
<li>AMERICAN MEGA TRENDS
<li>FLEXTRONIXS
<li>ASHOK LEYLAND
<li>HANI SOLUTONS
</ol>
</body>
</html>

Schedule.html
<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body>
<h3>PLACEMENT SCHEDULE</h3>
<table width="100%" cellspacing="2" cellpadding="2" border="5">
<tr>
<th>COMPANY</th>
<th>DEPARTMENT</th>
<th>DATE</th>
<th>VENUE</th>
</tr>
<tr>
<td align="center">HCL</td>

<td align="center">CSC AND IT</td>


<td align="center">20-04-2015</td>
<td align="center">VELS UNIVERSITY</td>
</tr>
<tr>

<td align="center">ZIFO TECHNOLOGIES</td>

<td align="center">BME</td>

<td align="center">21-04-2015</td>
<td align="center">SNN</td>
</tr>
<tr>

<td align="center">ASHOK LEYLAND</td>


<td align="center">MECH</td>
<td align="center">22-04-2015</td>
<td align="center">JEPPIAR</td>
</tr>
</table>
</body>
</html>

Gallery.html
<html>
<head>

<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body bgcolor="gray">
<center><h3>PHOTO GALLARY</h3></center>
<table width="100%" border="0">
<tr>
<td align="center"><img src="clg.jpg"></td>
<td align="center"><img src="clg.jpg"></td>
</tr></table>
</body>
</html>

EX.No 3
Create a web page using XHTML for Library management system application
Library.html
<html>
<head>
<title>LIBRARY MANAGEMENT SYSTEM
</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid{font-family:verdana;font-style:italic;color:red;text-align:center}
.ani{font-family:tahoma;font-style:italic;font-size:20;text-align:center;}
font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body bgcolor="yellow">
<center><p style="font-size:20pt;color:purple">LIBRARY MANAGEMENT
SYSTEM</br>
<p style="font-size:12pt;color:purple">SMK FOMRA INSTITUTE OF
TECHNOLOGY</br>
<img src="clg.jpg"></center>
<h2 class="vid"><a href="add.html">ADD BOOKs</h2>
<h2 class="vid"><a href="issue.html">ISSUES OF BOOK</h2>
<h2 class="vid"><a href="details.html">BOOK DETAILS</h2>
<h2 class="vid"><a href="report.html">REPORT</h2>
</body>
</html>
Add.html
<html>

<head>
<title>ADD DETAILS</title>
</head>
<body>
<center><h3>ADD BOOK</h3></center>
<form>
Title<input type="text" name="title"></br>
Author<input type="text" name="author"></br>
Year<input type="text" name="year"></br>
ISBN<input type="text" name="isbn"></br>
Date Purchased<input type="text" name="date"></br>
Price<input type="text" name="price"></br>
<input type="submit" value="SAVE" name="save">
<input type="submit" value="CLEAR" name="clear">
</form>
</body>
</html>

Issue.html
<html>
<head>
<title>ISSUE DETAILS</title>
</head>
<body>
<center><h3>ISSUES OF BOOK</h3></center>
<form>
BOOK NO<input type="text" name="bno"></br>
Student ID<input type="text" name="stID"></br>

Copies Available<input type="text" name="available"></br>


Issue Date<input type="text" name="ISsueDate"></br>
Due Date<input type="text" name="duedate"></br>
Price<input type="text" name="price"></br>
<input type="submit" value="SAVE" name="save">
<input type="submit" value="CLEAR" name="clear">
</form>
</body>
</html>

Details.html

<html>
<head>
<title>BOOK DETAILS</title>
</head>
<body>
<center><h3>BOOK DETAILS</h3></center>
<form>
SEARCH BY BOOK NAME<input type="text" name="stID"></br>
SEARCH BY ISBN<input type="text" name="available"></br>
SEARCH BY AUTHOR<input type="text" name="ISsueDate"></br>
<input type="submit" value="SEARCH" name="save">
</form>
</body>
</html>

Report.html

<html>
<head>
<title>Result</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
</head>
<body>
<h3>REPORT</h3>

<table width="100%" cellspacing="2" cellpadding="2" border="5">

<tr>

<th>STUDENT NAME</TH>
<th>STUDENT ID</TH>
<th>TITLE</TH>
<th>AUTHOR NAME</th>
<th>DATE OF ISSUE</th>
<th>DATE OF RETURN</th>

</tr>

<tr>

<td align="center">PRABHU</td>

<td align="center">CSC</td>

<td align="center">HCL</td>

<td align="center">PRABHU</td>

<td align="center">CSC</td>

<td align="center">HCL</td>

</tr>

<tr>

<td align="center">SELVI</td>

<td align="center">BME</td>

<td align="center">ZIFO TECHNOLOGIES</td>


<td align="center">PRABHU</td>

<td align="center">CSC</td>

<td align="center">HCL</td>

</tr>

</body>
</html>

OUTPUT

11Q
11. a. Create relations using MYSQL for a banking application given below enforcing primary
key and foreign key constraints.
CUSTOMER (CID, CNAME)
ACCOUNT (ANO, ATYPE, BALANCE, CID)
An account can be a savings account or a current account. Check ATYPE in S or C. A
customer can have both types of accounts.
TRANSACTION (TID, ANO, TTYPE, TDATE, TAMOUNT)
TTYPE CAN BE D OR W
D- Deposit; W Withdrawal
The primary keys are underlined.
Develop a java application using database connectivity to list all records from
the above relations and illustrate a join query and an update operation.
Answer
Step 1 : create tables using following sql statements
Customer
create table customer(cname varchar2(20),cid number(5));
Account
create table account(cid number(5),ano number(5),atype varchar(2),balance
number(5));
Transaction
create table trans(tid number(5),ttype varchar2(2),ano number(5),tdate
varchar2(12),tamount number(5));

Step 2 : Open a notepad and type the following code and save the file as .java.
Note ur class name and file name should be same. Here the class name is
BankApplication, so your file name must be BankApplication.java

Step 3 :
Open command prompt and go to the directory where you have saved the above
notepad file
Using cd command.

Step 4 :

Compile the file using javac filename.java


If your file name is BankApplication.. then.. javac BankApplication.java
To run : java BankApplication
Step 5 :
Run the file using java filename.

Program

BankApplication.java
import java.io.*;
import java.sql.*;
public class BankApplication {

public void createCustomer()throws Exception


{
String cname;
int cid;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Customer Name :");
cname = dis.readLine();
System.out.println("Enter Customer ID :");
cid = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tig
er");

String customerSQL = "INSERT INTO customer(cname,cid) VALUES(?,?)";

PreparedStatement customer_psmt = con.prepareStatement(customerSQL);


customer_psmt.setString(1,cname);
customer_psmt.setInt(2,cid);

int i = customer_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Customer Registered successfully");
}
else
{
System.out.println("Customer Registration failed");
}
}

public void createAccount()throws Exception


{
String atype;
int cid,balance,ano;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Customer ID :");
cid = Integer.parseInt(dis.readLine());
System.out.println("Enter Account No:");
ano = Integer.parseInt(dis.readLine());
System.out.println("Enter Account Type. Enter S for Saving Account. Enter C
for Current Account");

atype = dis.readLine();
System.out.println("Enter Balance:");
balance = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String accountSQL = "INSERT INTO account(cid,ano,atype,balance)
VALUES(?,?,?,?)";

PreparedStatement account_psmt = con.prepareStatement(accountSQL);


account_psmt.setInt(1,cid);
account_psmt.setInt(2,ano);
account_psmt.setString(3,atype);
account_psmt.setInt(4,balance);
int i = account_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Account Registered successfully");
}
else
{
System.out.println("Account Registration failed");
}
}

public void createTransaction()throws Exception


{
String ttype,tdate;
int tid,tamount,ano;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Transaction ID :");
tid = Integer.parseInt(dis.readLine());
System.out.println("Enter Transaction Type. Enter W for Withdraw amount
or D for Deposit Amount");
ttype = dis.readLine();
System.out.println("Enter Account No:");
ano = Integer.parseInt(dis.readLine());
System.out.println("Enter Transaction Date in DD-MM-YYYY:");
tdate = dis.readLine();
System.out.println("Enter Transaction Amount:");
tamount = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String transactionSQL = "INSERT INTO trans(tid,ttype,ano,tdate,tamount)
VALUES(?,?,?,?,?)";

PreparedStatement transaction_psmt =
con.prepareStatement(transactionSQL);
transaction_psmt.setInt(1,tid);
transaction_psmt.setString(2,ttype);
transaction_psmt.setInt(3,ano);

transaction_psmt.setString(4,tdate);
transaction_psmt.setInt(5,tamount);

int i = transaction_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Transaction Registered successfully");
}
else
{
System.out.println("Transaction Registration failed");
}
}

public void display()throws Exception


{
Connection con= null;
Class.forName("sun.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc: odbc:bme","scott","tiger");
String SQL = "SELECT cid,cname,tid,ttype,tamount FROM customer,trans";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(SQL);
while(rs.next())
{
System.out.println("Customer ID : " + rs.getInt(1));
System.out.println("Customer Name :" + rs.getString(2));
System.out.println("Transaction ID :" + rs.getInt(3));

System.out.println("Transaction Type :" + rs.getString(4));


System.out.println("Transaction amount :" + rs.getInt(5));
System.out.println();
System.out.println();
}
}

public static void main(String[] args)throws Exception


{
BankApplication ba = new BankApplication();
ba.createCustomer();
ba.createAccount();
ba.createTransaction();
ba.display();
}

12Q
12. a. Create relations using MYSQL for a bus reservation application given below enforcing
primary key and foreign key constraints.
BUS (ROUTENO, SOURCE, DESTINATION)
PASSENGER (PID, PNAME, DOB, GENDER)
BOOK_TICKET (PID, ROUTENO, JOURNEY_DATE, SEAT_NO)
The primary keys are underlined.
Develop a java application using database connectivity to list all records from
the above relations and illustrate a join query and an update operation.

Answer

Step 1 : create tables using following sql statements


BUS
create table bus(pid number(10),route number(5), source
varchar2(20),destination varchar2(20));
PASENGER
create table passenger(pid number(10) primary key,pname varchar2(20),
dob date,gender varchar2(10));
BOOK TICKET
create table book_ticket(pid number(10),routeno number(10),journey_date
date,seat_no number(4));

Step 2 : Open a notepad and type the following code and save the file as .java.
Note ur class name and file name should be same. Here the class name is
BusApplication, so your file name must be BusApplication.java

Step 3 :
Open command prompt and go to the directory where you have saved the above
notepad file
Using cd command.

Step 4 :
Compile the file using javac filename.java
If your file name is BusApplication.. then.. javac BusApplication.java
To run : java BusApplication

Step 5 :
Run the file using java filename.

Program
import java.io.*;

import java.sql.*;

public class BusApplication


{
public void reserve() throws Exception
{
DataInputStream r = new DataInputStream(System.in);
String pname,dob,gender,source,dest,j_date;
int id,n,route,i,j,k;
System.out.println("Enter Passenger name : ");
pname = r.readLine();
System.out.println("Enter Passenger ID : ");
id = Integer.parseInt(r.readLine());
System.out.println("Enter Passenger DOB in DD-MM-YYYY: ");
dob = r.readLine();
System.out.println("Enter Passenger Gender : ");
gender = r.readLine();
System.out.println("Enter No.of Passengers : ");
n = Integer.parseInt(r.readLine());
System.out.println("Enter journey date in DD-MM-YYYY: ");
j_date = r.readLine();
System.out.println("Enter Source : ");
source = r.readLine();
System.out.println("Enter Destination: ");
dest = r.readLine();
System.out.println("Enter Bus Route no: ");
route = Integer.parseInt(r.readLine());

Connection con= null;


Class.forName("sun.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc: odbc:bme","scott","tiger");
String busSQL = "INSERT INTO bus(pid,routeno,source,destination)
VALUES(?,?,?,?)";
String passSQL = "INSERT INTO passenger(pid,pname,dob,gender) VALUES
(?,?,?,?)";
String bookSQL = "INSERT INTO
book_ticket(pid,routeno,journey_date,seat_no) VALUES(?,?,?,?)";

PreparedStatement bus_psmt = con.prepareStatement(busSQL);


bus_psmt.setInt(1,id);
bus_psmt.setInt(2,route);
bus_psmt.setString(3,source);
bus_psmt.setString(4,dest);

i = bus_psmt.executeUpdate();

PreparedStatement pass_psmt = con.prepareStatement(passSQL);


pass_psmt.setInt(1,id);
pass_psmt.setString(2,pname);
pass_psmt.setString(3,dob);
pass_psmt.setString(4,gender);

j = pass_psmt.executeUpdate();

PreparedStatement book_psmt = con.prepareStatement(bookSQL);


book_psmt.setInt(1,id);
book_psmt.setInt(2,route);

book_psmt.setString(3,j_date);
book_psmt.setInt(4,n);

k = book_psmt.executeUpdate();

if((i == 1)&&(j==1)&&(k == 1))


{
System.out.println("Reservation Successfull");
}
else
{
System.out.println("Reservation failed");
}
con.commit();
con.close();
}

public void display() throws Exception


{
Connection con= null;
Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String SQL = "SELECT pname,pid,gender,dob FROM passenger";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(SQL);
while(rs.next())
{

System.out.println("Passenger name :" + rs.getString(1));


System.out.println("Passenger ID : " + rs.getInt(2));
System.out.println("Gender :" + rs.getString(3));
System.out.println("Date of birth :" + rs.getString(4));
System.out.println();
System.out.println();
}
}
public static void main(String[] args) throws Exception
{
BusApplication bus = new BusApplication();
bus.reserve();
bus.display();

}
}

13Q
13. a. Create relations using MYSQL for a student enrollment application given below enforcing
primary key and foreign key constraints.
STUDENT (ROLLNO, NAME, DATE_OF_BIRTH, GENDER, BRANCH_CODE)
BRANCH (BRANCH_CODE, BRANCH_NAME)
COURSE (CCODE, CNAME, CREDITS)
ENROLLS (ROLLNO, CCODE, SESS, GRADE)
SESS can take the values APRIL2014, NOVEMBER2014
The primary keys are underlined.
Develop a java application using database connectivity to list all records from
the above relations and illustrate a join query and an update operation.

Answer

Step 1 : create tables using following sql statements


Student
create table student(sname varchar2(20),rollno number(5),dob
varchar2(12),gender varchar2(6),bcode number(5));
Branch
create table branch(bname varchar2(20),bcode number(5));
Course
create table course(cname varchar2(20),ccode number(5),credits number(2));
Step 2 : Open a notepad and type the following code and save the file as .java.
Note ur class name and file name should be same. Here the class name is
Student, so your file name must be Student.java

Step 3 :
Open command prompt and go to the directory where you have saved the above
notepad file
Using cd command.

Step 4 :
Compile the file using javac filename.java
If your file name is Student.. then.. javac Student.java
To run : java Student
Step 5 :
Run the file using java filename.

Program

import java.io.*;
import java.sql.*;

public class Student {

public void createStudent() throws Exception


{
String sname,dob,gender;
int rollno,bcode;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Student Name :");
sname = dis.readLine();
System.out.println("Enter roll no :");
rollno = Integer.parseInt(dis.readLine());
System.out.println("Enter Student DOB :");
dob = dis.readLine();
System.out.println("Enter student gender :");
gender = dis.readLine();
System.out.println("Enter Branch code :");
bcode = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("sun.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc: odbc:bme","scott","tiger");
String stSQL = "INSERT INTO student(sname,rollno,dob,gender,bcode)
VALUES(?,?,?,?,?)";

PreparedStatement st_psmt = con.prepareStatement(stSQL);


st_psmt.setString(1,sname);
st_psmt.setInt(2,rollno);
st_psmt.setString(3,dob);

st_psmt.setString(4,gender);
st_psmt.setInt(5,bcode);

int i = st_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Student Registered successfully");
}
else
{
System.out.println("Student Registration failed");
}
}

public void createBranch() throws Exception


{
String bname;
int bcode;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Branch Name :");
bname = dis.readLine();
System.out.println("Enter Branch code :");
bcode = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");

con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String branchSQL = "INSERT INTO branch(bname,bcode) VALUES(?,?)";

PreparedStatement branch_psmt = con.prepareStatement(branchSQL);


branch_psmt.setString(1,bname);
branch_psmt.setInt(2,bcode);

int i = branch_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Branch Registered successfully");
}
else
{
System.out.println("Branch Registration failed");
}
}

public void createCourse() throws Exception


{
String cname;
int ccode,credits;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Course Name :");
cname = dis.readLine();
System.out.println("Enter Course code :");

ccode = Integer.parseInt(dis.readLine());
System.out.println("Enter Course Credits :");
credits = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String courseSQL = "INSERT INTO course(cname,ccode,credits)
VALUES(?,?,?)";

PreparedStatement course_psmt = con.prepareStatement(courseSQL);


course_psmt.setString(1,cname);
course_psmt.setInt(2,ccode);
course_psmt.setInt(3,credits);

int i = course_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Course Registered successfully");
}
else
{
System.out.println("Course Registration failed");
}
}

public void display() throws Exception


{
Connection con= null;
Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String SQL = "SELECT sname,rollno,cname,ccode,credits FROM
student,course";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(SQL);
while(rs.next())
{
System.out.println("Student Name :" + rs.getString(1));
System.out.println("Student roll no : " + rs.getInt(2));
System.out.println("Course name:" + rs.getString(3));
System.out.println("Course code :" + rs.getInt(4));
System.out.println("Course Credit :" + rs.getInt(5));
System.out.println();
System.out.println();
}
}
public static void main(String[] args) throws Exception
{
Student st = new Student();
st.createStudent();
st.createBranch();
st.createCourse();
st.display();

14Q
14. a. Create relations using MYSQL for an order processing application given below enforcing
primary key and foreign key constraints.
CUSTOMER (CID, NAME)
PRODUCT (PCODE, PNAME, UNIT_PRICE)
CUST_ORDER (OCODE, ODATE, CID)
ORDER_PRODUCT (OCODE, PCODE, NOU)
NOU Number of Units
An order can contain many products. The primary keys are underlined.
Develop a java application using database connectivity to list all records from
the above relations and illustrate a join query and an update operation

Answer
Step 1 : create tables using following sql statements
Customer
create table customer(cname varchar2(20),cid number(5));
Products
create table product(pcode number(5),pname varchar2(15),unit_price
number(3));
Orders
create table orders(ocode number(5),odate varchar2(12),cid number(5));

Step 2 : Open a notepad and type the following code and save the file as .java.
Note ur class name and file name should be same. Here the class name is
OrderProducts, so your file name must be OrderProducts.java

Step 3 :
Open command prompt and go to the directory where you have saved the above
notepad file
Using cd command.

Step 4 :
Compile the file using javac filename.java
If your file name is OrderProducts.. then.. javac OrderProducts.java
To run : java Student

Step 5 :
Run the file using java filename.

Program

import java.io.*;
import java.sql.*;
public class OrderProducts {

public void createUser() throws Exception


{
String cname;
int cid;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter customer name :");

cname = dis.readLine();
System.out.println("Enter customer ID :");
cid = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("sun.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc: odbc:bme","scott","tiger");
String userSQL = "INSERT INTO customer(cname,cid) VALUES(?,?)";

PreparedStatement user_psmt = con.prepareStatement(userSQL);


user_psmt.setString(1,cname);
user_psmt.setInt(2,cid);

int i = user_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Registered successfully");
}
else
{
System.out.println("Registration failed");
}

public void productList() throws Exception


{

String pname;
int pcode,unit_price;

DataInputStream dis = new DataInputStream(System.in);


System.out.println("Enter product name :");
pname = dis.readLine();
System.out.println("Enter product code :");
pcode = Integer.parseInt(dis.readLine());
System.out.println("Enter unit price :");
unit_price = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String productSQL = "INSERT INTO product(pcode,pname,unit_price)
VALUES(?,?,?)";

PreparedStatement product_psmt = con.prepareStatement(productSQL);


product_psmt.setInt(1,pcode);
product_psmt.setString(2,pname);
product_psmt.setInt(3,unit_price);

int i = product_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Product entered successfully");

}
else
{
System.out.println("Product register failed");
}
}

public void orderList() throws Exception


{
String odate;
int ocode,cid;

DataInputStream dis = new DataInputStream(System.in);


System.out.println("Enter order date in DD-MM-YYYY :");
odate = dis.readLine();
System.out.println("Enter product code :");
ocode = Integer.parseInt(dis.readLine());
System.out.println("Enter customer id:");
cid = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String orderSQL = "INSERT INTO orders(ocode,odate,cid) VALUES(?,?,?)";

PreparedStatement order_psmt = con.prepareStatement(orderSQL);


order_psmt.setInt(1,ocode);

order_psmt.setString(2,odate);
order_psmt.setInt(3,cid);

int i = order_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Order Registered successfully");
}
else
{
System.out.println("Order Registration failed");
}
}

public void display() throws Exception


{
Connection con= null;
Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","3K
amal94");
String SQL = "SELECT cid,ocode,odate,pcode,pname,unit_price FROM
product,orders";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(SQL);
while(rs.next())
{
System.out.println("Customer ID :" + rs.getInt(1));

System.out.println("Order code : " + rs.getInt(2));


System.out.println("Order date :" + rs.getString(3));
System.out.println("Product code :" + rs.getInt(4));
System.out.println("Product name :" + rs.getString(5));
System.out.println("Unit price :" + rs.getInt(6));
System.out.println();
System.out.println();
}

public static void main(String[] args) throws Exception


{
OrderProducts op = new OrderProducts();
op.createUser();
op.productList();
op.orderList();
op.display();
}

15Q

15. a. Create relations using MYSQL for a transport management system application given below
enforcing primary key and foreign key constraints.
DRIVER (DCODE, DNAME, DOB, GENDER)
CITY (CCODE, CNAME)
TRUCK (TRUCKCODE, TTYPE)
TTYPE can take two values (L,H)
L-Light
H- Heavy
Each truck is assigned a unique truck code. There can be many trucks belonging to the same truck
type.
DRIVE_TRUCK (TRUCKCODE, DCODE, DOT, CCODE)
DOT Date of Trip
The primary keys are underlined.
Develop a java application using database connectivity to list all records from
the above relations and illustrate a join query and an update operation.

Answer
Step 1 : create tables using following sql statements
Driver
create table driver(did number(5),dname varchar2(20),dob varchar2(12),gender
varchar2(6));
City
create table city(ccode number(5),city varchar2(15));
Truck
create table truck(tcode number(5),ttype varchar2(10));
Step 2 : Open a notepad and type the following code and save the file as .java.
Note ur class name and file name should be same. Here the class name is
Student, so your file name must be Student.java

Step 3 :
Open command prompt and go to the directory where you have saved the above
notepad file
Using cd command.

Step 4 :
Compile the file using javac filename.java

If your file name is TruckDriver.. then.. javac TruckDriver.java


To run : java TruckDriver
Step 5 :
Run the file using java filename.

Program

import java.io.*;
import java.sql.*;

public class TruckDriver {

public void createDriver() throws Exception


{
String dname,dob,gender;
int did;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Driver name :");
dname = dis.readLine();
System.out.println("Enter Driver ID :");
did = Integer.parseInt(dis.readLine());
System.out.println("Enter Driver DOB:");
dob = dis.readLine();
System.out.println("Enter Driver Gender:");
gender = dis.readLine();

Connection con= null;


Class.forName("sun.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc:
odbc:bme","scott","tiger");
String driverSQL = "INSERT INTO driver(did,dname,dob,gender)
VALUES(?,?,?,?)";

PreparedStatement driver_psmt = con.prepareStatement(driverSQL);


driver_psmt.setInt(1,did);
driver_psmt.setString(2,dname);
driver_psmt.setString(3,dob);
driver_psmt.setString(4,gender);

int i = driver_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Driver Registered successfully");
}
else
{
System.out.println("Driver Registration failed");
}

public void createCity() throws Exception

{
String city;
int ccode;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter city :");
city = dis.readLine();
System.out.println("Enter city ID :");
ccode = Integer.parseInt(dis.readLine());

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","sco
tt","3Kamal94");
String citySQL = "INSERT INTO city(ccode,city) VALUES(?,?)";

PreparedStatement city_psmt = con.prepareStatement(citySQL);


city_psmt.setInt(1,ccode);
city_psmt.setString(2,city);

int i = city_psmt.executeUpdate();

if(i == 1)
{
System.out.println("City Registered successfully");
}
else

{
System.out.println("City Registration failed");
}

public void createTruck() throws Exception


{
String ttype;
int tcode;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter Truck Code :");
tcode = Integer.parseInt(dis.readLine());
System.out.println("Enter Truck Type :");
ttype = dis.readLine();

Connection con= null;


Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","sco
tt","3Kamal94");
String truckSQL = "INSERT INTO truck(tcode,ttype) VALUES(?,?)";

PreparedStatement truck_psmt = con.prepareStatement(truckSQL);


truck_psmt.setInt(1,tcode);
truck_psmt.setString(2,ttype);

int i = truck_psmt.executeUpdate();

if(i == 1)
{
System.out.println("Truck Registered successfully");
}
else
{
System.out.println("Truck Registration failed");
}

public void display() throws Exception


{
Connection con= null;
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc:
odbc:bme","scott","tiger");
String SQL = "SELECT dname,did,tcode,ttype FROM driver,truck";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(SQL);
while(rs.next())
{
System.out.println("Driver Name :" + rs.getString(1));
System.out.println("Driver ID : " + rs.getInt(2));
System.out.println("Truck ID :" + rs.getInt(3));

System.out.println("Truck Type :" + rs.getString(4));


System.out.println();
System.out.println();
}
}

public static void main(String[] args)throws Exception


{
TruckDriver td = new TruckDriver();
td.createDriver();
td.createCity();
td.createTruck();
td.display();
}

You might also like