Sie sind auf Seite 1von 38

Ex.

No: 1 Date :

/ 2007

Basic SQL Commands


AIM: To execute basic SQL commands in SQL server environment. ALGORITHM: Step 1: Start the program Step 2: The prompted Login-id and password (Oracle) once given, SQL> prompt appears and connected to the Oracle DBA. Now ready to access to PL/SQL commands and statement to DBA. Step 3: Execute various SQL commands in the SQL server environment. Step 4: Verify the output of each command and statements executed. Step 5: Print out with the necessary details.

OUTPUT: SQL>create table employee(empno number(3) primary key, empname varchar2(15), 2 addr varchar(20), dob date, mailid varchar2(25)); Table created. ----------------------------------------------------------------------------------------------------------SQL> desc employee; Name Null? Type -----------------------------------------------------------------------EMPNO NOT NULL NUMBER(4) EMPNAME VARCHAR2(15) ADDR VARCHAR2(20) DOB DATE MAILID VARCHAR2(25) ----------------------------------------------------------------------------------------------------------SQL> alter table employee modify empno number(6); Table altered. ----------------------------------------------------------------------------------------------------------SQL> insert into employee values(&empno,'&empname','&addr','&dob','&emailid'); Enter value for empno: 55 Enter value for empname: Radhika Enter value for addr: R.S.Puram,Chennai Enter value for dob: 12-NOV-85 Enter value for emailid: radhi@rediffmail.com old 1: insert into employee values(&empno,'&empname','&addr','&dob','&emailid') new 1: insert into employee values(55,'Radhika','R.S.Puram,Chennai','12-NOV-85','radhi@rediffmail. 1 row created. SQL> insert into employee values(143,'Shiva','Vadapalani,Chennai','26-SEP80','shivbp@hotmail.com'); 1 row created. ----------------------------------------------------------------------------------------------------------SQL> select * from employee; EMPNO EMPNAME ADDR DOB MAILID --------- --------------- -------------------- --------- ------------------------55 Radhika R.S.Puram,Chennai 12-NOV-85 radhi@rediffmail.com 101 Balaji Poes Garden,Chennai 15-NOV-85 balaji@gmail.com 48 Divya Jainagar,CBE 12-NOV-85 divya@yahoomail.com 143 Shiva Vadapalani,Chennai 26-SEP-80 shivbp@hotmail.com

SQL> select distinct(dob) from employee; DOB --------26-SEP-80 12-NOV-85 15-NOV-85 -----------------------------------------------------------------------------------------------------------SQL> delete from employee where empno=55; 1 row deleted. SQL> select * from employee; EMPNO EMPNAME ADDR DOB MAILID --------- --------------- -------------------- --------- ------------------------101 Balaji Poes Garden,Chennai 15-NOV-85 balaji@gmail.com 48 Divya Jainagar,CBE 12-NOV-85 divya@yahoomail.com 143 Shiva Vadapalani,Chennai 26-SEP-80 shivbp@hotmail.com SQL>update employee set empno=empno+3 where dob='12-NOV-85' 1 row updated. ---------------------------------------------------------------------------------------------------------SQL> select * from employee; EMPNO EMPNAME ADDR DOB MAILID --------- --------------- -------------------- --------- ------------------------101 Balaji Poes Garden,Chennai 15-NOV-85 balaji@gmail.com 51 Divya Jainagar,CBE 12-NOV-85 divya@yahoomail.com 143 Shiva Vadapalani,Chennai 26-SEP-80 shivbp@hotmail.com ---------------------------------------------------------------------------------------------------------SQL> select min(empno) from employee; MIN(EMPNO) ---------51 ---------------------------------------------------------------------------------------------------------SQL> select max(empno) from employee; MAX(EMPNO) ---------143 ---------------------------------------------------------------------------------------------------------SQL> select sum(empno) from employee; SUM(EMPNO) ---------295 3

---------------------------------------------------------------------------------------------------------SQL> select avg(empno) from employee; AVG(EMPNO) ---------98.333333 ---------------------------------------------------------------------------------------------------------SQL> select * from employee where empno>100 or dob='26-sep-80'; EMPNO EMPNAME ADDR DOB MAILID --------- --------------- -------------------- --------- ------------------------101 Balaji Poes Garden,Chennai 15-NOV-85 balaji@gmail.com 143 Shiva Vadapalani,Chennai 26-SEP-80 shivbp@hotmail.com ---------------------------------------------------------------------------------------------------------SQL> create view empview as select empno,addr,mailid from employee View created. SQL> select * from empview; EMPNO ADDR MAILID --------- -------------------- ------------------------101 Poes Garden,Chennai balaji@gmail.com 51 Jainagar,CBE divya@yahoomail.com 143 Vadapalani,Chennai shivbp@hotmail.com ---------------------------------------------------------------------------------------------------------SQL>commit; Commit complete. ---------------------------------------------------------------------------------------------------------SQL>

Ex. No: .2 Date : /

/ 2007

NORMALIZATION
AIM: To create database (table) and implement the normalization concept to the database in SQL server environment.

ALGORITHM: Step 1: Start the program Step 2: The prompted Login-id and password (Oracle) once given, SQL> prompt appears and connected to the Oracle DBA. Now ready to access to PL/SQL commands and statement to DBA. Step 3: Create table insert data into the table. Step 4: Create view table for implementing normalization concept. Step 5: Show the result of 1NF, 2NF and 3NF of the given database. Step 6: Print out with the necessary details.

OUTPUT: 0 NF Normal table without constraints CUSTOMER ORDER TABLE SQL> desc custord; Name Null? Type ----------------------------------------------------- -------- --------------CUSTNAME VARCHAR2(15) PRODNO NUMBER(4) PRODDESC VARCHAR2(15) QTY NUMBER(4) CUSTADDR VARCHAR2(20) DATEORD DATE ORDNO NUMBER(4)

SQL> select * from custord; CUSTNAME PRODNO PRODDESC QTY CUSTADDR DATEORD ORDNO --------------- --------- --------------- --------- -------------------- --------- --------------------Shobana 5 Chocolate 200 Ambur 29-MAR-83 5 Abi 459 Shirts 5 Vellore 16-JUN-00 15 Karan 256 Pen 2 Chennai 03-MAY-06 70 1 NF remove multi valued attributes Virtual view files created as customer(custname,custaddr) view files created as customer_order(custname,ordno,prodno,proddesc,qty,dateord) SQL> select * from customer; CUSTNAME CUSTADDR --------------- -------------------Shobana Ambur Abi Vellore Karan Chennai

SQL> select * from customer_order; CUSTNAME ORDNO PRODNO PRODDESC QTY DATEORD --------------- --------- --------- --------------- --------- --------Shobana 5 5 Chocolate 200 29-MAR-83 Abi 15 459 Shirts 5 16-JUN-00 Karan 70 256 Pen 2 03-MAY-06 6

2 NF remove partial dependencies Virtual view files created as customer(custname,custaddr) Virtual view created as order(custname,ordno) Virtual view files created as cust_order(ordno,prodno,proddesc,qty,dateord) SQL> select * from customer; CUSTNAME CUSTADDR --------------- -------------------Shobana Ambur Abi Vellore Karan Chennai SQL> select * from c_order; CUSTNAME ORDNO --------------- ----------------Shobana 5 Abi 15 Karan 70 SQL> select * from cust_order; ORDNO PRODNO PRODDESC QTY DATEORD --------------- --------- --------- --------------- --------- -------------------5 5 Chocolate 200 29-MAR-83 459 5 Shirts 5 16-JUN-00 70 256 Pen 2 03-MAY-06 3 NF remove transitive decencies Virtual view files created as customer(custname,custaddr) Virtual view created as order(custname,ordno) Virtual view files created as cust_order(ordno,prodno,qty,dateord) Virtual view file created as product(prodno, proddesc) SQL> select * from customer; CUSTNAME CUSTADDR --------------- -------------------Shobana Ambur Abi Vellore Karan Chennai SQL> select * from c_order; CUSTNAME ORDNO --------------- ----------------Shobana 5 7

Abi Karan

15 70

SQL> select * from ord_only; ORDNO PRODNO QTY DATEORD --------- --------- --------- --------------------------5 5 200 29-MAR-83 15 459 5 16-JUN-00 70 256 2 03-MAY-06 SQL> select * from product; PRODNO PRODDESC --------- --------------5 Chocolate 459 Shirts 256 Pen SQL> commit; Commit complete.

RESULT : Thus a database (table) was created and the normalization concept to the database in SQL server environment was implemented.

Ex. No : .3 Date : /

/ 2007

INVENTORY
AIM: To implement inventory control, create database (table) and develop PL/SQL procedure to demonstrate inventory record.

ALGORITHM: Step 1: Start the program Step 2: The prompted Login-id and password (Oracle) once given, SQL> prompt appears and connected to the Oracle DBA. Now ready to access to PL/SQL commands and statement to DBA. Step 3: Create table suitable for inventory. Step 4: Develop PL/SQL procedure and compile successfully.. Step 5: Take input from the user for the given database. Step 6: Print out with the necessary details.

SOURCE CODE: SQL> create table trans(bno number(3), bname varchar2(15),authu varchar2(15), nofca number(6),tamount number(6)); SQL> desc trans; Name Null? Type ----------------------------------------- -------- ---------------------------BNO NUMBER(3) BNAME VARCHAR2(15) AUTHU VARCHAR2(15) NOFCA NUMBER(6) TAMOUNT NUMBER(6) SQL> create table bookstock as select * from trans; Table created. SQL> desc bookstock; Name Null? Type ----------------------------------------- -------- ---------------------------BNO NUMBER(3) BNAME VARCHAR2(15) AUTHU VARCHAR2(15) NOFCA NUMBER(6) TAMOUNT NUMBER(6) SQL> ed Wrote file afiedt.buf 1 declare 2 b varchar2(15); 3 n number(4); 4 l number(4); 5 t number(10); 6 a number(4); 7 bookrec bookstock%rowtype; 8 cursor cur is select *from bookstock; 9 begin 10 l:=0; 11 open cur; 12 loop 13 fetch cur into bookrec; 14 exit when cur%notfound; 15 b:='&bname'; 16 if(bookrec.bname=b)then 17 l:=1; 18 n:=&no_of_copy_reqd; 19 if(bookrec.nofca>n)then 20 t:= bookrec.nofca-n; 21 a:=bookrec.tamount*n; 10

22 update bookstock set tamount=t where bname=b; 23 insert into trans values(bookrec.bno,b,bookrec.authu,n,a); 24 else 25 dbms_output.Put_line('Not available'); 26 end if; 27 end if; 28 end loop; 29 close cur; 30 if l=0 then 31 dbms_output.Put_line('Not available'); 32 end if; 33* end; SQL> / Enter value for bname: se old 15: b:='&bname'; new 15: b:='se'; Enter value for no_of_copy_reqd: 2 old 18: n:=&no_of_copy_reqd; new 18: n:=2; PL/SQL procedure successfully completed.

OUTPUT: SQL>Enter value for book_name: ansi old 15:b=&book_name; new 15:b=ansi; Enter value for no_of_copy_required: 2 New 15:n=2; PL/SQL procedure successfully completed. SQL> select *from trans; BNO BNAM AUTHU NOFCA TAMOUNT 100 ansi name 2 200

RESULT: Thus we implemented inventory control, created database (table) and developed PL/SQL procedure to demonstrate inventory record.

11

Ex. No : .4 Date : /

/ 2007

BANKING
AIM: To implement banking system, which allows users to operate deposit and Withdrawal of database account using PL/SQL. ALGORITHM: Step 1: Start the program Step 2: Create a table bank Step 3: Also define basic PL/SQL statements for Deposit, WithD, Delete Step 4: Execute the pl/sql such that it takes inputs from user Step 5: Develop the deposit, withdw & delete PL/SQL statements and execute one after another. Step 6: Now do some operations like deposit, withdraw on different pl/sql procurers then check its output. Step 7: Print out with the necessary details.

12

OUTPUT: SQL> create table bank(sbno1 number(3),name1 varchar2(15),addr1 varchar2(25),balance1 number(6),interest1 number(3),total1 number(6),depdate1 date,intdate1 date); Table created. -----------------------------------------------------------------------------------------------------------------------SQL> desc bank; Name Null? Type ----------------------------------------------------------------------------SBNO1 NUMBER(3) NAME1 VARCHAR2(15) ADDR1 VARCHAR2(25) BALANCE1 NUMBER(6) INTEREST1 NUMBER(4) TOTAL1 NUMBER(6) DEPDATE1 DATE INTDATE1 DATE ----------------------------------------------------------------------------------------------------------------------1 declare 2 sbno1 number(3); 3 name1 varchar2(15); 4 addr1 varchar2(15); 5 balance1 number(6); 6 interest1 number(4); 7 total1 number(6); 8 depdate1 date; 9 intdate1 date; 10 begin 11 sbno1:=&sbno1; 12 name1:='&name1'; 13 addr1:='&addr1'; 14 balance1:=&balance1; 15 depdate1:=sysdate; 16 interest1:=0; 17 total1:=balance1; 18 newacc(sbno1,name1,addr1,balance1,depdate1,interest1,total1,intdate1); 19* end; SQL> / Enter value for sbno1: 5 old 11: sbno1:=&sbno1; new 11: sbno1:=5; Enter value for name1: balaji old 12: name1:='&name1'; new 12: name1:='balaji'; Enter value for addr1: hyderabad old 13: addr1:='&addr1'; new 13: addr1:='hyderabad'; Enter value for balance1: 500 old 14: balance1:=&balance1; new 14: balance1:=500; PL/SQL procedure successfully completed. 13

-----------------------------------------------------------------------------------------------------------------------SQL> select * from bank; SBNO1 NAME1 ADDR1 BALANCE1 INTEREST1 TOTAL1 DEPDATE1 NTDATE1 1 bavana chennai 2000 0 2000 03-MAY-07 2 3 senthil bala bangalore 2000 chennai 2000 0 0 2000 2000 03-MAY-07 03-MAY-07

-----------------------------------------------------------------------------------------------------------------------1 create or replace procedure depositt(sbno2 number, balance2 number) is 2 balance number(6); 3 interest number(4); 4 total number(6); 5 begin 6 select balance1, interest1, total1 into balance, interest, total from bank where sbno1=sbno2; 7 balance:=balance+balance2; 8 interest:=(balance2*0.02); 9 total:=balance+interest; 10 update bank set balance1=balance where sbno1=sbno2; 11 update bank set interest1=interest where sbno1=sbno2; 12 update bank set total1=total where sbno1=sbno2; 13 update bank set intdate1=sysdate where sbno1=sbno2; 14 end; 15 . SQL> Procedure created. -----------------------------------------------------------------------------------------------------------------------SQL> 1 create or replace procedure withd(sbno2 number,balance2 number) is 2 totalwith number(6); 3 balancewith number(6); 4 interest1 number(4); 5 begin 6 select balance1, total1, interest1 into balancewith, interest1, totalwith from bank where sbno1 7 if(totalwith-balance2)>500 then 8 balancewith:=balancewith-balance2; 9 interest1:=(balancewith*0.02); 10 totalwith:=balancewith+interest1; 11 update bank set balance1=balancewith where sbno1=sbno2; 12 update bank set interest1=interest1 where sbno1=sbno2; 13 update bank set total1=totalwith where sbno1=sbno2; 14 update bank set intdate1=sysdate where sbno1=sbno2; 15 else 16 dbms_output.put_line('amount cant be withdrawn'); 17 end if; 18 end; 19 . SQL> / Procedure created. 14

-----------------------------------------------------------------------------------------------------------------------SQL> create or replace procedure delet(sbnod number) is 2 begin 3 delete from bank where sbno1=sbnod; 4 end; 5 . SQL> Procedure created. -----------------------------------------------------------------------------------------------------------------------SQL> 1 declare 2 balance2 number(6); 3 sbno2 number(3); 4 choice varchar2(18); 5 begin 6 sbno2:=&sbno2; 7 choice:='&choice'; 8 balance2:=&balance2; 9 if choice='deposit' then 10 depositt(sbno2,balance2); 11 end if; 12 if choice='withdraw' then 13 withd(sbno2, balance2); 14 end if; 15 if choice='delete' then 16 delet(sbno2); 17 end if; 18* end; SQL> / Enter value for sbno2: 2 old 6: sbno2:=&sbno2; new 6: sbno2:=2; Enter value for choice: deposit old 7: choice:='&choice'; new 7: choice:='deposit'; Enter value for balance2: 200 old 8: balance2:=&balance2; new 8: balance2:=200; PL/SQL procedure successfully completed. -----------------------------------------------------------------------------------------------------------------------SQL> / Enter value for sbno2: 3 old 6: sbno2:=&sbno2; new 6: sbno2:=3; Enter value for choice: withdraw old 7: choice:='&choice'; new 7: choice:='withdraw'; Enter value for balance2: 7800 old 8: balance2:=&balance2; new 8: balance2:=7800; PL/SQL procedure successfully completed. 15

-----------------------------------------------------------------------------------------------------------------------SQL> / Enter value for sbno2: 3 old 6: sbno2:=&sbno2; new 6: sbno2:=3; Enter value for choice: withdraw old 7: choice:='&choice'; new 7: choice:='withdraw'; Enter value for balance2: 400 old 8: balance2:=&balance2; new 8: balance2:=400; PL/SQL procedure successfully completed. ----------------------------------------------------------------------------------------------------------------------SQL> / Enter value for sbno2: 1 old 6: sbno2:=&sbno2; new 6: sbno2:=1; Enter value for choice: delete old 7: choice:='&choice'; new 7: choice:='delete'; Enter value for balance2: 0 old 8: balance2:=&balance2; new 8: balance2:=0; PL/SQL procedure successfully completed. -----------------------------------------------------------------------------------------------------------------------SQL> select * from bank; SBNO1 NAME1 2 senthil 3 4 5 bala dfdf balaji ADDR1 BALANCE1 INTEREST1 TOTAL1 DEPDATE1 INTDATE1 bangalore 2200 4 2204 03-MAY-07 03-MAY-07 chennai gdfgdfg hyderabad 2000 10 500 0 0 0 2000 10 500 03-MAY-07 03-MAY-07 03-MAY-07

----------------------------------------------------------------------------------------------------------------------SQL> RESULT: Thus banking system, which allows users to operate savings and checking account using PL/SQL statement executed successfully.

16

Ex. No : .5 Date : /

/ 2007

PAYROLL
AIM: To implement payroll system, create database (table) and develop PL/SQL procedure to demonstrate payroll database.

ALGORITHM: Step 1: Start the program Step 2: Create a table payrolldb & employeedb Step 3: Insert data into the employeedb table. Step 4: Develop the PL/SQL statements to calculate resulted payrolldb databces. Step 5: Take input from the user for the given payroll database. Step 6: Print out with the necessary details.

17

SOURCE CODE: SQL> create table payrolldb(ename varchar2(15),basic number(6),hra number(6),cca number(6),ded number(6),gross number(6),netpay number(6)); Table created. SQL> desc payrolldb; Name Null? Type ----------------------------------------- -------- ---------------------------ENAME VARCHAR2(15) BASIC NUMBER(6) HRA NUMBER(6) CCA NUMBER(6) DED NUMBER(6) GROSS NUMBER(6) NETPAY NUMBER(6) SQL> create table employeedb as select * from payrolldb; Table created. SQL> / PL/SQL procedure successfully completed. 1 declare 2 shra payrolldb.hra%type; 3 scca payrolldb.cca%type; 4 sded payrolldb.ded%type; 5 snetpay payrolldb.netpay%type; 6 sgross payrolldb.gross%type; 7 emprec employeedb%rowtype; 8 cursor emp_cursor is select * from employeedb; 9 begin 10 open emp_cursor; 11 loop 12 fetch emp_cursor into emprec; 13 exit when emp_cursor%notfound; 14 shra:=emprec.basic*.4; 15 scca:=emprec.basic*.2; 16 sgross:=emprec.basic+shra+scca; 17 sded:=emprec.basic*.1; 18 snetpay:=sgross-sded; 19 insert into payrolldb values(emprec.ename,emprec.basic,shra,scca,sded,sgross,snetpay); 20 end loop; 21 commit work; 22* end; SQL> / PL/SQL procedure successfully completed. SQL> / 18

PL/SQL procedure successfully completed. SQL> desc employeedb; Name Null? Type ----------------------------------------- -------- ---------------------------ENAME VARCHAR2(15) BASIC NUMBER(6) HRA NUMBER(6) CCA NUMBER(6) DED NUMBER(6) GROSS NUMBER(6) NETPAY NUMBER(6) SQL> insert into employeedb values('&ename',&basic,&hra,&cca,&ded,&gross,&netpay); Enter value for ename: MANI Enter value for basic: 10000 Enter value for hra: 4000 Enter value for cca: 2000 Enter value for ded: 1000 Enter value for gross: 16000 Enter value for netpay: 15000 old 1: insert into employeedb values('&ename',&basic,&hra,&cca,&ded,&gross,&netpay) new 1: insert into employeedb values('MANI',10000,4000,2000,1000,16000,15000) 1 row created. SQL> / Enter value for ename: BALAMURUGAN Enter value for basic: 18000 Enter value for hra: 6000 Enter value for cca: 4000 Enter value for ded: 2000 Enter value for gross: 30000 Enter value for netpay: 25000 old 1: insert into employeedb values('&ename',&basic,&hra,&cca,&ded,&gross,&netpay) new 1: insert into employeedb values('BALAMURUGAN',18000,6000,4000,2000,30000,25000) 1 row created. SQL> / Enter value for ename: SENTHIL KUMAR Enter value for basic: 8000 Enter value for hra: 6000 Enter value for cca: 4000 Enter value for ded: 1000 Enter value for gross: 18000 Enter value for netpay: 15000 old 1: insert into employeedb values('&ename',&basic,&hra,&cca,&ded,&gross,&netpay) new 1: insert into employeedb values('SENTHIL KUMAR',8000,6000,4000,1000,18000,15000) 1 row created. 19

SQL> declare 2 shra payrolldb.hra%type; 3 scca payrolldb.cca%type; 4 sded payrolldb.ded%type; 5 snetpay payrolldb.netpay%type; 6 sgross payrolldb.gross%type; 7 emprec employeedb%rowtype; 8 cursor emp_cursor is select * from employeedb; 9 begin 10 open emp_cursor; 11 loop 12 fetch emp_cursor into emprec; 13 exit when emp_cursor%notfound; 14 shra:=emprec.basic*.4; 15 scca:=emprec.basic*.2; 16 sgross:=emprec.basic+shra+scca; 17 sded:=emprec.basic*.1; 18 snetpay:=sgross-sded; 19 insert into payrolldb values(emprec.ename,emprec.basic,shra,scca,sded,sgross,snetpay); 20 end loop; 21 commit work; 22 end; 23 . SQL> / PL/SQL procedure successfully completed. SQL> SELECT * FROM EMPLOYEEDB; ENAME BASIC HRA CCA DED GROSS NETPAY ----------------------------------------------------------------------------------------------------------MANI 10000 4000 2000 1000 16000 15000 BALAMURUGAN 18000 6000 4000 2000 30000 25000 SENTHIL KUMAR 8000 6000 4000 1000 18000 15000

SQL> SELECT * FROM PAYROLLDB; ENAME BASIC HRA CCA DED GROSS NETPAY ----------------------------------------------------------------------------------------------------------MANI 10000 4000 2000 1000 16000 15000 BALAMURUGAN 18000 7200 3600 1800 28800 27000 SENTHIL KUMAR 8000 3200 1600 800 12800 12000 RESULT: Thus payroll system was implemented, database (table) was created and PL/SQL Procedure was developed to demonstrate payroll database.

20

Ex. No: 6 Date :

/ 2007

Web Page Creation Using Form Controls


AIM : To implement web page information, develop HTML program to required web page form. ALGORITHM: Step 1: Start the program Step 2: Open appropriate software to develop html code. Step 3: Develop a HTML and DHTML program for required web page. Step 4: Design a web page format to accept user purchase details. Step 5: Take input from the user for the given web page. Step 6: Print out with the necessary details.

21

SOURCE CODE: <html> <head> <title>Order form</title> <h2 align="center">Designing a web Page using HTML, DHTML and Client-side Script</h2> <style> #a {color:green;font-size:25;text-decoration:underline} .a {color:red;font-size:15;font-style:italic} </style> <Script Language="JavaScript"> function rate_display() { if(frm.book.options[0].selected) document.frm.ratetxt.value = "$" else if(frm.book.options[1].selected) document.frm.ratetxt.value = "250" else if(frm.book.options[2].selected) document.frm.ratetxt.value = "500" else if(frm.book.options[3].selected) document.frm.ratetxt.value = "150" else if(frm.book.options[4].selected) document.frm.ratetxt.value = "100" else if(frm.book.options[5].selected) document.frm.ratetxt.value = "130" else if(frm.book.options[6].selected) document.frm.ratetxt.value = "170" } function tot_price() { var rt, nofbooks, totamt rt = parseInt(frm.qty.options[frm.qty.selectedIndex].value) nofbooks = parseInt(document.frm.ratetxt.value) totamt = rt * nofbooks document.frm.totxt.value = totamt } </Script> </head> <body> <h1 id="a" align="center">Welcome to Online Book Shopping</h1> <h2 class="a">Select the name of the book first, </h2> <h2 class="a">then Select the number of copies per each book</h2> <br><br><br> 22

<form name="frm"> <table align="center"> <tr> <td> <b>Book Name</b></td> <td> <b>Quantity</b></td> <td> <b>Rate per one book</b></td> </tr> <tr> <td> <select name="book" size="1" onChange=rate_display()> <option value="c1">----select a book------ </option> <option value="c1">Java Complete Reference</option> <option value="c2">Professional JSP</option> <option value="c3">HTML in 21 days</option> <option value="c4">Computer Networks</option> <option value="c5">Computer Architecture</option> <option value="c6">Compiler Design</option> </select> </td> <td> <select name="qty" size="1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </td> <td> <input type="text" name="ratetxt" size=12 value="Rate in Dollars"> </td> </tr> </table> <br> <center> <input type="button" value ="Calculate Total Amount" onClick=tot_price()> Total Price: <input type="text" name="totxt" size=7 value=$ > </center> </form> </body> </html>

23

OUTPUT:

RESULT: Thus a web page was designed using HTML, DHTML and Client side Script (JavaScript)..

24

Ex. No : .7 Date : /

/ 2007

Date Time Server


AIM: To implement Date and Time server which would give current date and time to the requesting client program using JAVA.

ALGORITHM: Step 1: Start the program Step 2: Create a server using ServerSocket also define the port which listens for client request. Step 3: When request arrived, send the current date and time to the client using Socket. Step 4: Similarly, create client using ServerSocket and a port through which it receives the response from the server. Step 5: When request arrived at client, read the arrived date and time, and display the output. Step 6: Now terminate both client and server program.

25

SOURCE CODE: Server import java.net.*; import java.io.*; import java.util.*; public class DateServer { public static void main(String ars[]) throws UnknownHostException,IOException { ServerSocket ss=new ServerSocket(2000); Socket s=ss.accept(); OutputStream os = s.getOutputStream(); PrintStream pw=new PrintStream(os); Date d=new Date(); pw.println(d); } }

Client import java.net.*; import java.io.*; public class DateClient { public static void main(String ars[]) throws UnknownHostException,IOException { Socket s=new Socket(InetAddress.getLocalHost(),2000); InputStream is = s.getInputStream(); DataInputStream dis1=new DataInputStream(is); try { String s1=dis1.readLine(); System.out.println("Today's Date and current Time in server is: "); System.out.println(s1); } catch(Exception e){} } }

26

OUTPUT:

RESULT: Thus a program to implement Date and Time server which would give current date and time to the requesting client program using JAVA was executed successfully. 27

Ex. No : .8 Date : /

/ 2007

JAVA DATABASE CONNECTIVITY


AIM: To access the student details stored in a database using JDBC connectivity in java

ALGORITHM: Step 1: Start the program Step 2: Create a Java program, then define the JDBC connectivity using Class and connection. Step 3: Crate databases screen like ADD, DELETE, PREV & NEXT using HTML code and access data from the user. Step 4: Now create a query using execute query statement. Step 5: The result set is stored in a ResultSet object. Step 6: Take input from the user for the given web page. Step 7: Print out with the necessary details.

28

SOURCE CODE import java.sql.*; public class Database1 { public static void main(String arg[]) throws Exception { String query ="select * from emp"; System.out.println("The Query is: "+ query + "\n"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:empdsn","",""); Statement sm=con.createStatement(); ResultSet rs=sm.executeQuery(query); System.out.println("ENO\t\t"+"ENAME\t\t"+"SALARY"); while(rs.next()) { System.out.println(rs.getInt("Eno")+"\t\t"+rs.getString("Ename")+"\t\t"+ rs.getFloat("sal")); } sm.close(); con.close(); } catch(Exception e){} } }

29

OUTPUT:

RESULT : Thus the student details stored in a database were accessed using JDBC connectivity in java

30

Ex. No : .9 Date : /

/ 2007

JSP Program for Order Processing AIM: To implement order processing using a JSP program. ALGORITHM: 1. Design a web page for view and place order to a particular company. 2. Provide the link get the stock details of the particular company. 3. Get the stock details from database using JSP program 4. Display the stock details of the company after enabling the link. 5. Place the order for the particular product. 6. Process the order using JSP program, which satisfies necessary condition (Invalid item, insufficient qty etc). 7. Display the final messages

31

SOURCE CODE: Link1.html <HTML> <HEAD> <TITLE></TITLE> </HEAD> <P align=center><FONT color=maroon><STRONG>ABC COMPANY</STRONG> </FONT></P> <A HREF="http://localhost/stock.jsp"><center>VIEW STOCK DETAILS </center></A><BODY bgColor=lavender> <FORM action="http://localhost/order.jsp" id=FORM1 method=post name=FORM1> <P>&nbsp;</P> <P align=center><FONT color=crimson>PLACE ORDER</FONT></P> <P>&nbsp; ITEM NO<INPUT id=text1 name=text1></P> <P>QTY <INPUT id=text2 name=text2></P> <P><INPUT id=submit1 name=submit1 type=submit value=Submit></P></FORM> </BODY> </HTML> stock.jsp <%@ page import="java.sql.*" %> <%! Connection con; ResultSet rs; Statement st; %> <% try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:example1","",""); } catch (Exception e) { System.out.println("exception"); } %> <% st=con.createStatement(); rs=st.executeQuery("Select * from johnson"); out.println("<bold><center>ABC COMPANY<center></bold>"); out.println("<br><br>STOCK DETAILS<br>"); out.println("<table border=5 bgcolor=yellow>");

32

while(rs.next()) { out.println("<tr><td>"+rs.getInt(1)); out.println("<td>"+rs.getString(2)); out.println("<td>"+rs.getInt(3)); out.println("<td>"+rs.getInt(4)+"</tr>"); } out.println("</table>"); out.println("<br><br><a href=http://localhost/link1.html>Back to purchase form</a>"); %> order.jsp <html> <head> <title></title> </head> <body bgcolor=megenta"> <%@ page import="java.sql.*"%> <%! Connection con=null; String s1=null; String s2=null; String s3=null; int k1,k2; Statement stmt=null; ResultSet rs=null;

%> <% try{ s1=request.getParameter("text1"); s2=request.getParameter("text2"); k1=Integer.parseInt(s1); k2=Integer.parseInt(s2); if(k2==0) out.println("Qty should not be zero"); else { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:example1","",""); stmt=con.createStatement(); rs=stmt.executeQuery("select * from johnson where itemno="+k1); int count=0; while(rs.next()) { count++; String ss=rs.getString(2); int ii=rs.getInt(4); int tot=(ii*k2); 33

if(rs.getInt(3)>=k2) { stmt.executeUpdate("update johnson set qty=qty-"+k2+" where itemno="+k1); out.println("Thank you for purchasing.The order will be delivered in 2 days"); out.println("<br>The ITEM NO : "+k1); out.println("<br>The PRODUCT NAME : "+ss); out.println("<br>The Qty Placed : "+k2); out.println("<br>The RATE PER QTY Rs.: "+ii); out.println("<br>The ToTAL PRICE IS Rs.: "+tot); } else out.println("Required Stock is not available"); } if(count==0) out.println("Invalid Item"); } } catch(Exception e) { System.out.println(e); } %> </body></html>

34

OUTPUT:

RESULT: Thus JSP program is implemented to process the order. 35

Ex. No: 10 Date : /

/ 2007

ASP Component
AIM: To create a Browser component using ASP.

ALGORITHM: Step 1 : Open an ASP file Step 2 : Declare the script language as VBScript Step 3 : Create a built-in object called BrowserType Step 4 : Use the BrowserType object and display all browser properties

36

SOURCE CODE:

<%@ Language=VBScript %> <% Dim B Set B = Server.CreateObject("Mswc.BrowserType") Response.Write "<h3>" Response.Write "Name :" & B.Browser & "<br>" Response.Write "Version :" & B.Version & "<br>" Response.Write "Support Frames :" & B.Frames & "<br>" Response.Write "Support Tables :" & B.Tables & "<br>" Response.Write "Support Cookies :" & B.Cookies & "<br>" Response.Write "Support Java :" & B.JavaApplets & "<br>" Response.Write "Support ActiveX :" & B.ActiveXControls & "<br>" Response.Write "Support Vbscript :" & B.VBScript & "<br>" Response.Write "Support JavaScript :" & B.JavaScript & "<br>" Response.Write "Supports BackgroundSound :" & B.BackgroundSounds & "<br>" Response.Write "Supports Background :" & B.Background & "<br>" %>

37

OUTPUT:

RESULT: Thus a browser component was created to demonstrate an ASP component.

38

Das könnte Ihnen auch gefallen