View
294
Download
19
Category
Preview:
Citation preview
EX.No 1)College.html
USE of INTERNAL and EXTERNAL STYLESHEETS
.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}
Shree Motilal Kanhaiyalal Fomra Institute Of Technology
Approved by AICTE, New Delhi & Affilated to ANNA UNIVERSITY, Chennai
Old Mahabalipuram Road, (I.T Highway), Near Kelambakkam,Chennai - 603 103.
HOME
DEPARTMENT
RESULT
CONTACT US
Department.html
Result
Departments
COMPUTER SCIENCE AND ENGINEERING
INFORMATION TECHNOLOGY
BIO MEDICAL ENGINEERING
INFORMATION TECHNOLOGY
ELECTRONICS AND COMMUNICATION ENGINEERING
ELECTRICAL AND ELECTRONICS ENGINEERING
MECHANICAL ENGINEERING
CIVIL ENGINEERING
Home.html
Result
MOTILAL KANHAIYALAL FOMRA CHARITABLE TRUST
Greetings to all. We, Shree Motilal Kanhaiyalal Fomra Institute
of Technology, welcomes you to this great institution. The Motilal
Kanhaiyalal Fomra Charitable Trust was founded during the year 1995
by Late Shree Kanhaiyalalji Fomra, with a view to promote the cause
of education and to help the economically and socially under
privileged students.
This is an ISO 9001:2008 certified institution.
Result.html
Result
Results of cse students
S.NAME
MARKS
RESULT
Dinesh
100
pass
Bala
99
pass
Gopi
98
pass
Xyz.htmlh3{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
SMK FOMRA PLACEMENT CELL
.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}
SMK FOMRA PLACEMENT CELL
Approved by AICTE, New Delhi & Affilated to ANNA UNIVERSITY, Chennai
Old Mahabalipuram Road, (I.T Highway), Near Kelambakkam,Chennai - 603 103.
PLACED STUDENTS DETAIL
COMPANIES VIITED
PLACEMENT SCHEDULE
GALLARY
VISITORS
Placed .html
SMK FOMRA PLACEMENT CELL
.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}
SMK FOMRA PLACEMENT CELL
Approved by AICTE, New Delhi & Affilated to ANNA UNIVERSITY, Chennai
Old Mahabalipuram Road, (I.T Highway), Near Kelambakkam,Chennai - 603 103.
PLACED STUDENTS DETAIL
COMPANIES VIITED
PLACEMENT SCHEDULE
GALLARY
VISITORS
Companies.html
Result
COMPANIES VISITED
ON CAMPUS DETAILS
HCL TECHNOLOGIS
COGNIZANT TECHNOLOGIES
WIPRO
VIRTUSA
HP
MPHASIS
SAINT GOBAIN
OFF CAMPUS DETAILS
INFOSYS
ATHENA HEALTH CARE
AMERICAN MEGA TRENDS
FLEXTRONIXS
ASHOK LEYLAND
HANI SOLUTONS
Schedule.html
Result
PLACEMENT SCHEDULE
COMPANY
DEPARTMENT
DATE
VENUE
HCL
CSC AND IT
20-04-2015
VELS UNIVERSITY
ZIFO TECHNOLOGIES
BME
21-04-2015
SNN
ASHOK LEYLAND
MECH
22-04-2015
JEPPIAR
Gallery.html
Result
PHOTO GALLARY
EX.No 3
Create a web page using XHTML for Library management system application
Library.html
LIBRARY MANAGEMENT SYSTEM
.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}
LIBRARY MANAGEMENT SYSTEM
SMK FOMRA INSTITUTE OF TECHNOLOGY
ADD BOOKs
ISSUES OF BOOK
BOOK DETAILS
REPORT
Add.html
ADD DETAILS
ADD BOOK
Title
Author
Year
ISBN
Date Purchased
Price
Issue.html
ISSUE DETAILS
ISSUES OF BOOK
BOOK NO
Student ID
Copies Available
Issue Date
Due Date
Price
Details.html
BOOK DETAILS
BOOK DETAILS
SEARCH BY BOOK NAME
SEARCH BY ISBN
SEARCH BY AUTHOR
Report.html
Result
REPORT
STUDENT NAME
STUDENT ID
TITLE
AUTHOR NAME
DATE OF ISSUE
DATE OF RETURN
PRABHU
CSC
HCL
PRABHU
CSC
HCL
SELVI
BME
ZIFO TECHNOLOGIES
PRABHU
CSC
HCL
OUTPUT
11Q11. 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.
AnswerStep 1 : create tables using following sql statementsCustomer
create table customer(cname varchar2(20),cid number(5));Accountcreate table account(cid number(5),ano number(5),atype varchar(2),balance number(5));Transactioncreate 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.
ProgramBankApplication.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","tiger");
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","3Kamal94");
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","3Kamal94");
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();
}
}
12Q12. 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","3Kamal94");
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();
}
}
13Q13. 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.
AnswerStep 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));
Branchcreate 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","3Kamal94");
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","3Kamal94");
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","3Kamal94");
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();
}
}
14Q14. 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
AnswerStep 1 : create tables using following sql statements
Customer
create table customer(cname varchar2(20),cid number(5));
Productscreate 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","3Kamal94");
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","3Kamal94");
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","3Kamal94");
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();
}
}
15Q15. 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));
Citycreate 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","scott","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","scott","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();
}
}
Recommended