· 6 years ago · Mar 15, 2019, 02:34 AM
1slip_1
2
3Slip 1 : Write a JSP script to accept username, store it into the session, compare it with
4password in another jsp file, if username matches with password then display appropriate
5message in html file.
6
7Slip1_checklogin.jsp
8
9<%@page contentType="text/html" pageEncoding="UTF-8"%>
10<!DOCTYPE html>
11<%
12String username = request.getParameter("username");
13String password = request.getParameter("password");
14out.println("Checking login<br>");
15if (username == null || password == null) {
16out.print("Invalid paramters ");
17}
18// Here you put the check on the username and password
19if (username.toLowerCase().trim().equals("admin")&&
20password.toLowerCase().trim().equals("admin")) {
21out.println("Welcome " + username + " <a href=\"Slip1.jsp\">Back to main</a>");
22session.setAttribute("username", username);
23}
24else
25{
26out.println("Invalid username and password");
27}
28%>
29Slip1.jsp
30<%@page contentType="text/html" pageEncoding="UTF-8"%>
31<!DOCTYPE html>
32<HTML>
33<HEAD>
34<TITLE>Login using jsp</TITLE>
35</HEAD>
36<BODY>
37<H1>LOGIN FORM</H1>
38<%
39String myname = (String)session.getAttribute("username");
40if(myname!=null)
41{
42out.println("Welcome "+myname+" , <a href=\"Slip1_logout.jsp\" >Logout</a>");
43}
44else
45{
46%>
47<form action="Slip1_checkLogin.jsp">
48<table>
49<tr>
50<td> Username : </td><td><input name="username" size=15 type="text"
51/></td>
52</tr>
53<tr>
54<td> Password : </td><td><input name="password" size=15
55type="password" /></td>
56</tr>
57</table>
58<input type="submit" value="login" />
59</form>
60<%
61}
62%>
63</BODY>
64</HTML>
65Slip1_logout.jsp
66<%@page contentType="text/html" pageEncoding="UTF-8"%>
67<!DOCTYPE html>
68<%
69String username=(String)session.getAttribute("username");
70if(username!=null)
71{
72out.println(username+" loged out, <a href=\"Slip1.jsp\">Back</a>");
73session.removeAttribute("username");
74}
75else
76{
77out.println("You are already not login <a href=\"Slip1.jsp\">Back</a>");
78}
79%>
80
81
82q1---------------------
83
84SLIP 1: Write a java program to display IP Address and Name of client machine.
85
86SERVER:
87import java.io.*;
88import java.net.*;
89class S_Slip1_1
90{
91public static void main(String a[]) throws Exception
92{
93ServerSocketss = new ServerSocket(1000);
94System.out.println("Server is waiting for client : ");
95Socket s =ss.accept();
96System.out.println("Client is connected");
97}
98}
99CLIENT:
100import java.io.*;
101import java.net.*;
102class C_Slip1_1
103{
104public static void main(String a[]) throws Exception
105{
106Socket ss = new Socket("localhost",1000);
107System.out.println("IP Address = "+ss.getInetAddress());
108System.out.println("Client port = "+ss.getPort());
109}
110}
111
112q1------
113
114SLIP 1: Write a java program to display IP Address and Name of client machine.
115
116SERVER:
117import java.io.*;
118import java.net.*;
119class S_Slip1_1
120{
121public static void main(String a[]) throws Exception
122{
123ServerSocketss = new ServerSocket(1000);
124System.out.println("Server is waiting for client : ");
125Socket s =ss.accept();
126System.out.println("Client is connected");
127}
128}
129CLIENT:
130import java.io.*;
131import java.net.*;
132class C_Slip1_1
133{
134public static void main(String a[]) throws Exception
135{
136Socket ss = new Socket("localhost",1000);
137System.out.println("IP Address = "+ss.getInetAddress());
138System.out.println("Client port = "+ss.getPort());
139}
140}
141
142
143---------------------------------------------------------------------------------------------------------------
144slip_2
145
146
147q1
148
149SLIP 2: Write a multithreading program in java to display all the vowels from a given String.
150
151import java.util.*;
152import java.io.*;
153class Slip2_1 extends Thread
154{
155String s1;
156Slip2_1(String s)
157{
158s1=s;
159start();
160}
161public void run()
162{
163System.out.println("Vowels are ");
164for(int i=0;i<s1.length();i++)
165{
166char ch=s1.charAt(i);
167if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
168System.out.print(" "+ch);
169}
170}
171public static void main(String a[]) throws Exception
172{
173DataInputStreamReader di = new DataInputStreamReader(System.in);
174System.out.println("Enter a string");
175String str=di.readLine();
176Slip2_1 s=new Slip2_1(str);
177}
178}
179
180
181q2
182
183
184SLIP 2 :
185Write a servlet which counts how many times a user has visited a web page. If the user is
186visiting the page for the first time, display a welcome message. If the user is revisiting the
187page, display the number of times visited. (Use cookies)
188
189import java.io.*;
190import javax.servlet.*;
191import javax.servlet.http.*;
192public class slip2 extends HttpServlet
193{
194public void doGet(HttpServletRequest req, HttpServletResponse res)
195throws ServletException,IOException
196{
197res.setContentType("text/html");
198PrintWriter out = res.getWriter();
199Cookie c[]=req.getCookies();
200if(c==null)
201{
202Cookie cookie = new Cookie("count","1");
203res.addCookie(cookie);
204out.println("<h3>Welcome Servlet<h3>"+ "slip2:<b>1</b>"); }
205else
206{
207int val=Integer.parseInt(c[0].getValue())+1; c[0].setValue(Integer.toString(val));
208res.addCookie(c[0]);
209out.println("slip2:<b>"+val+"</b>");
210}
211}
212}
213
214
215q3
216
217
2182. A college has given roll number to each student, The roll number is six digit number where first two digits are faculty(B.Sc., BCA, BA) third digit is year (Ist(1), IInd(2) and IIIrd(3)) and last three digit are actual number. Write PHP script to accept a number and print faculty, year and roll number of student
219
220<html>
221<body>
222<form action="Q2.php" method='get'>
223<table>
224<tr>
225<td>Enter Your Roll No. </td><td><input type=text name=roll_no placeholder="ex. 112001"><input type=Submit value="Submit"></td>
226</tr>
227<tr>
228<td></td><td><font color="red" size="2">
229format of Roll No: first two digits is 11 for B.sc.,
230 12 for Bcom,
23113 for BA<br>third digit
232 1/2/3 for respective year<br>last three are for actual roll no.</font></td>
233</tr>
234</table>
235</form>
236</body>
237</html>
238
239Phpfile :
240
241<?php
242$roll_no=$_GET['roll_no'];
243echo "Your Roll Number Is :$roll_no<br>";
244$fac=substr($roll_no,0,2);
245if($fac==11)
246echo "Faculty is B.Sc<br>";
247else if($fac==12)
248echo "Faculty is Bcom<br>";
249else if($fac==13)
250echo "Faculty is BA<br>";
251
252$year=substr($roll_no,2,1);
253if($year==1)
254echo "Year is First Year<br>";
255else if($year==2)
256echo "Year is Second Year<br>";
257else if($year==3)
258echo "Year is Third Year<br>";
259echo "Your Roll No. is".substr($roll_no,3)."<br>";
260
261?>
262
263
264q4
265
2662. Define an interface which has methods area(), volume(). Define constant PI. Create a
267class cylinder which implements this interface and calculate area and volume. (Use define())
268html file :
269
270<html>
271<body bgcolor="gold">
272<center>
273<h2> Calculate area and value of cylinder</h2>
274<form action="slip_2.php" method="GET">
275<h3> Enter radius : <input type=text name=r><br></h3>
276<h3> Enter height : <input type=text name=h><br><br></h3>
277<input type=submit value=submit name=Show>
278<input type=reset value=Reset name=Reset>
279</form>
280</center>
281</body>
282</html>
283
284Phpfile :
285<?php
286$r = $_GET['r'];
287$h = $_GET['h'];
288define('PI','3.14');
289interface cal
290{
291function area($r,$h);
292function vol($r,$h);
293}
294class cylinder implements cal
295{
296function area($r,$h)
297 {
298 $area = 2*PI*$r*($r+$h);
299echo "<h3>The area of cylinder is :$area</h3>";
300 }
301function vol($r,$h)
302 {
303 $vol = PI*$r*$r*$h;
304echo "<h3>The volume of cylinder is :$vol</h3>";
305 }
306}
307$c = new cylinder;
308 $c->area($r,$h);
309 $c->vol($r,$h);
310?>
311
312
313
314-----------------------------------------------------------------------------------------------------------------------------------------------
315
316slip_3
317
318
319q1
320
321SLIP 3: Write a JDBC program to display the details of employees (eno, ename, department,
322sal) whose department is “Computer Scienceâ€.
323
324import java.sql.*;
325import java.io.*;
326public class Slip3_1
327{
328public static void main(String args[])thorws IOException
329{
330Connection con;
331try
332{
333Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
334con=DriverManager.getConnection("jdbc:odbc:dsn");
335if(con==null)
336{
337System.out.println("Connection Failed....");
338System.exit(1);
339}
340System.out.println("Connection established...");
341
342Statement stmt=con.createStatement();
343ResultSet rs=stmt.executeQuery("select * From employee Where dept='computer science'");
344System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
345while(rs.next())
346
347{
348System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+""+rs.getInt(4));
349}
350con.close();
351rs.close();
352stmt.close();
353}
354catch(Exception e)
355{
356System.out.println(e);
357}
358}
359}
360
361
362
363q2 ----------
364
365Slip 3 :Write a java program to simulate traffic signal using multithreading.
366
367Slip3_2.java
368
369import java.applet.*;
370import java.awt.*;
371/*<applet code="Slip3_2.java" height="600" width="500">*/
372
373class Slip3_2 extends Applet implements Runnable
374{
375 Thread t;
376 int r,g,y,i;
377 public void init()
378 {
379 r=0; g=0; y=0;
380 t=new Thread(this);
381 t.start();
382 }
383 public void run()
384 {
385 try
386 {
387 for(i=24;i>=1;i--)
388 {
389 t.sleep(100);
390 if(i>=16 && i<24)
391 {
392 g=1;
393 repaint();
394 }
395 if(i>=8 && i<16)
396 {
397 y=1;
398 repaint();
399 }
400 if(i>=1 && i<8)
401 {
402 r=1;
403 repaint();
404 }
405 }
406 if(i==0)
407 {
408 run();
409 }
410 }
411 catch(Exception e)
412 {}
413 }
414 public void paint(Graphics g)
415 {
416 g.drawOval(100,100,100,100);
417 g.drawOval(100,225,100,100);
418 g.drawOval(100,350,100,100);
419 g.drawString("start" 200,200);
420 if(r==1)
421 {
422 g.setColor(color.red);
423 g.fillOval(100,100,100,100);
424 g.drawOval(100,100,100,100);
425 r=0;
426
427 g.drawString("stop" 200,200);
428 if(g==1)
429 {
430 g.setColor(color.green);
431 g.fillOval(100,225,100,100);
432 g.drawOval(100,225,100,100);
433 g=0;
434 if(y==1)
435 {
436 g.drawString("slow" 200,200);
437 g.setColor(color.yellow);
438 g.fillOval(100,350,100,100);
439 g.drawOval(100,350,100,100);
440 y=0;
441 }
442 }
443}
444
445
446
447
448
449q3----------------
450
451
4523. Write a PHP script to demonstrate the introspection for examining class(use function get_declared_classes() ,get_class_methods() and get_class_vars()).
453
454Phpfile :
455<?php
456class intro
457{
458var $i;
459function f1() {}
460function f2() {}
461}
462class intro_1 extends intro
463{
464var $j,$k;
465function f3() {}
466function f4() {}
467}
468echo class_exists('intro'); //returns true if class is exist
469var_dump(get_declared_classes()); //returns an array of all the class are define & declared in php including classes name
470var_dump(get_class_methods('intro_1')); //returns an array of methods in class intro_1
471var_dump(get_class_methods('Exception')); //returns an array of methods in class Exception
472var_dump(get_class_vars('intro_1')); //returns parent class of given class intro_1 if it is exists
473var_dump(get_parent_class('intro_1')); //reurns parent class of given class if it exist
474var_dump(get_object_vars($ob)); //retuns an array of parameter / variables for given object
475?>
476
477
478
479q4-------------
480
481
4823. Derive a class square from class Rectangle. Create one more class circle. Create an interface with only one method called area (). Implement this interface in all the classes. Include appropriate data members and constructors in all classes. Write a program to accept details of a square, circle and rectangle and display the area.
483Html file :
484
485<html>
486<body>
487<form action="slip_3.php" method="get">
488<h2> Square : </h2>
489Enter side for Square : <input type="text" name=s>
490<h2> Rectangle : </h2>
491Enter length :<input type="text" name=l><br>
492Enter breath : <input type="text" name=b>
493<h2> Circle : </h2>
494Enter radius : <input type="text" name=r><br>
495<input type="submit" name=submit value=Submit>
496<input type="reset" name=reset value=reset>
497</form>
498</body>
499</html>
500
501Phpfile :
502<?php
503$s = $_GET['s'];
504$l = $_GET['l'];
505$b = $_GET['b'];
506$r = $_GET['r'];
507interface findarea
508{
509function area($l,$c);
510}
511class rectangle implements findarea
512{
513function area($l,$b)
514 {
515 $area = $l*$b;
516echo "Area of Rectanle :".$area."<br>";
517 }
518}
519class square extends rectangle
520{
521function area($s,$s)
522 {
523 $area = $s*$s;
524echo "Area of Square :". $area."<br>";
525 }
526}
527class circle
528{
529function area($r)
530 {
531 $area = 0.5*$r*$r;
532echo "Area of Circle :". $area."<br>";
533 }
534}
535$fr = new rectangle;
536$fr->area($l,$b);
537$fs = new square;
538$fs->area($s,$s);
539$fc = new circle();
540$fc->area($r)
541?>
542
543
544------------------------------------------------------------------------------------------------------------------------------
545
546slip_4
547
548
549
550q1
551
552SLIP 4:
553Write a java program to display “Hello Java†message n times on the screen. (Use Runnable
554Interface).
555public class Slip4 implements Runnable
556{
557int i,no;
558Slip4(int n)
559{
560no = n;
561}
562public void run()
563{
564for(i = 1; i<=no; i++)
565{
566System.out.println("\nHello Java");
567try
568{
569Thread.sleep(50);
570}
571catch(Exception e)
572{
573System.out.println(e);
574}
575}
576}
577
578public static void main(String args[])
579{
580try
581{
582int n;
583System.out.println("\nEnter Number : ");
584BufferedReaderbr = new BufferedReader(new InputStreamReader(System.in));
585String s = br.readLine();
586n = Integer.parseInt(s);
587Thread t = new Thread(new Slip4(n));
588t.start();
589}
590catch(Exception e)
591{
592
593}
594}
595}
596
597
598q2-------------
599Slip 4 : Write a JSP program to create a shopping mall. User must be allowed to do
600purchase from two pages. Each page should have a page total. The third page should
601display a bill, which consists of a page total of whatever the purchase has been done and
602print the total.
603Slip4_first.jsp
604
605<%@page contentType="text/html" pageEncoding="UTF-8"%>
606<!DOCTYPE html>
607<html>
608<head>
609
610<title>JSP Page</title>
611</head>
612<body>
613<form action="Slip4_Second.jsp" method="post">
614<h1>Shopping Mall</h1>
615Rice :
616<select name="rice">
617<option value="2">2 Kg</option>
618<option value="5">5 Kg</option>
619<option value="10">10 Kg</option>
620<option value="15">15 Kg</option>
621</select>
622Wheat :
623<select name="wheat">
624<option value="2">2 Kg</option>
625<option value="5">5 Kg</option>
626<option value="10">10 Kg</option>
627<option value="15">15 Kg</option>
628</select>
629<input type="submit" value="Submit">
630</form>
631</body>
632</html>
633
634Slip4_Second.jsp
635<%@page contentType="text/html" pageEncoding="UTF-8"%>
636<!DOCTYPE html>
637<%
638String rice = request.getParameter("rice");
639int r = Integer.parseInt(rice);
640String wheat = request.getParameter("wheat");
641int w = Integer.parseInt(wheat);
642int tr = r * 40;
643int wt = w * 60;
644int pt = tr + wt;
645session.setAttribute("first_Total", pt);
646%>
647<html>
648<head>
649<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
650<title>JSP Page</title>
651</head>
652<body>
653<h1>Shopping Mall</h1>
654<form action="Slip4_Third.jsp" method="post">
655Maggi :
656<select name="maggi">
657<option value="1">1</option>
658<option value="2">2</option>
659<option value="3">3</option>
660<option value="4">4</option>
661<option value="5">5</option>
662</select>
663Good Day :
664<select name="good">
665<option value="1">1</option>
666<option value="2">2</option>
667<option value="3">3</option>
668<option value="4">4</option>
669<option value="5">5</option>
670</select>
671<input type="submit" value="Submit">
672</form>
673</body>
674</html>
675Slip4_Third.jsp
676<%@page contentType="text/html" pageEncoding="UTF-8"%>
677<!DOCTYPE html>
678<%
679String m = request.getParameter("maggi");
680String g = request.getParameter("good");
681int mp = Integer.parseInt(m);
682int gp = Integer.parseInt(g);
683int mpt = mp * 10;
684int gpt = gp * 10;
685int secont_total = mpt + gpt;
686int first_Total = (Integer)request.getSession().getAttribute("first_Total");
687NR CLASSES, PUNE (8796064387/90)
688int grand_Total = first_Total + secont_total;
689%>
690<html>
691<head>
692<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
693<title>JSP Page</title>
694</head>
695<body>
696<h1>Shopping Mall</h1>
697<h1>First Page Total <%=first_Total%></h1><br>
698<h1>Second Page Total <%=secont_total%></h1><br>
699<h1>Total Bill<%=grand_Total%></h1><br>
700</body>
701</html>
702
703
704q3-----------------
705
7064. Write a Calculator class that can accept two values, then add them, subtract them, multiply them together, or divide them on request. For example:
707$calc = new Calculator( 3, 4 );
708echo $calc- >add(); // Displays “7â€
709echo $calc- >multiply(); // Displays “12â€
710
711
712
713html file :
714<html>
715<body>
716<form action="slip_4_Q3.php" method=get>
717<center>
718<table>
719<tr><td>Enter No1</td><td><input type="text" name="a"></td></tr>
720<tr><td>Enter No2</td><td><input type="text" name="b"></td></tr>
721<tr><td></td><td><input type="submit" value="SUBMIT"></td></tr>
722</table>
723</center>
724</form>
725</body>
726</html
727php file :
728<?php
729class Calculate
730 {
731public $a;
732public $b;
733
734function __construct($a,$b)
735 {
736 $this->a=$a;
737 $this->b=$b;
738 }
739public function add()
740 {
741 $c=$this->a+$this->b;
742echo"Addition = $c<br>";
743 }
744public function subtract()
745 {
746 $c=$this->a-$this->b;
747echo"Subtract = $c<br>";
748 }
749public function multiply()
750 {
751 $c=$this->a*$this->b;
752echo"Multiplication = $c<br>";
753 }
754public function div()
755 {
756 $c=$this->a/$this->b;
757echo"Division = $c";
758 }
759 }
760$x=$_GET['a'];
761$y=$_GET['b'];
762$calc=new Calculate($x,$y);
763$calc->add();
764$calc->subtract();
765$calc->multiply();
766$calc->div();
767
768?>
769
770
771q4-----------
772
773
7744. Create a login form with a username and password. Once the user logs in, the second form should be displayed to accept user details (name, city, phoneno). If the user doesn’t enter information within a specified time limit, expire his session and give a warning otherwise Display Details($_SESSION)
775Html file :
776
777<html>
778<body>
779<form action="slip_4-1.php" method="post">
780<center>
781<h2> Enter Username : <input type="text" name="name"></h2>
782<h2> Enter Password : <input type="text" name="pwd"></h2>
783<input type="submit" value="Login">
784</center>
785</form>
786</body>
787</html>
788
789Phpfile :
790slip_4-1.php :
791<?php
792session_start();
793$t=date("1,d-m-y h:i:s",time()+20);
794if($_REQUEST['name']=='xyz’ && $_REQUEST['pwd']=='xyz')
795{
796 ?>
797<html>
798<body>
799<h1><u><center>enter ur details</center></u></h1>
800<form action="slip_4-2.php" method=get>
801<input type='hidden' name='etime' value="<?php echo $t?>">
802<h2> Enter Name : <input type=textbox name=uname></h2><br>
803<h2> Enter City : <input type=textbox name=city></h2><br>
804<h2> Enter Phone No : <input type=textbox name=pno></h2><br>
805<input type=submit name=submit value=DISPLAY>
806</form>
807</body>
808</html>
809<?php
810}
811else echo "<center><h1>Invalid Username Or Password</h1></center>"
812?>
813slip_4-2.php :
814<?php
815session_start();
816$t=$_REQUEST['etime'];
817$exp=date("1,d-m-y h:i:s",time());
818if($t<$exp)
819echo "<center><h1>Page Time Expired</h1></center>";
820else
821{
822echo "<center><h2>Name : ".$_REQUEST['uname']."</h2></center>";
823echo "<center><h2>City : ".$_REQUEST['city']."</h2></center>";
824echo "<center><h2>Phone NO : ".$_REQUEST['pno']."</h2></center>";
825session_destroy();
826}
827?>
828
829
830-----------------------------------------------------------------------------------------------------------------------------------------------------
831
832
833slip_5
834
835
836q1-----------
837
838SLIP 5 : Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a
839record in it.
840import java.sql.*;
841class Slip5_1
842{
843public static void main(String args[])
844{
845 Connection con;
846try
847{
848Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
849con=DriverManager.getConnection("jdbc:odbc:dsn");
850if(con==null)
851{
852System.out.println("Connection Failed....");
853System.exit(1);
854}
855System.out.println("Connection Established...");
856Statement stmt=con.createStatement();
857//create a table teacher
858String query="create table Teacher"+"(TNoint ,"+"
859TNamevarchar(20),"+" salint,"+" desgvarchar(20))";
860stmt.executeUpdate(query);
861System.out.println("given table created in database");
862//insert record into teacher table
863stmt.executeUpdate("insert into Teacher
864"+"values(1,'NRC',50000,'MCS')");
865stmt.executeUpdate("insert into Teacher
866"+"values(2,'ABC',10000,'MCA')");
867stmt.executeUpdate("insert into Teacher
868"+"values(3,'XYZ',40000,'MCA')");
869stmt.executeUpdate("insert into Teacher
870"+"values(4,'PQR',20000,'MCS')");
871System.out.println("Succesfully inserted in table....");
872//display details
873ResultSet rs=stmt.executeQuery("select * From Teacher");
874System.out.println("TNo\t"+"TName\t"+"sal\t"+"desg");
875while(rs.next())
876{
877System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getStr
878ing(4));
879}
880}
881catch(Exception e)
882{
883System.out.println(e);
884}
885}
886}
887
888
889q2-----------
890
891import java.awt.*;
892import java.applet.*;
893/*
894<APPLET
895 code = "Flag.class"
896 width = "500"
897 height = "300"
898 >
899</APPLET>
900*/
901public class Flag extends Applet implements Runnable
902{
903 Thread t;
904 int x1,x2,x3,y3,x4,y4,x5,ln;
905
906 public void init()
907 {
908 t=new Thread(this);
909 t.start();
910 ln=1;
911 }
912 public void run()
913 {
914 try
915 { if(ln==1)
916 {
917 for(x1=200;x1>100;)
918 {
919 t.sleep(200);
920 repaint();
921 }
922 }
923 ln=2;
924 if(ln==2)
925 {
926 for(x2=100;x2<150;)
927 {
928 t.sleep(200);
929 repaint();
930 }
931 }
932 ln=3;
933 if(ln==3)
934 {
935 for(x3=150,y3=100;x3>125&&y3<125;)
936 {
937 t.sleep(200);
938 repaint();
939 }
940 }
941 ln=4;
942 if(ln==4)
943 {
944 for(x4=125,y4=125;x4<150&&y4<150;)
945 {
946 t.sleep(200);
947 repaint();
948 }
949 }
950 ln=5;
951 if(ln==5)
952 {
953 for(x5=150;x5>100;)
954 {
955 t.sleep(200);
956 repaint();
957 }
958 }
959 ln=1;
960 }catch(Exception e)
961 {
962 System.out.println(e);
963 }
964 run();
965 }
966 public void paint(Graphics g)
967 {
968 if(ln==1&&x1>100)
969 {
970 g.drawLine(100,200,100,x1-=5);
971 }
972
973 if(ln==2&&x2<150)
974 {
975 g.drawLine(100,200,100,100);
976 g.drawLine(100,100,x2+=5,100);
977 }
978 if(ln==3&&x3>125&&y3<125)
979 {
980 g.drawLine(100,200,100,100);
981 g.drawLine(100,100,150,100);
982 g.drawLine(150,100,x3-=5,y3+=5);
983 }
984 if(ln==4&&x4<150&&y4<150)
985 {
986 g.drawLine(100,200,100,100);
987 g.drawLine(100,100,150,100);
988 g.drawLine(150,100,125,125);
989 g.drawLine(125,125,x4+=5,y4+=5);
990 }
991 if(ln==5&&x5>100)
992 {
993 g.drawLine(100,200,100,100);
994 g.drawLine(100,100,150,100);
995 g.drawLine(150,100,125,125);
996 g.drawLine(125,125,150,150);
997 g.drawLine(150,150,x5-=5,150);
998 }
999
1000 }
1001}
1002
1003
1004
1005q3--------------------------------------
1006
1007
10085. Write an PHP script to search employee name from employee.dat file(Use AJAX concept)
1009employee.dat file
10101 Ramesh
10112 Gopal
10123 sandip
1013
1014HTML File
1015
1016<html>
1017<head><title>Slip 5</title>
1018<script>
1019function search()
1020{
1021
1022 s=document.getElementById('txt1').value;
1023ob=new XMLHttpRequest();
1024
1025ob.onreadystatechange=function()
1026 {
1027if(ob.readyState==4 &&ob.status==200)
1028 {
1029document.getElementById('o').innerHTML=ob.responseText;
1030 }
1031 }
1032ob.open("GET","slip5.php?srch="+s);
1033ob.send();
1034}
1035</script>
1036</head>
1037<body>
1038<input type=text id=txt1 placeholder="Enter Employee name"></br>
1039<input type=button value="Search" onclick="search()">
1040<h1 id="o">Output</h1>
1041</body>
1042</html>
1043
1044PHP File
1045
1046<?php
1047$nm=$_GET['srch'];
1048$fp=fopen("employee.dat","r");
1049echo "<table border=1><tr><th>EmpId</th><th>Employee Name</th></tr>";
1050while($res=fscanf($fp,"%s %s"))
1051{
1052if($res[1]==$nm)
1053 {
1054echo "<tr><td>".$res[0]."</td><td>".$res[1]."</td><tr>";
1055 }
1056}
1057echo "</table>";
1058?>
1059
1060
1061
1062q4------------------------------
1063
1064
10655. Define a class Employee having private members – id, name, department, salary. Define parameterized constructors. Create a subclass called “Manager†with private member bonus. Create 6 objects of the Manager class and display the details of the manager having the maximum total salary (salary + bonus).
1066
1067<?php
1068class Employee
1069{
1070private $eid,$ename,$edept,$sal;
1071function __construct($a,$b,$c,$d)
1072{
1073$this->eid=$a;
1074$this->ename=$b;
1075$this->edept=$c;
1076$this->sal=$d;
1077}
1078public function getdata()
1079{
1080return $this->sal;
1081}
1082public function display()
1083{
1084echo $this->eid."</br>";
1085echo $this->ename."</br>";
1086echo $this->edept."</br>";
1087}
1088}
1089class Manager extends Employee
1090{
1091private $bonus;
1092public static $total1=0;
1093function __construct($a,$b,$c,$d,$e)
1094{
1095parent::__construct($a,$b,$c,$d);
1096$this->bonus=$e;
1097}
1098public function max($ob)
1099{
1100$sal=$this->getdata();
1101$total=$sal+$this->bonus;
1102if($total>self::$total1)
1103{
1104self::$total1=$total;
1105return $this;
1106}
1107else
1108{
1109return $ob;
1110}
1111}
1112public function display()
1113{
1114parent::display();
1115echo self::$total1;
1116}
1117}
1118$ob=new Manager(0,"ABC","",0,0);
1119$ob1=new Manager(1,"ramdas","computer",28000,2000);
1120$ob=$ob1->max($ob);
1121$ob2=new Manager(2,"ramdas1","computer",30000,2500);
1122$ob=$ob2->max($ob);
1123$ob3=new Manager(3,"ramdas2","computer",32000,3000);
1124$ob=$ob3->max($ob);
1125$ob4=new Manager(4,"ramdas","computer",28000,4000);
1126$ob=$ob4->max($ob);
1127$ob5=new Manager(5,"ramdas","computer",28000,5000);
1128$ob=$ob5->max($ob);
1129$ob->display();
1130?>
1131
1132
1133
1134---------------------------------------------------------------------------------------------------------------------------------------------
1135
1136slip_6
1137
1138
1139q1---------------------------
1140
1141
1142SLIP 6: Write a java program to accept the details of customer (CID, CName, Address,
1143Ph_No) and store it into the database(Use PreparedStatement interface)
1144import java.sql.*;
1145import java.io.*;
1146class Slip6_1
1147{
1148public static void main(String a[])
1149{
1150PreparedStatement ps;
1151Connection con;
1152try{
1153Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
1154con=DriverManager.getConnection("jdbc:odbc:dsn6");
1155if(con==null)
1156{
1157System.out.println("Connection Failed......");
1158System.exit(1);
1159}
1160System.out.println("Connection Esatablished......");
1161Statement stmt=con.createStatement();
1162BufferedReaderbr = new BufferedReader(new
1163InputStreamReader(System.in));
1164String query="insert into Customer values(?,?,?,?)";
1165ps=con.prepareStatement(query);
1166System.out.println("Customer Details....");
1167System.out.println("Enter CID");
1168int cid=Integer.parseInt(br.readLine());
1169ps.setInt(1,cid);
1170System.out.println("Enter name");
1171String name=br.readLine();
1172ps.setString(2,name);
1173System.out.println("Enter Address");
1174String add=br.readLine();
1175ps.setString(3,add);
1176System.out.println("Enter Ph_No");
1177String phno=br.readLine();
1178ps.setString(4,phno);
1179int no=ps.executeUpdate();
1180if(no!=0)
1181System.out.println("Data inserted succesfully.....");
1182else
1183System.out.println("Data NOT inserted");
1184con.close();
1185}
1186catch(Exception e)
1187{
1188e.printStackTrace();
1189}
1190}
1191}
1192
1193
1194q2----------------------
1195
1196Slip 6 : Write a socket program in java to check whether given file is present on server or
1197not, If it present then display its content on the server’s machine.
1198S_Slip6_2.java
1199
1200import java.io.*;
1201import java.net.*;
1202class S_Slip6_2
1203{
1204public static void main(String a[]) throws Exception
1205{
1206ServerSocket ss = new ServerSocket(1000);
1207System.out.println("Server is waiting for client : ");
1208Socket s =ss.accept();
1209System.out.println("Client is connected");
1210DataInputStream dis=new DataInputStream(s.getInputStream());
1211DataOutputStream dos=new DataOutputStream(s.getOutputStream());
1212String fname =(String)dis.readUTF();
1213File f = new File(fname);
1214if(f.exists())
1215{
1216System.out.println("file is exists");
1217FileInputStream fin = new FileInputStream(fname);
1218int ch;
1219String msg = "";
1220while((ch=fin.read())!=-1)
1221{
1222msg=msg+(char)ch;
1223}
1224dos.writeUTF(msg);
1225}
1226else
1227dos.writeUTF("0");
1228}
1229}
1230C_Slip6_2.java
1231
1232import java.io.*;
1233import java.net.*;
1234class C_Slip6_2
1235{
1236public static void main(String a[]) throws Exception
1237{
1238Socket s = new Socket("localhost",1000);
1239System.out.println("client is connected : ");
1240DataInputStream dis=new DataInputStream(s.getInputStream());
1241DataOutputStream dos=new DataOutputStream(s.getOutputStream());
1242BufferedReader br = new BufferedReader(new
1243InputStreamReader(System.in));
1244System.out.println("Enter file name : ");
1245String fname = br.readLine();
1246dos.writeUTF(fname);
1247String msg = (String)dis.readUTF();
1248if(msg.equals("0"))
1249System.out.println("File not present ");
1250else
1251{
1252System.out.println("Content of the file is : \n");
1253System.out.println(msg);
1254}
1255}
1256}
1257
1258
1259
1260q3------------------------------------
1261
1262
12636. Write a PHP Script create login form and validate it (Use database and Sticky form concept)
1264
1265
1266<html>
1267<head>
1268<title>Sticky Form</title>
1269</head>
1270<body>
1271<form action="<?php echo $_SERVER['PHP_SELF']?>" method=post>
1272<input type=text name=txtuname value="<?php if(isset($_POST['txtuname']))echo $_POST['txtuname'];?>" ></br>
1273<input type=password name=txtupass value="<?php if(isset($_POST['txtupass']))echo $_POST['txtupass'];?>" ></br>
1274<input type=submit value="Login" name=submit>
1275<?php
1276if(isset($_POST['submit']))
1277$nm=$_POST['txtuname'];
1278$ps=$_POST['txtupass'];
1279$con=mysql_connect("localhost","root","rsb");
1280mysql_select_db("slip6db",$con);
1281$result=mysql_query("select * from login where uname='$nm' and upass='$ps'");
1282$flag=0;
1283while($row=mysql_fetch_array($result))
1284{
1285 $flag++;
1286}
1287if($flag==1)
1288echo "Login validated";
1289else
1290echo "username or password invalid";
1291?>
1292</body>
1293</html>
1294
1295
1296
1297
1298
1299Q4-----------------------
1300
1301
13026. Write a PHP Script to create a super class Vehicle having members Company and price.Derive 2 different classes LightMotorVehicle (members – mileage) and HeavyMotorVehicle (members – capacity-in-tons). Define 5 Object of each subclass and display details in table format.
1303
1304<?php
1305class vehicle
1306{
1307public $company,$price;
1308public function __construct($a,$b)
1309{
1310$this->company=$a;
1311$this->price=$b;
1312}
1313}
1314class Lightmotorvehicle extends vehicle
1315{
1316public $milege;
1317public function __construct($a,$b,$c)
1318{
1319$this->company=$a;
1320$this->price=$b;
1321$this->milege=$c;
1322}
1323public function display()
1324{
1325echo "<table border=1 width=300>
1326 <tr><td>".$this->company."</td>
1327 <td>".$this->price."</td><td>".$this->milege."</td></tr>";
1328}
1329}
1330class Heavymotorvehicle extends vehicle
1331{
1332public $capacity;
1333public function __construct($a,$b,$c)
1334{
1335$this->company=$a;
1336$this->price=$b;
1337$this->capacity=$c;
1338}
1339public function display()
1340{
1341echo "<table border=1 width=300>";
1342echo "<tr><td>".$this->company."</td><td>".$this->price."</td><td>".$this->capacity;
1343echo "</td></tr></table>";
1344}
1345}
1346$ob1=new Lightmotorvehicle("Maruti",200000,25);
1347$ob1->display();
1348$ob2=new Lightmotorvehicle("Toyota",500000,20);
1349$ob2->display();
1350$ob3=new Lightmotorvehicle("skoda",400000,15);
1351$ob3->display();
1352$ob4=new Heavymotorvehicle("Tata Truck",1220000,25);
1353$ob4->display();
1354$ob5=new Heavymotorvehicle("Bajaj",200000,25);
1355$ob5->display();
1356$ob6=new Heavymotorvehicle("mahindra",900000,25);
1357$ob6->display();
1358?>
1359
1360
1361
1362-------------------------------------------------------------------------------------------------------------------------------
1363
1364slip_7
1365
1366<%@page contentType="text/html" pageEncoding="UTF-8"%>
1367<!DOCTYPE html>
1368<html>
1369<body>
1370<%! int n,rem,r; %>
1371<% n=Integer.parseInt(request.getParameter("num"));
1372 if(n<10)
1373 {
1374 out.println("Sum of first and last digit is ");
1375%><font size=18 color=red><%= n %></font>
1376<%
1377 }
1378 else
1379 {
1380 rem=n%10;
1381 do{
1382 r=n%10;
1383 n=n/10;
1384 }while(n>0);
1385 n=rem+r;
1386 out.println("Sum of first and last digit is ");
1387%><font size=18 color=red><%= n %></font>
1388<%
1389 }
1390%>
1391</body>
1392</html>
1393
1394
1395
1396q2 (1)----------------------------------------
1397
1398
1399SLIP 7: Write a JSP program to calculate sum of first and last digit of a given number. Display sum in Red Color with font size 18.
1400
1401
1402HTML FILE
1403
1404<!DOCTYPE html>
1405<html>
1406<body>
1407<form method=post action="Slip7.jsp">
1408Enter Any Number : <Input type=text name=num><br><br>
1409<input type=submit value=Display>
1410</form>
1411</body>
1412</html>
1413
1414
1415
1416q2-------------------------------------------------------------------------------------------
1417
1418
1419import java.awt.Color;
1420import java.awt.Graphics;
1421import javax.swing.*;
1422/*<APPLET CODE="car.class" WIDTH=400 HEIGHT=300> </APPLET>*/
1423public class car extends JApplet {
1424public static void main(String[] args) {
1425
1426JFrame frame = new JFrame();
1427frame.getContentPane().add(new car());
1428frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1429frame.setSize(1024, 739);
1430frame.setVisible(true);
1431}
1432
1433public void paint(Graphics g) {
1434try
1435{
1436int j = 0;
1437while (j < 500)
1438{
1439g.setColor(Color.white);
1440g.fillRect(0, 0, 5000, 5000);
1441g.setColor(Color.red);
1442g.fillRect(250 + j, 250, 100, 50);
1443g.setColor(Color.black);
1444g.fillOval(260 + j, 300, 20, 20);
1445g.fillOval(320 + j, 300, 20, 20);
1446j++;
1447Thread.sleep(2);
1448}
1449} catch (InterruptedException e) {
1450}
1451}
1452}
1453
1454
1455
1456
1457
1458q3----------------------------------------
1459
1460
14617.Create a form to accept employee details like name, address and mobile number. Once the employee information is accepted, then accept LIC information like policy_no, name, premium. Display employee details and LIC details on next form.(use COOKIE)
1462
1463
1464
1465Html file :
1466
1467<html>
1468<body>
1469
1470<form action="slip_7_Q3_1.php" method="post">
1471<center>
1472<h2>Enter Employee Details :</h2>
1473
1474<table>
1475<tr><td>Name : </td><td><input type="text" name="name"></td><tr>
1476<tr><td>Address : </td><td><input type="text" name="addr"></td></tr>
1477<tr><td>Mobile No : </td><td><input type="text" name="mob_no"></td></tr>
1478<tr><td></td><td><input type="submit" value=Next></td></tr>
1479</table>
1480</center>
1481
1482</form>
1483</body>
1484</html>
1485
1486Phpfile :
1487
1488slip_7_Q3_1.php
1489
1490<html>
1491<body>
1492
1493<form action="slip_7_Q3_2.php" method="post">
1494<center>
1495<h2>Enter LIC Information :</h2>
1496
1497<table>
1498<tr><td>Policy no. : </td><td><input type="text" name="p_no"></td><tr>
1499<tr><td>Policy Name : </td><td><input type="text" name="p_name"></td></tr>
1500<tr><td>Premium : </td><td><input type="text" name="premium"></td></tr>
1501<tr><td></td><td><input type="submit" value=Next></td></tr>
1502</table>
1503</center>
1504
1505</form>
1506</body>
1507</html>
1508
1509<?php
1510setcookie("emp1",$_POST['name'],time()+3600);
1511setcookie("emp2",$_POST['addr'],time()+3600);
1512setcookie("emp3",$_POST['mob_no'],time()+3600);
1513?>
1514
1515Phpfile :
1516slip_7_Q3_2.php
1517
1518<?php
1519echo "<h3>Employee Details</h3> ";
1520
1521echo "<b>Name : </b>".$_COOKIE['emp1']."<br>";
1522echo "<b>Address : </b>".$_COOKIE['emp2']."<br>";
1523echo "<b>Mobile No. : </b>".$_COOKIE['emp3']."<br>";
1524
1525echo "<b>Policy no. : </b>".$_POST['p_no']."<br>";
1526echo "<b>Policy Name : </b>".$_POST['p_name']."<br>";
1527echo "<b>Premium : </b>".$_POST['premium']."<br>";
1528?>
1529
1530------------------------------------------------------------------------------------------------------
1531
1532slip_8
1533
1534
1535q1----------------------------------------------------
1536
1537SLIP 8: Write a multithreading program using Runnable interface to blink Text on the frame.
1538
1539import java.awt.*;
1540import java.awt.event.*;
1541
1542class Slip8_1 extends Frame implements Runnable
1543{
1544 Thread t;
1545 Label l1;
1546 int f;
1547 Slip8_1()
1548 {
1549 t=new Thread(this);
1550 t.start();
1551 setLayout(null);
1552 l1=new Label("Hello JAVA");
1553 l1.setBounds(100,100,100,40);
1554 add(l1);
1555 setSize(300,300);
1556 setVisible(true);
1557 f=0;
1558 }
1559 public void run()
1560 {
1561 try
1562 {
1563 if(f==0)
1564 {
1565 t.sleep(200);
1566 l1.setText("");
1567 f=1;
1568 }
1569 if(f==1)
1570 {
1571 t.sleep(200);
1572 l1.setText("Hello Java");
1573 f=0;
1574 }
1575 }
1576 catch(Exception e)
1577 {
1578 System.out.println(e);
1579 }
1580 run();
1581 }
1582 public static void main(String a[])
1583 {
1584 new Slip8_1();
1585 }
1586}
1587
1588
1589
1590
1591q2----------------------------------------------------------------------
1592
1593
1594save file to .html
1595
1596
1597
1598<html>
1599<head>
1600<title>New Page 1</title>
1601</head>
1602<body>
1603
1604<form method="POST" action="http://localhost:8080/loginslip8">
1605
1606
1607
1608 <p>Enter Username: <input type="text" name="uname" size="20"></p>
1609 <p>Enter Password: <input type="text" name="pass" size="20"></p>
1610 <p> <input type="submit" value="Submit" name="B1"></p>
1611</form>
1612
1613</body>
1614
1615</html>
1616
1617
1618
1619
1620q2---------------------------------------------
1621
1622
1623
1624import java.io.*;
1625import java.lang.*;
1626import java.sql.*;
1627import javax.servlet.*;
1628import javax.servlet.http.*;
1629
1630public class loginslip8 extends HttpServlet
1631{
1632
1633 public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
1634{
1635 response.setContentType("text/html");
1636
1637 PrintWriter pw = response.getWriter();
1638
1639
1640 Connection conn;
1641 try
1642{
1643 String uname = request.getParameter("uname");
1644 String pass = request.getParameter("pass");
1645 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
1646 conn = DriverManager.getConnection("jdbc:odbc:mydsn.dsn");
1647
1648 String query = "select * from login where username='"+uname+"' and password='"+pass+"'";
1649 Statement stmt = conn.createStatement();
1650 ResultSet rs = stmt.executeQuery(query);
1651
1652 if(rs.next())
1653 {
1654 pw.println("<br>Welcome ..."+uname);
1655 } else {
1656 pw.println("<br>Sorry, Please enter correct credentials");
1657 }
1658
1659 }
1660 catch (Exception e){
1661 pw.println(e);
1662 }
1663 }
1664
1665
1666q3--------------------------------------------------------------------------
1667
1668
1669
16708. Write a script to keep track of number of times the web page has been accessed
1671(use $_COOKIE).
1672
1673<?php
1674if(isset($_COOKIE['cnt']))
1675{
1676 $x=$_COOKIE['cnt'];
1677 $x=$x+1;
1678setcookie('cnt',$x);
1679}
1680else
1681{
1682setcookie('cnt',2);
1683echo "you accessed this page 1st time";
1684}
1685echo “You accessed this page $_COOKIE['cnt'] timesâ€;
1686
1687?>
1688
1689
1690
1691
1692q4----------------------------------------------------------------------------------------------------
1693
1694
1695
16968. Write Ajax program to carry out validation for a username entered in textbox. If the textbox is blank, print ‘Enter username’. If the number of characters is less than three, print’ Username is too short’. If value entered is appropriate the print ‘Valid username’.
1697Html file :
1698<html>
1699<head>
1700<script type="text/javascript">
1701functionval_user(str)
1702 {
1703varob=false;
1704ob=new XMLHttpRequest();
1705if(str=="")
1706document.getElementById("a").innerHTML="Username Should not be Empty";
1707elseif(str.length<=3)
1708document.getElementById('a').innerHTML="lenght is too short";
1709elsedocument.getElementById('a').innerHTML="valid username";
1710 }
1711</script>
1712</head>
1713<body>
1714<form>
1715<table align="center">
1716<tr><td><b>Enter Username : </b></td><td><input type=text name=u_name id=u_name></td></tr>
1717<tr><td></td><td><font color="red" size=3><span id=a></span></font></td></tr>
1718<tr><thcolspan="2"><input type=button value=submit onclick="val_user(form.u_name.value)"></th></tr>
1719</table>
1720</form>
1721</body>
1722</html>
1723
1724
1725
1726
1727-------------------------------------------------------------------------------------------------------------------------------------------------
1728
1729
1730slip_9
1731
1732
1733q1-----------------------------------------------------------------
1734
1735
1736SLIP 9: Write a JDBC program to delete the records of employees whose names are starts with ‘A’character.
1737
1738import java.sql.*;
1739class Slip9_1
1740{
1741 public static void main(String args[])
1742 {
1743 Connection con;
1744 Statement stmt;
1745 try
1746 {
1747 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
1748 con=DriverManager.getConnection("jdbc:odbc:dsn");
1749 if(con==null)
1750 {
1751 System.out.println("Connection Failed....");
1752 System.exit(1);
1753 }
1754 System.out.println("Connection Established...");
1755
1756 stmt=con.createStatement();
1757
1758 int no = stmt.executeUpdate("Delete from employee where name like 'A%'");
1759 if(no!=0)
1760 System.out.println("Delete Data sucessfully.....");
1761 else
1762 System.out.println("Data NOT Deleted");
1763
1764 con.close();
1765 }
1766
1767 catch(Exception e)
1768 {
1769 System.out.println(e);
1770 }
1771 }
1772}
1773
1774
1775
1776q2----------------------------------------------------------------------------------------
1777
1778import java.applet.Applet;
1779import java.awt.*;
1780
1781public class slip9b extends Applet implements Runnable
1782{
1783Thread t;
1784int x,y,k;
1785int counter=0;
1786public void init()
1787{
1788x=10;
1789k=0;
1790y=200;
1791t=new Thread(this);
1792t.start();
1793}
1794public void run()
1795{
1796try
1797{
1798while(true)
1799{
1800repaint();
1801Thread.sleep(1000);
1802++counter;
1803}
1804}
1805catch(Exception e)
1806{ }
1807}
1808public void paint(Graphics g)
1809{
1810g.setFont(new Font("ariel",Font.BOLD,30));
1811FontMetrics fm=g.getFontMetrics();
1812String s="Vinita";
1813Dimension d=getSize();
1814g.drawString(s,x,y);
1815if(k==0)
1816{
1817x=360;
1818y=25;
1819k=1;
1820}
1821else if(k==1)
1822{
1823x=700;
1824y=200;
1825k=2;
1826}
1827else if(k==2)
1828{
1829x=360;
1830y=400;
1831k=3;
1832}
1833else if(k==3)
1834{
1835x=10;
1836y=200;
1837k=0;
1838}
1839}
1840}
1841
1842
1843q3-------------------------------------------------------------------------------------------
1844
1845
18469. Create an abstract class Shape with methods calc_area( ) and calc_volume( ). Derive three classes Sphere(radius) , Cone(radius, height) and Cylinder(radius, height), Calculate area and volume of all. (Use Method overriding).
1847
1848Html file :
1849
1850<html>
1851<body>
1852<form action="slip9.php" method=get>
1853<center><h2>For Cone & Cylinder</h2>
1854Enter Radius </td><td><input type="text" name="r">
1855Enter Height</td><td><input type="text" name="h">
1856<input type="submit" value="SUBMIT">
1857</form>
1858</body>
1859</html>
1860Phpfile :
1861
1862
1863<?php
1864
1865define('pi',3.14);
1866abstract class shape
1867{
1868
1869abstract function calc_area($r,$h);
1870abstract function calc_vol($r,$h);
1871
1872}
1873class sphere extends shape
1874{
1875functioncalc_area($r,$r)
1876 {
1877return 4*pi*$r*$r;
1878 }
1879
1880functioncalc_vol($r,$r)
1881 {
1882return (4/3)*pi*$r*$r*$r;
1883 }
1884}
1885
1886class cylinder extends shape
1887{
1888functioncalc_area($r,$h)
1889 {
1890return 2*pi*$r*($r+$h);
1891 }
1892
1893functioncalc_vol($r,$h)
1894 {
1895return pi*$r*$r*$h;
1896 }
1897}
1898
1899class cone extends shape
1900{
1901functioncalc_area($r,$h)
1902 {
1903return 0.5*$r*$r*$h;
1904 }
1905
1906functioncalc_vol($r,$h)
1907 {
1908return $r*$r*$r*$h;
1909 }
1910}
1911$r=$_GET['r'];
1912$h=$_GET['h'];
1913$ob=new cone();
1914echo "Area of cone ".$ob->calc_area($r,$h);
1915echo "</br>";
1916echo "Volume of cone ".$ob->calc_vol($r,$h);
1917echo "</br>";
1918$ob=new cylinder();
1919echo "Area of cylinder ".$ob->calc_area($r,$h);
1920echo "</br>";
1921echo "Volume of cylinder".$ob->calc_vol($r,$h);
1922echo "</br>";
1923
1924$ob=new sphere();
1925echo "Area of sphere ".$ob->calc_area($r,$r);
1926echo "</br>";
1927echo "Volume of sphere ".$ob->calc_vol($r,$r);
1928
1929?>
1930
1931
1932
1933---------------------------------------------------------------------------------------------------------------------------------------------
1934
1935
1936slip_10
1937
1938
1939
1940q1-----------------------
1941
1942SLIP 10: Write a JDBC program to count the number of records in table.(Without using standard method)
1943
1944import java.sql.*;
1945
1946class Slip10_1
1947{
1948 public static void main(String args[])
1949 {
1950 Connection con;
1951 Statement stmt;
1952 try
1953 {
1954 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
1955 con=DriverManager.getConnection("jdbc:odbc:dsn");
1956 if(con==null)
1957 {
1958 System.out.println("Connection Failed.......");
1959 System.exit(1);
1960 }
1961 System.out.println("Connection Established......");
1962 stmt=con.createStatement();
1963 ResultSet rs=stmt.executeQuery("select * from employee");
1964
1965 int cnt=0;
1966 while(rs.next())
1967 {
1968 cnt++;
1969 }
1970 System.out.println("Number of records in Table are:"+cnt);
1971 }
1972
1973 catch(Exception e)
1974 {
1975 System.out.println(e);
1976
1977 }
1978 }
1979}
1980
1981
1982q2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1983
1984
1985Slip 10 : Write a multithreading application in java for bouncing ball.
1986Slip 10_2.java
1987
1988import java.awt.*;
1989class Slip10_2 extends java.applet.Applet implements Runnable
1990{
1991Thread t;
1992int f,y,f1,f2,f3;
1993public void init()
1994{
1995t=new Thread(this);
1996t.start();
1997f=0; y=0; f1=0;
1998}
1999public void run()
2000{ try
2001{
2002if (f==0)
2003
2004{ t.sleep(10);
2005y=y+5;
2006repaint();
2007if(f1==6)
2008f1=0;
2009}
2010if(f==1)
2011{ t.sleep(10);
2012y=y-5;
2013repaint();
2014if(f1==6)
2015f1=0;
2016}
2017}
2018catch(Exception e)
2019{System.out.println(e); }
2020run();
2021}
2022public void paint(Graphics g)
2023{
2024if(f==0)
2025{
2026if(f1==1)
2027g.setColor(Color.green);
2028if(f1==2)
2029g.setColor(Color.blue);
2030if(f1==3)
2031g.setColor(Color.red);
2032if(f1==4)
2033g.setColor(Color.yellow);
2034if(f1==5)
2035g.setColor(Color.orange);
2036g.fillOval(150,y+10,20,20);
2037if(y==400)
2038{
2039f1++;
2040 f=1;
2041}
2042}
2043if(f==1)
2044{
2045if(f1==1)
2046g.setColor(Color.green);
2047if(f1==2)
2048g.setColor(Color.blue);
2049if(f1==3)
2050g.setColor(Color.red);
2051if(f1==4)
2052g.setColor(Color.yellow);
2053if(f1==5)
2054g.setColor(Color.orange);
2055g.fillOval(150,y-10,20,20);
2056if(y==0)
2057{
2058f1++; f=0;
2059}
2060
2061}
2062
2063q4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2064
2065
2066
206710. Create a form to accept student information (name, class, address). Once the student
2068information is accepted, accept marks in next form (Java, PHP, ST, IT, pract1, and project).
2069Display the mark sheet for the student in the next form containing name, class, marks of the
2070subject, total and percentage(Use $_COOKIE).
2071Html file :
2072
2073<html>
2074<body>
2075<form action="slip_10-1.php" method="post">
2076<center>
2077<h2>Enter Students information :</h2>
2078<table>
2079<tr><td>Name : </td><td><input type="text" name="name"></td><tr>
2080<tr><td>Address : </td><td><input type="text" name="addr"></td></tr>
2081<tr><td>Class : </td><td><input type="text" name="class"></td></tr>
2082<tr><td></td><td><input type="submit" value=Next></td></tr>
2083</table>
2084</center>
2085</form>
2086</body>
2087</html>
2088Phpfile :
2089Slip_10-1.php :
2090<html>
2091<body>
2092<form action="slip_10-2.php" method="post">
2093<center>
2094<h2>Enter Marks for Student:</h2>
2095<table>
2096<tr><td>Java : </td><td><input type="text" name="m1"></td><tr>
2097<tr><td>PHP : </td><td><input type="text" name="m2"></td></tr>
2098<tr><td>ST : </td><td><input type="text" name="m3"></td></tr>
2099<tr><td>IT : </t d><td><input type="text" name="m4"></td></tr>
2100<tr><td>Practical : </td><td><input type="text" name="m5"></td></tr>
2101<tr><td>Project : </td><td><input type="text" name="m6"></td></tr>
2102<tr><td></td><td><input type="submit" value=Next></td></tr>
2103</table>
2104</center>
2105</form>
2106</body>
2107</html>
2108
2109<?php
2110setcookie("stud1",$_POST['name'],time()+3600);
2111setcookie("stud2",$_POST['addr'],time()+3600);
2112setcookie("stud3",$_POST['class'],time()+3600);
2113?>
2114
2115Slip_10-2.php :
2116<?php
2117echo "<h3>Marksheet</h3> ";
2118echo "Name : ".$_COOKIE['stud1']."<br>";
2119echo "Address : ".$_COOKIE['stud2']."\n";
2120echo "Class : ".$_COOKIE['stud3']."\n";
2121echo "Java : ".$_POST['m1']."\n";
2122echo "PHP : ".$_POST['m2']."\n";
2123echo "ST : ".$_POST['m3']."\n";
2124echo "IT : ".$_POST['m3']."\n";
2125echo "Practical : ".$_POST['m3']."\n";
2126echo "Project : ".$_POST['m3']."\n";
2127?>
2128
2129
2130
2131
2132----------------------------------------------------------------------------------------------------------------
2133
2134slip_11
2135
2136
2137
2138Q1=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2139
2140
2141
2142SLIP11: Write a JDBC program to remove “percentage†column from student (rno, sname, percentage) table. Student table is already created.
2143
2144import java.sql.*;
2145
2146class Slip11
2147{
2148 public static void main(String a[])
2149 {
2150 Connection con;
2151 Statement stmt;
2152 try
2153 {
2154 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2155 con=DriverManager.getConnection("jdbc:odbc:dsn");
2156 if(con==null)
2157 {
2158 System.out.println("Connection Failed.......");
2159 System.exit(1);
2160 }
2161 System.out.println("Connection Established......");
2162 stmt=con.createStatement();
2163 int no = stmt.executeUpdate("alter table student drop column per");
2164 if(no!=0)
2165 System.out.println("Drop col sucessfully");
2166 else
2167 System.out.println("NOT Drop col ");
2168 }
2169 catch(Exception e)
2170 {
2171 System.out.println(e);
2172 }
2173 }
2174}
2175
2176
2177
2178
2179Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2180
2181
2182import java.util.*;
2183
2184import java.io.*;
2185import javax.servlet.*;
2186import javax.servlet.http.*;
2187
2188public class slip11 extends HttpServlet {
2189
2190 public void doGet(HttpServletRequest req, HttpServletResponse res)
2191 throws ServletException, IOException {
2192 res.setContentType("text/html");
2193 PrintWriter out = res.getWriter();
2194
2195 // Get the current session object, create one if necessary
2196 HttpSession session = req.getSession();
2197
2198 out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
2199 out.println("<BODY><H1>Session Timer</H1>");
2200
2201 // Display the previous timeout
2202 out.println("The previous timeout was " +
2203 session.getMaxInactiveInterval());
2204 out.println("<BR>");
2205
2206 // Set the new timeout
2207 session.setMaxInactiveInterval(2*60*60); // two hours
2208
2209 // Display the new timeout
2210 out.println("The newly assigned timeout is " +
2211 session.getMaxInactiveInterval());
2212
2213 out.println("</BODY></HTML>");
2214 }
2215}
2216
2217
2218
2219
2220Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2221
2222
222311. Write PHP script to create a CD catalog using XML file.
2224
2225Xml file :
2226
2227<?xml version='1.0' encoding='UTF-8' ?>
2228
2229<CD>
2230<cd type='music'>
2231<name>silent_songs</name>
2232<launch-date>5-6-2014</launch-date>
2233<composer>A-R-Rehman</composer>
2234</cd>
2235
2236<cd type='music'>
2237<name>Hip-Hop</name>
2238<launch-date>4-8-2011</launch-date>
2239<composer>Yo-Yo-Honey singh</composer>
2240</cd>
2241
2242<cd type='music'>
2243<name>love track</name>
2244<launch-date>6-9-2000</launch-date>
2245<composer>Arjit Singh</composer>
2246</cd>
2247</CD>
2248
2249
2250Phpfile :
2251
2252<?php
2253$xml=simplexml_load_file('slip_11_Q3.xml');
2254var_dump($xml);
2255?>
2256
2257
2258
2259-----------------------------------------------------------------------------------------------------------------------------------------
2260
2261SLIP_12
2262
2263Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2264
2265
2266SLIP12: Write a java program to display the number’s between 1 to 100 continuously in a TextField by clicking on button. (use Runnable Interface)
2267
2268import java.awt.event.*;
2269import javax.swing.*;
2270
2271class Message implements Runnable
2272{
2273 JTextField t;
2274 public void run()
2275 {
2276 for(int i =1; i<=100;i++)
2277 {
2278 t.setText(""+i);
2279 try
2280 {
2281 Thread.sleep(50);
2282 }
2283 catch(Exception e)
2284 {
2285
2286 }
2287 }
2288 }
2289}
2290class Slip12_1 implements ActionListener
2291{
2292 JFrame f;
2293 JPanel p;
2294 JTextField t;
2295 JButton b;
2296 Thread t1;
2297
2298 Slip12_1()
2299 {
2300 f = new JFrame();
2301 p = new JPanel();
2302
2303 t = new JTextField(60);
2304 b = new JButton("Start");
2305
2306 t1 = new Thread(this);
2307
2308 b.addActionListener(this);
2309
2310 p.add(t);
2311 p.add(b);
2312
2313 f.add(p);
2314 f.setSize(400, 400);
2315 f.setVisible(true);
2316 }
2317
2318
2319 public void actionPerformed(ActionEvent e)
2320 {
2321 t1.start();
2322 }
2323}
2324
2325
2326
2327Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2328
2329
2330Slip 12 :Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it
2331into database and display it in tabular form. (Use PreparedStatement interface)
2332Slip12.html
2333<!-- To change this template, choose Tools | Templates and open the template in the editor.
2334-->
2335<!DOCTYPE html>
2336<html><body>
2337<form method=get action="Slip12.jsp">
2338Enter Account No. : <input type=text name=ano><br><br>
2339Enter Account Type:<input type=text name=type><br><br>
2340Enter Balance : <input type=text name=bal><br><br>
2341<input type=submit value="Save">
2342</form>
2343</body></html>
2344Slip12.jsp
2345<%@page contentType="text/html" pageEncoding="UTF-8"%>
2346<!DOCTYPE html>
2347<html><body>
2348<%@ page import="java.sql.*;" %>
2349<%! int ano,bal;
2350String type; %>
2351<%
2352ano=Integer.parseInt(request.getParameter("ano"));
2353type=request.getParameter("type");
2354bal=Integer.parseInt(request.getParameter("bal"));
2355try{
2356Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2357Connection cn=DriverManager.getConnection("jdbc:odbc:acnt","","");
2358PreparedStatement s=cn.prepareStatement("insert into Account values(?,?,?)");
2359s.setInt(1,ano);
2360s.setString(2,type);
2361s.setInt(3,bal);
2362s.executeUpdate();
2363out.println("Record is saved");
2364Statement st=cn.createStatement();
2365ResultSet rs=st.executeQuery("select * from Account");
2366%>
2367<table border="1" width="40%">
2368<% while(rs.next())
2369{
2370%>
2371<tr><td><%= rs.getInt("ano") %></td>
2372<td><%= rs.getString("type") %></td>
2373<td><%= rs.getInt("bal") %></td>
2374</tr>
2375<%
2376}
2377cn.close();
2378}catch(Exception e)
2379{
2380out.println(e);
2381}
2382%>
2383</body></html>
2384
2385
2386
2387Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2388
2389
2390
239112. Write a PHP script for the following: Design a form to accept a number from the user. Perform the operations and show the results.
23921) Factorial of a number using Recursion.
2393 2) Add the digits of that number to reduce it to single digit.
2394 (use the concept of self processing page.)
2395
2396<html>
2397<head>
2398<title>slip12</title>
2399</head>
2400<body>
2401<?php
2402if($_SERVER['REQUEST_METHOD']=="GET")
2403{
2404?>
2405<form action="<?php echo $_SERVER['PHP_SELF']?>" method=POST>
2406<input type name=txtnumber placeholder="Enter a number ">
2407<input type=submit value="calculate">
2408</form>
2409<?php
2410}
2411else if($_SERVER['REQUEST_METHOD']=="POST")
2412{
2413function fact($n)
2414 {
2415if($n==1)
2416 {
2417return 1;
2418 }
2419else { return($n*fact($n-1));
2420
2421 }
2422 }
2423functionsingleval($n)
2424 {
2425while($n>9)
2426 {$sum=0;
2427while($n)
2428 {
2429 $r=$n%10;
2430 $sum=$sum+$r;
2431 $n=$n/10;
2432 }
2433 $n=$sum;
2434 }
2435return $n;
2436 }
2437echo fact($_POST['txtnumber']);
2438echo "</br>";
2439echosingleval($_POST['txtnumber']);
2440}
2441?>
2442</body>
2443</html>
2444
2445
2446
2447Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2448
2449
245012. Create student table as follows Student(sno, sname, per).
2451Write Ajax program to select the student name and print the selected student’s details.
2452Html file :
2453<html>
2454<body>
2455<form action="slip_12.php" method="get">
2456Enter student name Name:<input type="text" name=sname><br>
2457<input type="submit" value=submit>
2458</form>
2459</body>
2460</html>
2461
2462Phpfile :
2463<?php
2464$sname=$_GET['sname'];
2465$con=mysql_connect("localhost","root","");
2466$d=mysql_select_db("bca_programs",$con);
2467$result=mysql_query("select *from student where sname='$sname'");
2468while($row=mysql_fetch_array($result))
2469{
2470echo $row['sno']."--".$row['sname']."--".$row['per']."<br>";
2471}
2472?>
2473
2474
2475
2476----------------------------------------------------------------------------------------------------------------
2477
2478SLIP_13
2479
2480
2481Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2482
2483SLIP13: Write a java program to create a Mobile (Model_No, Company_Name, Price, Color) table.
2484
2485import java.sql.*;
2486class Slip13_1
2487{
2488 public static void main(String a[])
2489 {
2490 Connection con;
2491 Statement stmt;
2492 try
2493 {
2494 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2495 con=DriverManager.getConnection("jdbc:odbc:dsn");
2496 if(con==null)
2497 {
2498 System.out.println("Connection Failed");
2499 System.exit(1);
2500 }
2501 System.out.println("Connection Established....");
2502 stmt=con.createStatement();
2503
2504 String sql="create table mobile"+"(Model_No int,"+"Company_Name varchar(20),"+"price float(6,2),"+"color varchar(20))";
2505 stmt.executeUpdate(sql);
2506 System.out.println("Table Created sucessfully...");
2507
2508 con.close();
2509
2510 }
2511 catch(Exception e)
2512 {
2513 System.out.println(e);
2514 }
2515 }
2516}
2517
2518
2519
2520
2521Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CLIENT XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2522
2523GossipClient.java
2524
2525import java.io.*;
2526import java.net.*;
2527public class GossipClient
2528{
2529 public static void main(String[] args) throws Exception
2530 {
2531 Socket sock = new Socket("127.0.0.1", 3000);
2532 // reading from keyboard (keyRead object)
2533 BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
2534 // sending to client (pwrite object)
2535 OutputStream ostream = sock.getOutputStream();
2536 PrintWriter pwrite = new PrintWriter(ostream, true);
2537
2538 // receiving from server ( receiveRead object)
2539 InputStream istream = sock.getInputStream();
2540 BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
2541
2542 System.out.println("Start the chitchat, type and press Enter key");
2543
2544 String receiveMessage, sendMessage;
2545 while(true)
2546 {
2547 sendMessage = keyRead.readLine(); // keyboard reading
2548 pwrite.println(sendMessage); // sending to server
2549 pwrite.flush(); // flush the data
2550 if((receiveMessage = receiveRead.readLine()) != null) //receive from server
2551 {
2552 System.out.println(receiveMessage); // displaying at DOS prompt
2553 }
2554 }
2555 }
2556}
2557
2558
2559Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SERVER XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2560
2561
2562GossipServer.java
2563
2564import java.io.*;
2565import java.net.*;
2566public class GossipServer
2567{
2568 public static void main(String[] args) throws Exception
2569 {
2570 ServerSocket sersock = new ServerSocket(3000);
2571 System.out.println("Server ready for chatting");
2572 Socket sock = sersock.accept( );
2573 // reading from keyboard (keyRead object)
2574 BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
2575 // sending to client (pwrite object)
2576 OutputStream ostream = sock.getOutputStream();
2577 PrintWriter pwrite = new PrintWriter(ostream, true);
2578
2579 // receiving from server ( receiveRead object)
2580 InputStream istream = sock.getInputStream();
2581 BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
2582
2583 String receiveMessage, sendMessage;
2584 while(true)
2585 {
2586 if((receiveMessage = receiveRead.readLine()) != null)
2587 {
2588 System.out.println(receiveMessage);
2589 }
2590 sendMessage = keyRead.readLine();
2591 pwrite.println(sendMessage);
2592 pwrite.flush();
2593 }
2594 }
2595}
2596
2597
2598Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2599
2600
260113. Write a PHP script using AJAX concept, to develop user-friendly and interactive search engine
2602
2603
2604
2605HTML File
2606<html>
2607<head>
2608<title>Slip13.html</title>
2609<script>
2610function search()
2611{
2612srch=document.getElementById('txtsrch').value;
2613ob=new XMLHttpRequest();
2614ob.onreadystatechange=function()
2615 {
2616if(ob.readyState==4 &&ob.status==200)
2617 {
2618document.getElementById('o').innerHTML=ob.responseText;
2619 }
2620 }
2621ob.open("GET","slip13.php?s="+srch);
2622ob.send();
2623
2624}
2625</script>
2626</head>
2627<body>
2628<table align=center border=0>
2629<tr><td><input type=text id=txtsrch placeholder="enter search string"><input type=button value="SEARCH" onclick="search()">
2630</table>
2631<span id=o></span>
2632
2633</body>
2634
2635</html>
2636
2637PHP File
2638
2639<?php
2640$search=$_GET['s'];
2641$con=mysql_connect("localhost","root","rsb");
2642mysql_select_db("slip13db",$con);
2643$r=mysql_query("select * from slip13 where des='$search'");
2644echo "<table align=center">
2645while($row=mysql_fetch_array($r))
2646{
2647echo "<tr><td>".$row[0]."</td></tr>";
2648
2649}
2650echo "</table>";
2651?>
2652
2653
2654Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2655
2656
265713. Considerer the following entities and their relationships.
2658Student (Stud_id,name,class)
2659Competition (c_no,c_name,type)
2660Relationship between student and competition is many-many with attribute rank and year.
2661Create a RDB in 3NF for the above and solve the following. Using above database write a script in PHP to accept a competition name from user and display information of student who has secured 1st rank in that competition.
2662Html file :
2663<html>
2664<body>
2665<form action="slip_13.php" method="get">
2666Enter the name of competition :<input type=text name=cname><br>
2667<input type=submit value=SUBMIT>
2668</form>
2669</body>
2670<html>
2671
2672Phpfile :
2673<?php
2674 $c_name = $_GET['cname'];
2675 $con = mysql_connect("localhost","root","");
2676 $d = mysql_select_db("bca_programs",$con);
2677 $q = mysql_query("select student_slip_13.stud_id,stud_name,stud_class from student_slip_13,compitition_slip_13,sc_slip_13 where student_slip_13.stud_id=sc_slip_13.stud_id and sc_slip_13.c_no=compitition_slip_13.c_no and c_name='$c_name' and rank=1");
2678echo "<table>";
2679echo "<tr><td>Student Id |</td><td>Student Name |</td><td>Student Class</td></tr>";
2680while($row = mysql_fetch_array($q))
2681 {
2682echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
2683 }
2684echo "</table>";
2685mysql_close();
2686
2687?>
2688
2689
2690
2691-------------------------------------------------------------------------------------------------------------------------
2692
2693SLIP_14
2694
2695
2696
2697Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2698
2699SLIP 14:
2700Write a client server programs which displays the server machines date and time on the
2701client machine.
2702/* Server_Slip14_1*/
2703import java.net.*;
2704import java.io.*;
2705import java.util.Date;
2706public class Server_Slip14_1
2707{
2708public static void main(String g[])throws UnknownHostException, IOException
2709{
2710ServerSocket ss=new ServerSocket(4444);
2711System.out.println("server started");
2712Socket s=ss.accept();
2713System.out.println("Client connected");
2714Date d=new Date();
2715int m=d.getMonth();
2716m=m+1;
2717int y=d.getYear();
2718y=y+1900;
2719String time=""+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+" Date is
2720"+d.getDate()+"/"+m+"/"+y;
2721OutputStream os=s.getOutputStream();
2722DataOutputStream dos=new DataOutputStream(os);
2723dos.writeUTF(time);
2724}
2725}
2726/* client_Slip14_1*/
2727import java.net.*;
2728import java.io.*;
2729importjava.util.*;
2730public class Client_Slip14_1
2731{
2732public static void main(String args[]) throws Exception
2733{
2734Socket s = new Socket("localhost",4444);
2735DataInputStream dos = new DataInputStream(s.getInputStream());
2736String time = dos.readUTF();
2737System.out.println("Current date and time is "+time);
2738}
2739
2740}
2741
2742
2743Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2744
2745
2746Slip 14_2 : Write a JDBC program in java to display details of Book_Sales(SalesID, Date,
2747Amount)
2748*of selected month in JTable. Book_sales table is already created. (Use JCombo
2749component for Month selection)
2750import java.io.*;
2751import java.awt.*;
2752import java.awt.event.*;
2753import javax.swing.*;
2754import java.sql.*;
2755class Slip14_2 extends JFrame implements ItemListener
2756{
2757JComboBox cb;
2758String head[]={"SalesID","Date","Amount"};
2759String as[][]=new String[10][10];
2760Slip14_2()
2761{
2762setLayout(null);
2763cb=new JComboBox();
2764cb.setBounds(350,20,100,20);
2765cb.addItem("JAN");
2766cb.addItem("FEB");
2767cb.addItem("MARCH");
2768cb.addItem("APRIL");
2769cb.addItem("MAY");
2770cb.addItem("JUN");
2771cb.addItem("JULY");
2772cb.addItem("AUG");
2773cb.addItem("SEP");
2774cb.addItem("OCT");
2775cb.addItem("NOV");
2776cb.addItem("DEC");
2777add(cb);
2778cb.addItemListener(this);
2779setSize(500,400);
2780setVisible(true);
2781}
2782public void itemStateChanged(ItemEvent ie)
2783{
2784String str=cb.getSelectedItem().toString();
2785try
2786{
2787Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2788Connection cn=DriverManager.getConnection("jdbc:odbc:dsn");
2789Statement st=cn.createStatement();
2790ResultSet rs=st.executeQuery("select * from BookSales where Date like '"+str+"%'");
2791int i=0;
2792while(rs.next())
2793{
2794as[i][0]=rs.getString("SalesID");
2795as[i][1]=rs.getString("Date");
2796as[i][2]=rs.getString("Amount");
2797i++;
2798}
2799cn.close();
2800JTable jt=new JTable(as,head);
2801JScrollPane pane=new JScrollPane(jt);
2802pane.setBounds(0,0,300,400);
2803add(pane);
2804}catch(Exception e)
2805{
2806System.out.println(e);
2807}
2808}
2809public static void main(String args[])
2810{
2811new Slip14_2();
2812}
2813}
2814
2815
2816
2817Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2818
2819
282014. Create student registration form and display details in the next page. (Use sticky form concept).
2821
2822
2823
2824Slip14.php
2825<html>
2826<body>
2827<table border=1>
2828<tr><thcolspan=2>
2829<form action="<?php echo $_SERVER['PHP_SELF']?>" method=post>
2830<tr><td>Enter Name</td><td><input type="text" name="nm" value="<?php if(isset($_POST['nm']))echo $_POST['nm']?>"</td></tr>
2831<tr><td>Enter Roll No</td><td><input type="text" name="rno" value="<?php if(isset($_POST['rno']))echo $_POST['rno']?>"</td></tr>
2832<tr><td>Enter State</td><td><input type="text" name="st" value="<?php if(isset($_POST['st']))echo $_POST['st']?>" </td></tr>
2833<tr><td>Enter City</td><td><input type="text" name="ct" value="<?php if(isset($_POST['ct']))echo $_POST['ct']?>"</td></tr>
2834<tr><td>Enter Percentage</td><td><input type="text" name="per" value="<?php if(isset($_POST['per']))echo $_POST['per']?>"</td></tr>
2835<tr><td><input type="submit" value="Submit" name="submit"></td>
2836<td><input type="reset" value="Reset"></td></tr>
2837</form>
2838</table>
2839<?php
2840if(isset($_POST['submit']))
2841{
2842$nm=$_POST['nm'];
2843$rno=$_POST['rno'];
2844$st=$_POST['st'];
2845$ct=$_POST['ct'];
2846$perc=$_POST['per'];
2847}
2848if((!empty($nm)) && (!empty($rno)) && (!empty($st)) && (!empty($ct)) && (!empty($perc)))
2849{
2850setcookie('nm',$nm);
2851setcookie('rno',$rno);
2852setcookie('st',$st);
2853setcookie('ct',$ct);
2854setcookie('perc',$perc);
2855
2856header("location:slip14_1.php");
2857}
2858?>
2859</body>
2860</html>
2861SLIP14_1.php
2862<?php
2863echo "Your name is $_COOKIE[nm] </br>";
2864echo "Your Roll No Is : $_COOKIE[rno]</br>";
2865echo "Your State Is : $_COOKIE[st]</br>";
2866echo "Your City Is : $_COOKIE[ct]</br>";
2867echo "Your Percentage Is : $_COOKIE[perc]</br>";
2868
2869?>
2870
2871
2872
2873Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2874
2875
2876
287714. Write Ajax program to print Movie details by selecting an Actor’s name. Create table MOVIE and ACTOR as follows with 1 : M cardinality MOVIE (mno, mname, release_yr) and ACTOR(ano, aname).
2878Html file :
2879<html>
2880<head>
2881<script type="text/javascript">
2882function display(a_name)
2883{
2884 // alert("hi");
2885varob=false;
2886ob=new XMLHttpRequest();
2887ob.onreadystatechange=function()
2888 {
2889if(ob.readyState==4 &&ob.status==200)
2890document.getElementById("place").innerHTML=ob.responseText;
2891 }
2892ob.open("GET","slip_14.php?a_name="+a_name,true);
2893ob.send();
2894}
2895</script>
2896</head>
2897<body>
2898Select Actor Name :
2899<select name="a_name" onchange="display(this.value)">
2900<option value="">select actor</option>
2901<option value="Swapnil Joshi">Swapnil Joshi</option>
2902<option value="Sachit">Sachit</option>
2903</select>
2904<div id="place"></div>
2905</body>
2906</html>
2907
2908Phpfile :
2909<?php
2910 $a_name = $_GET['a_name'];
2911 $con = mysql_connect("localhost","root","");
2912 $d = mysql_select_db("bca_programs",$con);
2913 $q = mysql_query("select movie.m_no,m_name,r_year from movie,actor_slip_14 where a_name='$a_name' && actor_slip_14.m_no=movie.m_no"); //echo $q;
2914echo "<table border=1>";
2915echo "<tr><th>Movie No</th><th>Movie Name</th><th>Release Year</th></tr>";
2916while($row = mysql_fetch_array($q))
2917 {
2918echo "<tr>";
2919echo "<td>".$row[0]."</td>";
2920echo "<td>".$row[1]."</td>";
2921echo "<td>".$row[2]."</td>";
2922echo "</tr>";
2923 }
2924echo "</table>";
2925?>
2926
2927
2928
2929---------------------------------------------------------------------------------------------------------------------------------------
2930
2931SLIP_15
2932
2933
2934
2935Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2936
2937SLIP15: Write a JDBC program in java to update an address of given customer(cid,cname,address) and display updated details.
2938
2939import java.sql.*;
2940import java.io.*;
2941class Slip15_1
2942{
2943 public static void main(String args[])throws Exception
2944 {
2945 Connection con;
2946 Statement stmt;
2947 PreparedStatement ps;
2948 String name;
2949 try
2950 {
2951 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2952 con=DriverManager.getConnection("jdbc:odbc:dsn");
2953 if(con==null)
2954 {
2955 System.out.println("Connection Failed....");
2956 System.exit(1);
2957 }
2958
2959 System.out.println("Connection Established...");
2960
2961 stmt=con.createStatement();
2962
2963 String query="Update Customer set address=? where name=?";
2964 ps=con.prepareStatement(query);
2965
2966 DataInputStream di = new DataInputStream(System.in);
2967 System.out.println("Enter Customer name for Update:");
2968 name=di.readLine();
2969
2970 System.out.println("Enter new Address:");
2971 String addr=di.readLine();
2972 ps.setString(1,addr);
2973 ps.setString(2,name);
2974 int no=ps.executeUpdate();
2975
2976 if(no==0)
2977 {
2978 System.out.println("Not updated in table....");
2979 System.out.println("Name Not match"+name);
2980 }
2981 else
2982 {
2983 System.out.println("Succesfully updated in table....");
2984
2985 ps=con.prepareStatement("select * from Customer where name=?");
2986 ps.setString(1,name);
2987 ResultSet rs=ps.executeQuery();
2988 System.out.println("cid\t"+"Name\t"+"address\t"+"ph_no");
2989 while(rs.next())
2990 {
2991 System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4));
2992 }
2993 }
2994 con.close();
2995
2996 }
2997 catch(Exception e)
2998 {
2999 System.out.println(e);
3000 }
3001 }
3002
3003
3004
3005Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX .HTML
3006
3007
3008<html>
3009<body>
3010<form method="Post" action="http://localhost:8080/Stud">
3011
3012Enter Roll No :<input type="text" name="txtsno"><br><br>
3013Enter Name :<input type="text" name="txtnm"><br><br>
3014Enter class : <input type="text" name="txtclass"><br><br>
3015Subject 1 : <input type="text" name="txtsub1"><br><br>
3016Subject 2 :<input type="text" name="txtsub2"><br><br>
3017Subject 3 : <input type="text" name="txtsub3"><br><br>
3018
3019<input type="submit" value="Result">
3020</form>
3021</body>
3022</html>
3023
3024
3025Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3026
3027
3028import java.io.*;
3029import javax.servlet.*;
3030import javax.servlet.http*;
3031public class student extends HttpServlet
3032{
3033 public void doPost(HttpServletResponse res, HttpServletRequest req)throws IOException
3034 {
3035 int sno,s1,s2,s3,total;
3036 String snm,sclass;
3037 float per;
3038 res.setContentType=("text/html");
3039 Printwriter out.res.getWriter();
3040 sno=Integer.parseInt(req.getParameter("txtsno"));
3041 s1=Integer.parseInt(req.getParameter("txtsub1"));
3042 s2=Integer.parseInt(req.getParamter("txtsub2"));
3043 s3=Integer.parseInt(req.getParameter("txtsub3"));
3044 snm=req.getParameter("txtnm");
3045 sclass=req.getParameter("txtsclass");
3046 total=s1+s2+s3;
3047 per=(total/3);
3048 out.println("<html><head>");
3049 out.println("<body>");
3050 out.println("<h2>Student Details...</h2>");
3051 out.println("<b>Student NO: "+sno+"<br>");
3052 out.println("<b>Student Name: "+snm+"<br>");
3053 out.println("<b>Student Class: "+sclass+"<br>");
3054 out.println("<b><i>Subject1:</b></i>"+s1+"<br>");
3055 out.println("<b><i>Subject2:</b></i>"+s2+"<br>");
3056 out.println("<b><i>Subject3:</b></i>"+s3+"<br>");
3057 out.println("<b><i>Total :</b></i>"+total+"<br>");
3058 out.println("<b><i>Percentage :</b></i>"+per+"<br>");
3059 if(per<50)
3060 out.println("<h1><i>Pass Class</i></h1>");
3061 else if(per<55 && per>50)
3062 out.println("<h1><i>Second class</i></h1>");
3063 else if(per<60 && per>=55)
3064 out.println("<h1><i>Higher class</i></h1>");
3065 out.close();
3066 }
3067}
3068
3069
3070Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3071
3072
3073HTML File
3074
3075<html>
3076<form action=slip15.php method=post enctype=multipart/form-data>
3077<input type=file name=file></br>
3078<input type=submit value="Upload">
3079</form>
3080</html>
3081
3082
3083Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3084
3085
3086
3087PHP File
3088
3089<?php
3090
3091echo "File name : ".$_FILES['file']['name']."</br>";
3092echo "File Size: ".$_FILES['file']['size']."</br>";
3093echo "File Name on Sever: ".$_FILES['file']['tmp_name']."</br>";
3094echo "File Error: ".$_FILES['file']['error']."</br>";
3095
3096print_r($_FILES);
3097
3098?>
3099
3100
3101
3102Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3103
3104
310515. Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like Google suggestions. Hint create array of suggestions and matching string will be displayed).
3106Html file :
3107<html>
3108<head>
3109<script type="text/javascript" >
3110function m1(str)
3111 {
3112varob=false;
3113ob=new XMLHttpRequest();
3114 ob.open("GET","slip_15.php?q="+str);
3115 ob.send();
3116 ob.onreadystatechange=function()
3117 {
3118if(ob.readyState==4 &&ob.status==200)
3119 {
3120 document.getElementById("a").innerHTML=ob.responseText;
3121 }
3122 }
3123 }
3124</script>
3125</head>
3126<body>
3127<form>
3128Search<input type=text name=search size="20" onkeyup="m1(form.search.value)">
3129<input type=button value="submit" onclick="m1(form.search.value)">
3130</form>
3131suggestions :<span id="a"></span><br>
3132</body>
3133</html>
3134
3135Phpfile :
3136<?php
3137$a=array("pune","satara","nashik","sangli","mumbai","murud","akola","dound","dhule","ratnagiri","rajpur");
3138$q=$_GET['q'];
3139if(strlen($q)>0)
3140{
3141 $match="";
3142for($i=0;$i<count($a);$i++)
3143 {
3144 if(strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
3145 {
3146if($match=="")
3147 $match=$a[$i];
3148else $match=$match.",".$a[$i];
3149 }
3150 }
3151if($match=="")
3152echo "No Suggestios";
3153else echo $match;
3154}
3155?>
3156
3157
3158
3159-------------------------------------------------------------------------------------------------------------
3160
3161
3162SLIP_16
3163
3164
3165import java.sql.*;
3166import java.io.*;
3167 class slip15
3168{
3169 public static void main(String args[])throws IOException
3170 {
3171 Connection con;
3172 Statement st;
3173 PrparedStatement ps;
3174 String name;
3175
3176 try
3177 {
3178 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
3179 con=DriverManager.getConnection("jdbc:odbc:dsn16");
3180
3181 if(con==null)
3182 {
3183 System.out.println("Connection faild...");
3184 System.exit(1);
3185 }
3186 System.out.println("Connection Established");
3187
3188 st.CreateStatement();
3189 String query("Update customer set add=? where cname=? ");
3190
3191 ps=con.prepareStatement(query);
3192
3193 DataInputStreamReader di=new DataInputStreamReader(System.in);
3194 System.out.println("Enter Cutomer Name: ");
3195 name=di.readLine();
3196
3197 System.out.println("Enter Address: ");
3198 string add=di.readLine();
3199 ps.setString(1,add);
3200 ps.setstring(2,name);
3201
3202 int no=ps.executeUpdate();
3203
3204 if(no==0)
3205 {
3206 System.out.println("records are not Updated...");
3207 System.out.println("Name is not matching...."+name);
3208 }
3209 else
3210 System.out.println("Records are added Successfully");
3211
3212 ps=con.prepareStatement("select * from customer where name=? ");
3213 ps.setString(1,name);
3214 resultSet rs=ps.executeQuery();
3215
3216 System.out.println("cid "+ "cname" + "add" + "phno");
3217 while(rs.next())
3218 {
3219 System.out.println("\n" rs.getInt(1)+ "\t" rs.getString(2)+ "\t" rs.getString(3)+ "\t" rs.getInt(4));
3220 }
3221 con.close();
3222 }
3223
3224 catch(Exception(e))
3225 {
3226
3227 System.out.println(e);
3228 }
3229}
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3241
3242
3243SLIP16 Q1. Write a JSP page, which accepts user name in a text box and greets the user according to the time on server machine.
3244
3245HTML:
3246
3247<%@page contentType="text/html" pageEncoding="UTF-8"%>
3248<!DOCTYPE html>
3249<html>
3250 <body>
3251 <form action="Slip16.jsp" method="post">
3252 Enter Your Name : <input type="text" name="name"><br>
3253
3254 <input type="submit" value="Submit">
3255 </form>
3256 </body>
3257</html>
3258
3259
3260
3261Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3262
3263,JSP
3264
3265
3266JSP:
3267
3268<%@page contentType="text/html" pageEncoding="UTF-8"%>
3269<!DOCTYPE html>
3270
3271<%
3272
3273 String name = request.getParameter("name");
3274
3275 Calendar rightnow = Calendar.getInstance();
3276 int time = rightnow.get(Calendar.HOUR_OF_DAY);
3277
3278 if(time > 0 && time <= 12)
3279 {
3280 out.println("Good Morning"+name);
3281 }
3282 else if(time >12 && time <=16)
3283 {
3284 out.println("Good Afternoon"+name);
3285 }
3286 else
3287 {
3288 out.println("Good Night"+name);
3289 }
3290%>
3291
3292
3293Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3294
3295
3296slip16 Q2
3297
3298class MyThread extends Thread
3299{
3300
3301 public MyThread(String s)
3302 {
3303 super(s);
3304 }
3305
3306 public void run()
3307 {
3308 System.out.println(getName()+" thread created.");
3309 while(true)
3310 {
3311 System.out.println(this);
3312 int s = (int)(Math.random()*5000);
3313 System.out.println(getName()+" is sleeping for "+s+"msec");
3314 try{
3315 Thread.sleep(s);
3316 }catch(Exception e){}
3317 }
3318 }
3319}
3320
3321class ThreadLifeCycle{
3322 public static void main(String args[]){
3323 MyThread t1 = new MyThread("harshada"),
3324 t2 = new MyThread("visave");
3325 t1.start();
3326 t2.start();
3327
3328 try{
3329 t1.join();
3330 t2.join();
3331 }catch(Exception e){}
3332
3333 System.out.println(t1.getName()+" thread dead.");
3334 System.out.println(t2.getName()+" thread dead.");
3335 }
3336}
3337
3338
3339
3340
3341Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3342
3343
3344slip 16
3345Q 3
3346
3347<?php
3348 echo"<table border=2>";
3349 foreach($_SERVER as $k=>$v)
3350 {
3351 echo"<tr><td>".$k."</td><td>".$v."</td></tr>";
3352 }
3353 echo"</table>";
3354?>
3355
3356
3357-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-----------------------------------------------
3358
3359
3360SLIP_17
3361
3362Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3363
3364SLIP17: Write a java program which will display name and priority of current thread. Change name of Thread to MyThread and set the priority to 2 and display it on screen.
3365
3366class Slip17_1
3367{
3368 public static void main(String a[])
3369 {
3370 String S;
3371 int p;
3372
3373 Thread t = Thread.currentThread();
3374
3375 S = t.getName();
3376 System.out.println("\n Current Thread name : "+S);
3377
3378 p = t.getPriority();
3379 System.out.println("\n Current thread priority : "+p);
3380
3381 t.setName("My Thread");
3382 S = t.getName();
3383 System.out.println("\nChanged Name : "+S);
3384
3385 t.setPriority(2);
3386 p = t.getPriority();
3387 System.out.println("\nChanged Priority : "+p);
3388 }
3389}
3390
3391
3392
3393Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3394
3395
3396import java.awt.*;
3397import java.awt.event.*;
3398import javax.swing.*;
3399import java.sql.*;
3400
3401class DDLOperations extends JFrame{
3402 private JPanel panNorth,panSouth;
3403 private JLabel lblQuery;
3404 private JTextArea txtQuery;
3405 private JButton btnCreate,btnAlter,btnDrop;
3406
3407 public DDLOperations(){
3408 lblQuery = new JLabel("Type DDL Query");
3409 txtQuery = new JTextArea(4,50);
3410
3411 panNorth = new JPanel();
3412 panNorth.add(lblQuery);
3413 panNorth.add(new JScrollPane(txtQuery));
3414
3415 btnCreate = new JButton("Create Table");
3416 btnAlter = new JButton("Alter Table");
3417 btnDrop = new JButton("Drop Table");
3418
3419 panSouth = new JPanel();
3420 panSouth.add(btnCreate);
3421 panSouth.add(btnAlter);
3422 panSouth.add(btnDrop);
3423
3424 setTitle("DDL Operations");
3425 setSize(400,300);
3426 add(panNorth,"North");
3427 add(panSouth,"South");
3428 setVisible(true);
3429 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3430
3431 ButtonHandler bh = new ButtonHandler();
3432 btnCreate.addActionListener(bh);
3433 btnAlter.addActionListener(bh);
3434 btnDrop.addActionListener(bh);
3435 }
3436
3437 class ButtonHandler implements ActionListener{
3438 public void actionPerformed(ActionEvent ae){
3439 try{
3440 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
3441 con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
3442
3443 String sql = txtQuery.getText();
3444 Statement s = con.createStatement();
3445 s.execute(sql);
3446 txtQuery.setText("");
3447 }
3448 catch(Exception e){
3449 JOptionPane.showMessageDialog(null,e);
3450 }
3451 }
3452 }
3453
3454 public static void main(String args[]){
3455 new DDLOperations();
3456 }
3457}
3458
3459
3460
3461Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3462
3463
3464
346517. Write a PHP program to accept username and password from the user. Validate it against the login table in the database. If there is a mismatch between username and password, then, display the error message as ?invalid user name and password; else display the message as ?Login successful? on the browser.
3466
3467Html file :
3468<html>
3469<head>
3470<title>login</title>
3471</head>
3472<body>
3473<center>
3474<form action="slip_16.php" method="post">
3475<table>
3476<tr><td><label>Email id :</label></td><td><input type=text name=emailid></td></tr>
3477<tr><td><label >Password :</label></td><td><input type=password name=password></td></tr>
3478<tr><td><input type=submit value="login & continue"></td><td></td></tr>
3479</table>
3480</form>
3481</center>
3482</body>
3483</html>
3484Phpfile :
3485
3486<?php
3487$con=mysql_connect("localhost","root","") or die("I cannot connect"); //echo "connected successfuly";
3488$d=mysql_select_db("bca_programs",$con);
3489$q=mysql_query("select * from login");
3490$emailid=$_REQUEST['emailid']; //echo $emailid;
3491$password=$_REQUEST['password'];
3492$n=0;
3493while($row=mysql_fetch_array($q))
3494{
3495if($row[0]==$emailid&& $row[1]==$password)
3496 $n=1;
3497}
3498if($n==1)
3499echo "<center><h3>WELCOME USER</h3><center>";
3500else
3501echo "<i>Emailid or Password Missmatch</i>";
3502?>
3503
3504
3505
3506----------------------------------------------------------------------------------------------
3507
3508
3509SLIP_18
3510
3511
3512Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3513
3514
3515SLIP18 : Write a java program using multithreading to execute the threads sequentially.(Use Synchronized Method)
3516
3517class PrintDemo
3518{
3519 public void printCount()
3520 {
3521 try
3522 {
3523 for(int i = 5; i > 0; i--)
3524 {
3525 System.out.println("Counter --- " + i );
3526 }
3527 }
3528 catch (Exception e)
3529 {
3530 System.out.println("Thread interrupted.");
3531 }
3532 }
3533
3534}
3535
3536class ThreadDemo extends Thread
3537{
3538 private Thread t;
3539 private String threadName;
3540 PrintDemo PD;
3541
3542 ThreadDemo( String name, PrintDemo pd)
3543 {
3544 threadName = name;
3545 PD = pd;
3546 }
3547 public void run()
3548 {
3549 synchronized(PD)
3550 {
3551 PD.printCount();
3552 }
3553 System.out.println("Thread " + threadName + " exiting.");
3554 }
3555
3556 public void start ()
3557 {
3558 System.out.println("Starting " + threadName );
3559 if (t == null)
3560 {
3561 t = new Thread (this, threadName);
3562 t.start ();
3563 }
3564 }
3565
3566}
3567
3568public class Slip18_1
3569{
3570 public static void main(String a[])
3571 {
3572
3573 PrintDemo PD = new PrintDemo();
3574
3575 ThreadDemo T1 = new ThreadDemo( "Thread - 1 ", PD );
3576 ThreadDemo T2 = new ThreadDemo( "Thread - 2 ", PD );
3577
3578 T1.start();
3579 T2.start();
3580
3581 // wait for threads to end
3582 try
3583 {
3584 T1.join();
3585 T2.join();
3586 }
3587 catch( Exception e)
3588 {
3589 System.out.println(e);
3590 }
3591 }
3592}
3593
3594
3595
3596Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3597
3598
3599mport java.io.*;
3600import javax.servlet.*;
3601import javax.servlet.http.*;
3602import java.util.*;
3603
3604 public class info_check extends HttpServlet
3605 {
3606 public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
3607 {
3608 try
3609 {
3610 res.setContentType("text/html");
3611 PrintWriter out = res.getWriter();
3612 out.println("<html>");
3613 out.println("<body>");
3614 java.util.Properties p=System.getProperties();
3615 out.println("Server Name :"+req.getServerName()+"<br>");
3616 out.println("Operating System Name :"+p.getProperty("Linux")+"<br>");
3617 out.println("IP Address :"+req.getRemoteAddr()+"<br>");
3618 out.println("Remote User:"+req.getRemoteUser()+"<br>");
3619 out.println("Remote Host:"+req.getRemoteHost()+"<br>");
3620 out.println("Local Name :"+req.getLocalName()+"<br>");
3621 out.println("Server Port:"+req.getServerPort()+"<br>");
3622 out.println("Servlet Name :"+this.getServletName()+"<br>");
3623 out.println("Protocol Name :"+req.getProtocol()+"<br>");
3624 out.println("</html>");
3625 out.println("</body>");
3626 }
3627 catch(Exception e)
3628 {
3629 e.printStackTrace();
3630
3631 }
3632 }
3633 }
3634
3635
3636Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3637
3638
363918. Create a XML file which gives details of books available in “ABC Bookstore†from following categories
36401) Technical
36412) Cookin
36423) YOGA
3643
3644
3645
3646Xml file :
3647
3648<?xml version='1.0' ?>
3649<ABC_Bookstore>
3650<books category="technical">
3651<book_no>1</book_no>
3652<book_name>def</book_name>
3653<author_name>xxx</author_name>
3654<price>100</price>
3655<year>1990</year>
3656</books>
3657<books category="Cooking">
3658<book_no>2</book_no>
3659<book_name>ccc</book_name>
3660<author_name>aaa</author_name>
3661<price>200</price>
3662<year>1950</year>
3663</books>
3664<books category="YOGA">
3665<book_no>3</book_no>
3666<book_name>ddd</book_name>
3667<author_name>zzz</author_name>
3668<price>150</price>
3669<year>2016</year>
3670</books>
3671</ABC_Bookstore>
3672
3673
3674
3675Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3676
3677
3678
367918. Write a PHP program to implement Create, Read, Update and Display operations on
3680Teacher table with attributes(tid, tname,address, subject). (Use Radio Buttons).
3681
3682Html file :
3683<slip_18.html>
3684<html>
3685<body>
3686<form action="slip_18.php" method="get">
3687<center><h2>Teacher Details :</h2><br>
3688<table>
3689<tr><td><input type=radio name=r value="1"></td><td><b>Create Teacher Table:</b></td></tr>
3690<tr><td><input type=radio name=r value="2"></td><td><b> Insert Values :</b></td></tr>
3691<tr><td><input type=radio name=r value="3"></td><td><b>Update Values :</b></td></tr>
3692<tr><td><input type=radio name=r value="4"></td><td><b>Display :</b></td></tr>
3693</table>
3694<br><input type=submit value=Submit name=submit>
3695</center>
3696</form>
3697</body>
3698</html>
3699
3700Phpfile :
3701(slip_18.php)
3702<?php
3703$r=$_GET['r'];
3704$con =mysql_connect("localhost","root","");
3705$d =mysql_select_db("bca_programs",$con);
3706if($r==1)
3707{
3708 $q=mysql_query("create table teacher_slip_18(tidint,tnamevarchar(10),subjectvarchar(10),addressvarchar(20))");
3709echo "<center><b><h2> Table Created Successfully.....!!!</h2><b></center>";
3710
3711}
3712else if($r==2)
3713{
3714header("location:slip_18_insert.html");
3715}
3716else if($r==3)
3717{
3718header("location:slip_18update.html");
3719}
3720else if($r==4)
3721{
3722$q1=mysql_query("select *from teacher_slip_18");
3723echo "<center>";
3724echo "<table border=1 width=30% height=20%>";
3725echo "<h2><tr><td><b>Teacher id </b></td>
3726 <td><b>Teacher Name<b></td>
3727 <td><b>Subject<b></td>
3728 <td><b>Address<b></td></tr></h2>";
3729 while($row=mysql_fetch_array($q1))
3730{
3731Echo"<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td></tr>";
3732}
3733echo "</table>";
3734echo "</center>";
3735}
3736?>
3737
3738<slip_18_insert.html>
3739<html>
3740<body>
3741<form action="slip_18_insert.php" method="get">
3742<center><h2>Enter Teacher Details :</h2><br>
3743<table>
3744<tr><td>Enter Teacher id :</td><td><input type=text name=tid></td></tr>
3745<tr><td>Enter Teacher name :</td><td><input type=text name=tname></td></tr>
3746<tr><td>Enter Subject :</td><td><input type=text name=subject></td></tr>
3747<tr><td>Enter Address :</td><td><input type=text name=add></td></tr>
3748<tr><td><input type=submit value=Show name=submit></td></tr>
3749</table>
3750</center>
3751</form>
3752</body>
3753</html>
3754
3755
3756(slip_18_insert.php)
3757<?php
3758 $tid=$_GET['tid'];
3759 $tname=$_GET['tname'];
3760 $subjectt=$_GET['subject'];
3761 $add=$_GET['add'];
3762$con =mysql_connect("localhost","root","");
3763$d =mysql_select_db("bca_programs",$con);
3764$q2=mysql_query("insert into teacher_slip_18 values($tid,'$tname',$subject,'$add')");
3765echo "<center><b><h2> Values Inserted Successfully.....!!!</h2><b></center>";
3766?>
3767(slip_18_update.html)
3768<?php
3769$edit=$_GET['edit'];
3770$c=mysql_connect("localhost","root","");
3771$d=mysql_select_db("bca_programs",$c);
3772$q=mysql_query("select * from emp_slip_18");
3773$row=mysql_fetch_array($q);
3774?>
3775
3776<html>
3777<body>
3778<form action="slip_18_update.php" method="get">
3779<center><h2>Update teacher Details :</h2><br>
3780<table>
3781<tr><td> Teacher id :</td><td><input type=text name=tid value="<?php echo $row[0];?>"></td></tr>
3782<tr><td> Teacher name :</td><td><input type=text name=tname value="<?php echo $row[1];?>"></td></tr>
3783<tr><td> Subject :</td><td><input type=text name=subject value="<?php echo $row[3];?>"></td></tr>
3784<tr><td> Address :</td><td><input type=text name=add value="<?php echo $row[4];?>"></td></tr>
3785<tr><td><input type=submit value=Show name=submit></td></tr>
3786</table>
3787</center>
3788</form>
3789</body>
3790</html>
3791(slip_18_update1.php)
3792<?php
3793 $a_no=$_GET['tid'];
3794 $a_name=$_GET['tname'];
3795 $a_sal=$_GET['subject'];
3796 $a_add=$_GET['add'];
3797$con =mysql_connect("localhost","root","");
3798$d =mysql_select_db("bca_programs",$con);
3799$r=mysql_query("update teacher_slip_18 set tid=$tid,tname='$tname',subject='$subject',address='$add' where tid=$tid");
3800?>
3801
3802
3803
3804
3805--------------------------------------------------------------------------------
3806
3807SLIP_19
3808
3809
3810Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3811
3812JSP FILE:
3813<%@page contentType="text/html" pageEncoding="UTF-8"%>
3814<!DOCTYPE html>
3815<html>
3816<body>
3817<font color=red>
3818<%! int i,n;
3819String s1;
3820%>
3821<% s1=request.getParameter("num");
3822n=s1.length();
3823i=0;
3824do
3825{
3826 char ch=s1.charAt(i);
3827 switch(ch)
3828 {
3829 case '0': out.println("Zero ");break;
3830 case '1': out.println("One ");break;
3831 case '2': out.println("Two ");break;
3832 case '3': out.println("Three ");break;
3833 case '4': out.println("Four ");break;
3834 case '5': out.println("Five ");break;
3835 case '6': out.println("Six ");break;
3836 case '7': out.println("Seven ");break;
3837 case '8': out.println("Eight ");break;
3838 case '9': out.println("Nine ");break;
3839 }
3840 i++;
3841}while(i<n);
3842%>
3843</font>
3844</body>
3845</html>
3846
3847
3848Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTML
3849
3850SLIP19: Create a JSP page to accept a number from an user and display it in words: Example: 123 One Two Three. The output should be in red color.
3851
3852HTML FILE :
3853
3854<!DOCTYPE html>
3855<html>
3856<body>
3857<form method=get action="Slip19.jsp">
3858Enter Any Number : <input type=text name=num><br><br>
3859<input type=submit value="Display">
3860</form>
3861</body>
3862</html>
3863
3864
3865Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3866
3867
3868import java.applet.Applet;
3869import java.io.*;
3870import java.awt.*;
3871import java.util.*;
3872/*
3873<applet code="Smile.java" height=200 width=200>
3874</applet>
3875*/
3876
3877public class Smile extends Applet implements Runnable
3878{
3879Thread t;
3880int x=0;
3881
3882public void run()
3883{
3884repaint();
3885}
3886
3887public void init()
3888{
3889Smile s1=new Smile();
3890t=new Thread(s1);
3891t.start();
3892setSize(500,500);
3893setBackground(Color.blue);
3894}
3895
3896public void paint(Graphics g)
3897{
3898if(x==0)
3899{
3900g.drawOval(40,40,130,130);
3901g.drawOval(57,75,20,20);
3902g.drawOval(110,75,20,20);
3903g.drawArc(60,110,80,40,180,180);
3904x=1;
3905}
3906else if(x==1)
3907{
3908g.drawOval(40,40,130,130);
3909g.drawOval(57,75,20,20);
3910g.drawOval(110,75,20,20);
3911g.drawArc(60,110,80,40,-180,-180);
3912x=0;
3913}
3914try
3915{
3916Thread.sleep(2000);
3917}
3918catch(Exception e)
3919{
3920e.printStackTrace();
3921}
3922repaint();
3923}
3924}
3925
3926
3927Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3928
392919. Write a PHP script to accept a string and then display each word of string in reverse order. (use concept of self processing form)
3930
3931php file :
3932
3933<html>
3934<body>
3935<form method=post action="<?php echo $_SERVER['PHP_SELF'] ?>">
3936Enter String : <input type=text name=str1><br>
3937<input type=submit name=submit>
3938</form>
3939<?php
3940if(isset($_POST['submit']))
3941 {
3942 $str=$_POST['str1'];
3943 $str2=strrev($str);
3944echo"<br>".$str2;
3945 }
3946?>
3947</body>
3948</html>
3949
3950
3951
3952Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3953
3954
395519. Consider the following relational database:
3956 Project (P_Group_No, Project_Title)
3957 Student (Seat no, Name, Class, P_Group_No)
3958Write a PHP script to accept project title and display list of students those who are
3959working in a particular project.
3960Html file :
3961<html>
3962<body>
3963<form action="slip_19.php" method="get">
3964<b>Enter the title of project :: </b><input type=text name=ptitle><br>
3965<input type=submit value=SUBMIT>
3966</form>
3967</body>
3968</html>
3969
3970Phpfile :
3971<?php
3972 $ptitle = $_GET['ptitle'];
3973 $con =mysql_connect("localhost","root","");
3974 $d =mysql_select_db("bca_programs",$con);
3975 $q =mysql_query("select s_name from student_slip19,project where project_title='$ptitle' && student_slip19.p_group_no=project.p_group_no");
3976echo "Student Name :<br>";
3977while($row = mysql_fetch_array($q))
3978 {
3979echo $row['s_name'];
3980 }
3981mysql_close();
3982?>
3983
3984
3985------------------------------------------------------------------------------------
3986
3987SLIP_20
3988
3989
3990Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3991
3992SLIP 20: Write a JSP program to display the details of Hospital (HNo, HName, Address) in tabular form on browser
3993<%@page contentType="text/html" pageEncoding="UTF-8"%>
3994<!DOCTYPE html>
3995
3996<html><body>
3997<%@ page import="java.sql.*;" %>
3998<%! int hno;
3999String hname,address; %>
4000<%
4001
4002try{
4003 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
4004 Connection cn=DriverManager.getConnection("jdbc:odbc:hospital_data","","");
4005
4006 Statement st=cn.createStatement();
4007 ResultSet rs=st.executeQuery("select * from Hospital");
4008 %>
4009 <table border="1" width="40%">
4010 <tr>
4011 <td>Hospital No</td>
4012 <td>Name</td>
4013 <td>Address</td>
4014 </tr>
4015 <% while(rs.next())
4016 {
4017 %>
4018 <tr> <td><%= rs.getInt("hno") %></td>
4019 <td><%= rs.getString("hname") %></td>
4020 <td><%= rs.getString("address") %></td>
4021 </tr>
4022 <%
4023 }
4024 cn.close();
4025}catch(Exception e)
4026{
4027 out.println(e);
4028}
4029%>
4030</body></html>
4031
4032
4033
4034
4035Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CLEINT
4036
4037
4038client side:
4039
4040import java.io.*;
4041import java.net.*;
4042import java.awt.*;
4043import java.awt.event.*;
4044
4045class ChatClient extends Frame{
4046 private TextArea taMsgs;
4047 private TextField txtMsg;
4048 private Button btnSend;
4049 private Panel panSouth;
4050
4051 private MyThread t;
4052
4053 private Socket s;
4054
4055 private DataInputStream fromServer;
4056 private DataOutputStream toServer;
4057
4058 public ChatClient(){
4059 taMsgs = new TextArea();
4060
4061 txtMsg = new TextField(40);
4062 btnSend = new Button("Send");
4063
4064 panSouth = new Panel();
4065 panSouth.add(txtMsg);
4066 panSouth.add(btnSend);
4067
4068 setTitle("Client");
4069 setSize(300,400);
4070 setLocation(100,100);
4071 add(taMsgs,"Center");
4072 add(panSouth,"South");
4073 setVisible(true);
4074
4075 addWindowListener(new WindowAdapter(){
4076 public void windowClosing(WindowEvent we){
4077 System.exit(0);
4078 }
4079 });
4080
4081 try{
4082 s = new Socket("localhost",5060);
4083
4084 fromServer = new DataInputStream(s.getInputStream());
4085 toServer = new DataOutputStream(s.getOutputStream());
4086
4087 t = new MyThread();
4088 t.start();
4089 }
4090 catch(Exception e){
4091 System.out.println(e);
4092 System.exit(0);
4093 }
4094
4095 btnSend.addActionListener(new ActionListener(){
4096 public void actionPerformed(ActionEvent ae){
4097 try{
4098 String str = txtMsg.getText();
4099 toServer.writeBytes(str+"\n");
4100 taMsgs.append("Me:"+str+"\n");
4101 txtMsg.setText("");
4102 txtMsg.requestFocus();
4103 }catch(Exception e){}
4104 }
4105 });
4106 }
4107
4108
4109 class MyThread extends Thread{
4110 public void run(){
4111 while(true){
4112 try{
4113 String str = fromServer.readLine();
4114 if(str!=null)
4115 taMsgs.append("You:"+str+"\n");
4116 }catch(Exception e){}
4117 }
4118 }
4119 }
4120
4121 public static void main(String args[]){
4122 new ChatClient();
4123 }
4124}
4125
4126
4127
4128Q2XXXXXXXXXXXXXXXXXXX SERVER
4129
4130
4131
4132server:
4133
4134import java.io.*;
4135import java.net.*;
4136import java.awt.*;
4137import java.awt.event.*;
4138
4139class ChatServer extends Frame{
4140 private TextArea taMsgs;
4141 private TextField txtMsg;
4142 private Button btnSend;
4143 private Panel panSouth;
4144
4145 private MyThread t;
4146
4147 private Socket s;
4148 private ServerSocket ss;
4149
4150 private DataInputStream fromClient;
4151 private DataOutputStream toClient;
4152
4153 public ChatServer(){
4154 taMsgs = new TextArea();
4155
4156 txtMsg = new TextField(40);
4157 btnSend = new Button("Send");
4158
4159 panSouth = new Panel();
4160 panSouth.add(txtMsg);
4161 panSouth.add(btnSend);
4162
4163 setTitle("Server");
4164 setSize(300,400);
4165 setLocation(100,100);
4166 add(taMsgs,"Center");
4167 add(panSouth,"South");
4168 setVisible(true);
4169
4170 addWindowListener(new WindowAdapter(){
4171 public void windowClosing(WindowEvent we){
4172 System.exit(0);
4173 }
4174 });
4175
4176 try{
4177 ss = new ServerSocket(5060);
4178
4179 s = ss.accept();
4180
4181 fromClient = new DataInputStream(s.getInputStream());
4182 toClient = new DataOutputStream(s.getOutputStream());
4183
4184 t = new MyThread();
4185 t.start();
4186 }
4187 catch(Exception e){
4188 System.out.println(e);
4189 System.exit(0);
4190 }
4191
4192 btnSend.addActionListener(new ActionListener(){
4193 public void actionPerformed(ActionEvent ae){
4194 try{
4195 String str = txtMsg.getText();
4196 toClient.writeBytes(str+"\n");
4197 taMsgs.append("Me:"+str+"\n");
4198 txtMsg.setText("");
4199 txtMsg.requestFocus();
4200 }catch(Exception e){}
4201 }
4202 });
4203 }
4204
4205
4206 class MyThread extends Thread{
4207 public void run(){
4208 while(true){
4209 try{
4210 String str = fromClient.readLine();
4211 if(str!=null)
4212 taMsgs.append("You:"+str+"\n");
4213 }catch(Exception e){}
4214 }
4215 }
4216 }
4217
4218 public static void main(String args[]){
4219 new ChatServer();
4220 }
4221}
4222
4223
4224
4225
4226Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4227
422820. Write PHP program to select list of subjects (use multivalued parameter) displays on next page.
4229
4230
4231HTML File
4232<html>
4233<head><title>Slip20
4234</title>
4235</head>
4236<form action=slip20.php method=get>
4237Select List of subjects
4238<select multiple name="subjects[]">
4239<option value="VB.NET">Vb.NET</option>
4240<option value="PHP">PHP</option>
4241<option value="JAVA">JAVA</option>
4242</select>
4243<input type=submit value="submit">
4244
4245</form>
4246</html>
4247PHP File
4248<?php
4249echo "You selected subjects are";
4250echo "</br>";
4251foreach($_GET['subjects'] as $s)
4252{
4253echo "$s</br>";
4254}
4255
4256?>
4257
4258
4259
4260Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4261
4262
426320. Consider the following entities and their relationships
4264Emp (emp_no,emp_name,address,phone,salary)
4265Dept (dept_no,dept_name,location)
4266Emp-Deptare related with one-many relationship. Create a RDB in 3NF for the above and solve following. Using above database write a PHP script which will
4267a) Insert employee records in table .
4268b) Print a salary statement in the format given below, for a given department. (Accept department name from the user).
4269Html file :
4270<html>
4271<body>
4272<form action="slip_20.php" method="get">
4273<center><h2>Fill Employee Details : </h2>
4274<table>
4275<tr><td>Enter Employee No :</td><td><input type=text name=e_no></td></tr>
4276<tr><td>Enter Employee Name :</td><td><input type=text name=e_nm></td></tr>
4277<tr><td>Enter Address :</td><td><input type=text name=add></td></tr>
4278<tr><td>Enter Phone :</td><td><input type=text name=ph></td></tr>
4279<tr><td>Enter Salary :</td><td><input type=text name=sal></td></tr>
4280<tr><td>Enter Department no :</td><td><input type=text name=d_no></td></tr>
4281<tr><td>Enter Department name :</td><td><input type=text name=d_nm></td></tr>
4282<tr><td>Enter Location :</td><td><input type=text name=loc></td></tr>
4283<tr><td></td><td><input type=submit value=OK></td></tr>
4284</table>
4285</center>
4286</form>
4287</body>
4288</html>
4289
4290Phpfile :
4291<?php
4292 $e_no = $_GET['e_no'];
4293 $e_name = $_GET['e_nm'];
4294 $add = $_GET['add'];
4295 $ph = $_GET['ph'];
4296 $sal = $_GET['sal'];
4297 $d_no = $_GET['d_no'];
4298 $d_nm = $_GET['d_nm'];
4299 $loc = $_GET['loc'];
4300 $con = mysql_connect("localhost","root","");
4301 $d = mysql_select_db("bca_programs",$con);
4302 $q = mysql_query("insert into emp values($e_no,'$e_name','$add',$ph,$sal)");
4303 $q1 = mysql_query("insert into dept values($d_no,'$d_nm','$loc',$e_no)");
4304 $q2 = mysql_query("select MIN(salary),MAX(salary),SUM(salary) from emp,dept where emp.emp_no=dept.emp_no");
4305echo "<tr><td>Minimum salary----</td><td>Maximum salary----</td><td>Sum of Salary</td></tr>";
4306while($row = mysql_fetch_array($q2))
4307 {
4308echo "<tr><td>".MIN(salary)."</td><td>".MAX(salary)."</td><td>".SUM(salary)."</td></tr>";
4309 }
4310mysql_close();
4311?>
4312
4313
4314
4315_--------------------------------------------------------------------------------------------
4316
4317SLIP_21
4318
4319
4320
4321
4322Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4323
4324
4325SLIP21: Write a JDBC Program in java to display the names of Employees starting with ‘S’
4326character
4327
4328
4329
4330
4331import java.sql.*;
4332class Slip21_1
4333{
4334 public static void main(String args[])
4335 { Connection con;
4336 try
4337 {
4338 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
4339 con=DriverManager.getConnection("jdbc:odbc:dsn");
4340 if(con==null)
4341 {
4342 System.out.println("Connection Failed....");
4343 System.exit(1);
4344 }
4345 System.out.println("Connection Established...");
4346
4347 Statement stmt=con.createStatement();
4348 ResultSet rs=stmt.executeQuery("select * from employee where name like 'S%'");
4349 System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
4350 while(rs.next())
4351 {
4352 System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));
4353 }
4354 }
4355 catch(Exception e)
4356 {
4357 System.out.println(e);
4358
4359 }
4360 }
4361}
4362
4363
4364
4365Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4366
4367HTMLXXXXXXXXXXXXXXX
4368
4369<html>
4370<body>
4371<form method="GET" action="http://localhost:8080/choice">
4372select your hobbie:<br>
4373<input type="radio" name="ch" value="painting">PAINTING<br>
4374<input type="radio" name="ch" value="drawing">DRAWING<br>
4375<input type="radio" name="ch" value="swiming">SWIMING<br>
4376<input type="radio" name="ch" value="singing">SINGING<br>
4377<br><input type="submit" value="select">
4378<br><input type="reset">
4379</form>
4380</body>
4381</html>
4382
4383
4384JAVA XXXXXXXXXX
4385
4386
4387import java.io.*;
4388import javax.servlet.*;
4389import javax.servlet.http.*;
4390
4391
4392 public class Setb21 extends HttpServlet
4393 {
4394
4395
4396 public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
4397 {
4398
4399 PrintWriter out = null;
4400 try
4401 {
4402 out=res.getWriter();
4403 String hb=req.getParameter("ch");
4404 Cookie c1=new Cookie("hobby",hb);
4405 out.println("hobby are:"+hb);
4406 //res.addCookie(c1);
4407 }
4408 catch(Exception e)
4409 {
4410 e.printStackTrace();
4411
4412 }
4413 }
4414 }
4415
4416
4417Q22 XXX
4418
4419setb2n.java
4420import java.io.*;
4421import javax.servlet.*;
4422import javax.servlet.http.*;
4423
4424
4425 public class setb2n extends HttpServlet
4426{
4427
4428 public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
4429 {
4430
4431 PrintWriter out = null;
4432 try
4433 {
4434 out=res.getWriter();
4435 Cookie c[]=req.getCookies();
4436 for(int i=0;i<c.length;i++)
4437 {
4438 String s1=c[i].getName();
4439 out.println("selected hobby are :"+s1);
4440 }
4441 }
4442 catch(Exception e)
4443 {
4444 e.printStackTrace();
4445 }
4446 }
4447 }
4448
4449
4450Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4451
4452
4453<html>
4454 <body>
4455 <form acion="<?php echo $_SERVER['PHP_SELF']?>" method="post">
4456string1: <input type="text" name=txt1 value="<?php if(isset($_POST['txt1'])) echo $_POST['txt1'];?>">
4457string2: <input type="text" name=txt2> value="<?php if(isset($_POST['txt2'])) echo $_POST['txt2'];?>">
4458<input type=submit value="submit">
4459 </form>
4460<?php
4461 $s1=$_POST['txt1'];
4462 $s2=$_POST['txt2'];
4463 if(strcomp($s1,$s2)==0)
4464 echo "Strings are mathcing";
4465else
4466 echo "Strings are not matching";
4467?>
4468 </body>
4469</html>
4470
4471
4472Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4473
4474
447521. Consider the following entities and their relationships
4476Doctor (doc_no, doc_name, address, city, area)
4477Hospital (hosp_no, hosp_name, hosp_city)
4478Doctor and Hospital are related with many-many relationship
4479Create a RDB in 3 NF for the above and solve following
4480Using above database, write a PHP script which accepts hospital name and print information about doctors visiting / working in that hospital in tabular format.
4481Html file :
4482<html>
4483<body>
4484<form action="slip_21.php" method="get">
4485Enter the Name Of Hospital : <input type=text name=hosp><br>
4486<input type=submit value=SUBMIT>
4487</form>
4488</body>
4489<html>
4490
4491Phpfile :
4492<?php
4493 $hosp=$_GET['hosp'];
4494 $con=mysql_connect("localhost","root","");
4495 $d=mysql_select_db("bca_programs",$con);
4496 $q=mysql_query("select doctor.doc_no,doc_name,address,city,area from doctor,hospital,doc_hosp where hosp_name='$hosp' and doc_hosp.doc_no=doctor.doc_no and doc_hosp.hosp_no=hospital.hosp_no");
4497echo "<tr><td>Doctor no--</td><td>Doctor Name--</td><td>Address--</td><td>city--</td><td>Area</td></tr>";
4498while($row=mysql_fetch_array($q))
4499 {
4500echo "<br><tr><td>".$row[0]." | </td><td>".$row[1]." | </td><td>".$row[2]." | </td><td>".$row[3]." |</td><td>".$row[4]." |</td></tr>";
4501 }
4502mysql_close();
4503?>
4504
4505
4506
4507---------------------------------------------------------------------------------
4508
4509
4510SLIP_22
4511
4512
4513
4514CLIENT
4515
4516//client.java
4517import java.net.*;
4518import java.io.*;
4519public class client
4520{
4521 public static void main(String args[])
4522 {
4523 try
4524 {
4525 Socket s = new Socket("localhost",2222);
4526 InputStream is=s.getInputStream();
4527 InputStreamReader isr= new InputStreamReader(is);
4528 BufferedReader br=new BufferedReader(isr);
4529 OutputStream os=s.getOutputStream();
4530 PrintWriter pw= new PrintWriter(os,true);
4531 String msg="5";
4532 pw.println(msg);
4533 msg=br.readLine();
4534 int gh=Integer.parseInt(msg) ;
4535 System.out.println("factorial="+gh);
4536 s.close();
4537 }
4538 catch (Exception e)
4539 {
4540 e.printStackTrace();
4541 }
4542 }
4543}
4544
4545
4546
4547
4548
4549SERVER XXXXXXXXX
4550
4551
4552
4553//server.java
4554import java.net.*;
4555import java.io.*;
4556public class server
4557{
4558 public static void main(String args[])
4559 {
4560 try
4561 {
4562 ServerSocket ss =new ServerSocket(2222);
4563 System.out.println("Server is started");
4564 while(true)
4565 {
4566 Socket s=ss.accept();
4567 System.out.print("Connection request Received");
4568 InputStream is=s.getInputStream();
4569 InputStreamReader isr= new InputStreamReader(is);
4570 BufferedReader br=new BufferedReader(isr);
4571 OutputStream os=s.getOutputStream();
4572 PrintWriter pw= new PrintWriter(os,true);
4573 String no= br.readLine();
4574 //System.out.print("no:"+ " " + (char)no);
4575 int no1=Integer.parseInt(no);
4576 int fact=1,i=0;
4577 while(no1>i)
4578 {
4579 fact=fact*no1;
4580 no1--;
4581 //System.out.println("fact="+fact+"no="+no1);
4582 }
4583 pw.println(fact);
4584 s.close();
4585 }
4586 }
4587 catch(Exception e)
4588 {
4589 e.printStackTrace();
4590 }
4591 }
4592}
4593
4594
4595
4596Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4597
4598
4599import java.sql.*;
4600import java.io.*;
4601import javax.sql.*;
4602
4603class slip6
4604{
4605 public static void main(String args[])
4606 {
4607 Connection con;
4608 Statement state;
4609 ResultSet rs;
4610 int ch;
4611
4612 boolean flag=true;
4613 String decision;
4614 int no;
4615
4616
4617 try
4618 {
4619 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
4620 con = DriverManager.getConnection("jdbc:odbc:lab.dsn");
4621
4622 System.out.println("Statement object created");
4623
4624 do
4625 {
4626 System.out.println("\n");
4627 System.out.println("Menu:");
4628 System.out.println("1.create Table");
4629 System.out.println("2.Insert Record into the Table");
4630 System.out.println("3.Display all the Records from the Table");
4631 System.out.println("4.Exit");
4632 System.out.println("Enter your choice: ");
4633
4634 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
4635 ch=Integer.parseInt(br.readLine());
4636
4637 switch(ch)
4638 {
4639 case 1:
4640 state=con.createStatement();
4641 String query="create table student"+"(rno int ,"+" sname varchar(20),"+" per int,"+" address varchar(20))";
4642 state.executeUpdate(query);
4643 System.out.println("Table created");
4644
4645
4646 case 2:
4647 System.out.println("Enter student Number: ");
4648 int rno=Integer.parseInt(br.readLine());
4649
4650 System.out.println("Enter student Name: ");
4651 String sname=br.readLine();
4652
4653 System.out.println("Enter per: ");
4654 int per=Integer.parseInt(br.readLine());
4655
4656 System.out.println("Enter address: ");
4657 String address=br.readLine();
4658
4659 String sql="insert into student values(?,?,?,?)";
4660 PreparedStatement p=con.prepareStatement(sql);
4661 p.setInt(1,rno);
4662 p.setString(2,sname);
4663 p.setInt(3,per);
4664 p.setString(4,address);
4665
4666 p.executeUpdate();
4667 System.out.println("Record Added");
4668
4669 break;
4670
4671
4672 case 3:
4673 state=con.createStatement();
4674 sql="select * from student";
4675 rs=state.executeQuery(sql);
4676 while(rs.next())
4677 {
4678 System.out.println("\n");
4679 System.out.print("\t" +rs.getInt(1));
4680 System.out.print("\t" +rs.getString(2));
4681 System.out.print("\t" +rs.getInt(3));
4682 System.out.print("\t" +rs.getString(4));
4683 }
4684 break;
4685
4686 case 4:
4687 System.exit(0);
4688
4689 default:
4690 System.out.println("Invalid Choice");
4691 break;
4692 }
4693 }while(ch!=4);
4694 }catch(Exception e)
4695 {
4696 System.out.println(e);
4697 }
4698 }
4699}
4700
4701
4702
4703Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXX
4704
4705
470622.Write a script to keep track of number of times the web page has been accessed.(Use $_SESSION[])
4707
4708Html file :
4709
4710<html>
4711<head>
4712<title> Number of times the web page has been viited.</title>
4713</head>
4714
4715<body>
4716<?php
4717session_start();
4718
4719if(isset($_SESSION['count']))
4720 $_SESSION['count']=$_SESSION['count']+1;
4721else
4722 $_SESSION['count']=1;
4723
4724echo "<h3>This page is accessed</h3>".$_SESSION['count'];
4725?>
4726
4727
4728
4729
4730Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4731
4732
473322. Consider the following entities and their relationships
4734Movie (movie_no, movie_name, release_year)
4735Actor (actor_no, name)
4736Relationship between movie and actor is many – many with attribute rate in Rs. Create a RDB in 3 NF for the above and solve following Using above database, write PHP scripts for the
4737following: (Hint: Create HTML form having two radio buttons)
4738a) Accept actor name and display the names of the movies in which he has acted.
4739b) Insert new movie information
4740html file :
4741<html>
4742<body>
4743<form action="slip_22.php" method="get">
4744<h3>Enter Actor Name : <input type=text name=nm></h3>
4745<input type=radio name=a value=1>Display Movie Name<br><br>
4746<h3>Enter movie no :<input type=text name=m_no></h3>
4747<h3>Enter movie name :<input type=text name=m_nm></h3>
4748<h3>Enter release year :<input type=text name=r_yr></h3>
4749<h3>Enter actor no :<input type=text name=a_no></h3>
4750<h3>Enter actor name :<input type=text name=a_nm></h3>
4751<input type=radio name=a value=2>Insert New movie info<br><br>
4752<input type=submit value=OK>
4753</form>
4754<div id="place"></div>
4755</body>
4756</html>
4757
4758php file :
4759<?php
4760 $r = $_GET['a'];
4761 $con =mysql_connect("localhost","root","");
4762 $d =mysql_select_db("bca_programs",$con);
4763if($r == 1)
4764 {
4765 $actor_name = $_GET['nm'];
4766 $q =mysql_query("select m_name from movie,actor,movie_actor where movie.m_no=movie_actor.m_noand actor.a_no=movie_actor.a_no and a_name='$actor_name'");
4767echo "<br>Movie Name </br>";
4768while($row=mysql_fetch_array($q))
4769 {
4770echo $row[0]."<br>";
4771 }
4772 }
4773else if($r == 2)
4774 {
4775 $m_no = $_GET['m_no'];
4776 $m_name = $_GET['m_nm'];
4777 $r_yr = $_GET['r_yr'];
4778 $a_no = $_GET['a_no'];
4779 $a_name = $_GET['a_nm'];
4780 $q =mysql_query("insert into movie values($m_no,'$m_name',$r_yr)");
4781 $q1 =mysql_query("insert into actor values($a_no,'$a_name')");
4782echo "Value Inserted";
4783 }
4784mysql_close();
4785?>
4786
4787
4788
4789
4790
4791
4792
4793------------------------------------------------------------------------------------------------------------
4794
4795SLIP_23
4796
4797
4798
4799Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4800
4801
4802<%@page contentType="text/html" pageEncoding="UTF-8"%>
4803<!DOCTYPE html>
4804<%
4805
4806 int rno = Integer.parseInt(request.getParameter("rno"));
4807
4808 String s_name = request.getParameter("name");
4809
4810 String s_gender = request.getParameter("gender");
4811
4812 String s_know = request.getParameter("know");
4813
4814 String s_class = request.getParameter("Class");
4815
4816 out.println("\nRoll No :"+rno);
4817 out.println("\nName :"+s_name);
4818 out.println("\nGender :"+s_gender);
4819 out.println("\nComp_Know :"+s_know);
4820 out.println("\nClass :"+s_class);
4821 %>
4822
4823
4824
4825
4826
4827HTMLZXXXXXXXXXXXXXXXXXXXXXXXXX
4828
4829SLIP23 : Write a JSP script to accept the details of Student (RNo, SName, Gender, Comp_Know ,Class) and display it on the browser. Use appropriate controls for accepting data.
4830
4831HTML FILE:
4832<!DOCTYPE html>
4833<html>
4834<head>
4835<title></title>
4836<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4837</head>
4838<body>
4839<h1>Enter Information</h1>
4840<form action="Slip23.jsp" method="post">
4841Roll No : <input type="text" name="rno"><br><br>
4842
4843Name : <input type="text" name="name"><br><br>
4844
4845Gender : <input type="radio" name="gender" value="Male" checked>Male
4846<input type="radio" name="gender" value="Female">Female
4847<br><br>
4848
4849Comp_Know : <input type="radio" name="know" value="Yes" checked>Yes
4850<input type="radio" name="know" value="No">No
4851<br><br>
4852
4853Class :
4854<select name="Class">
4855<option value="11">11Th</option>
4856<option value="12">12Th</option>
4857<option value="FY">FY</option>
4858<option value="SY">SY</option>
4859<option value="TY">TY</option>
4860</select>
4861<br><br>
4862
4863<input type="submit" value="Submit">
4864</form>
4865</body>
4866</html>
4867
4868
4869Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4870
4871
4872import java.sql.*;
4873import java.io.*;
4874import javax.sql.*;
4875
4876class Elements{
4877 public static void main(String args[]){
4878 try{
4879 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
4880 con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
4881
4882 Statement s=null;
4883 PreparedStatement ps=null;
4884 ResultSet rs=null;
4885
4886 char ch = args[0].charAt(0);
4887
4888 String name="",symbol="";
4889 int weight=0;
4890
4891 switch(ch)
4892 {
4893 case 'R':
4894 s = con.createStatement();
4895 rs = s.executeQuery("select * from elements");
4896 while(rs.next()){
4897 System.out.println(rs.getInt(1)+"\t"+
4898 rs.getString(2)+"\t"+
4899 rs.getString(3));
4900 }
4901 break;
4902 case 'D':
4903 name = args[1];
4904 ps = con.prepareStatement("delete from elements where name=?");
4905 ps.setString(1,name);
4906 if(ps.executeUpdate()==1)
4907 System.out.println("Element "+name+" deleted successfully.");
4908 else
4909 System.out.println("Element "+name+" not found.");
4910 break;
4911 case 'U':
4912 weight = Integer.parseInt(args[1]);
4913 name = args[2];
4914 symbol = args[3];
4915
4916 ps = con.prepareStatement("update elements set atomic_weight=?,chemical_symbol=? where name=?");
4917
4918 ps.setInt(1,weight);
4919 ps.setString(2,symbol);
4920 ps.setString(3,name);
4921
4922 if(ps.executeUpdate()==1)
4923 System.out.println("Element "+name+" updated successfully.");
4924 else
4925 System.out.println("Element "+name+" not found.");
4926 }
4927
4928 con.close();
4929 }
4930 catch(Exception e){
4931 System.out.println(e);
4932 }
4933 }
4934}
4935
4936
4937
4938
4939Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4940
4941
494223. Write a PHP script to generate an XML in the following format
4943HTML file
4944<html>
4945<head>
4946<title>Create XML</title>
4947</head>
4948<form action=slip23.php method=get>
4949Enter Book Title<input type=text name=txtTitle></br>
4950Enter Publication<input type=text name=publ></br>
4951<input type=submit value="submit">
4952</form>
4953</html>
4954
4955PHP File
4956<?php
4957
4958echo "Links data posted";
4959$ele=$_GET['txtTitle'];
4960$att=$_GET['publ'];
4961$xmltags="<?xml version=1.0?>";
4962$xmltags=$xmltags."<Bookstore>";
4963$xmltags=$xmltags."<Books>";
4964$xmltags=$xmltags."<PHP>";
4965$xmltags=$xmltags."<title>";
4966$xmltags=$xmltags.$ele;
4967$xmltags=$xmltags."</title>";
4968$xmltags=$xmltags."<publication>";
4969$xmltags=$xmltags.$att;
4970$xmltags=$xmltags."</attrib>";
4971$xmltags=$xmltags."</PHP>";
4972$xmltags=$xmltags."</Books>";
4973$xmltags=$xmltags."</Bookstore>";
4974
4975if($fp=fopen("books.xml","w"))
4976{
4977if($wt=fwrite($fp,$xmltags))
4978 {
4979echo "File created";
4980 }
4981else
4982echo "Not write";
4983}
4984else
4985echo "Not opened";
4986
4987?>
4988
4989
4990Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4991
4992
499323. Consider the following entities and their relationships
4994BillMaster(billno, custname, billdate )
4995BillDetails(itemname, qty, rate, discount)
4996BillMaster and BillDetails are related with one-to-many relationship.
4997Create a RDB in 3 NF for the above and solve following
4998Write PHP script to print the bill in following format Accept the Bill number from user.
4999Html file :
5000<html>
5001<body>
5002<form action="slip_23.php" method="get">
5003<center><h3>Enter the Bill Number : <input type=text name=bno><br></h3>
5004<input type=submit value=SUBMIT></center>
5005</form>
5006</body>
5007<html>
5008
5009Phpfile :
5010<?php
5011 $bno = $_GET['bno'];
5012 $con =mysql_connect("localhost","root","");
5013 $d =mysql_select_db("bca_programs",$con);
5014 $q =mysql_query("select * from bill_master where bill_no=$bno");
5015echo "<center>";
5016while($row = mysql_fetch_array($q))
5017 {
5018echo "<h3><br>Bill No : ".$row[0]." Bill Date : ".$row[2]."</h3>";
5019echo "<h3>Customer Name : ".$row[1]."</h3>";
5020 }
5021 $i=1;
5022 $gt=0;
5023 $q1=mysql_query("select item_name,qty,rate,discount from bill_details,bill_master where bill_details.bill_no=$bno and bill_details.bill_no=bill_master.bill_no");
5024echo "<table border=1 width=30% height=10%>";
5025echo "<tr><td><b>SrNo. </b></td><td><b> Particular </b></td><td><b> Quantity </b></td><td><b> Rate </b></td><td><b> Total </b></td></tr>";
5026while($row1=mysql_fetch_array($q1))
5027 {
5028 $t=$row1[1]*$row1[2]; Echo"<br><tr><td>".$i++."</td><td>".$row1[0]."</td><td>".$row1[1]."</td><td>".$row1[2]."</td><td>".$t."</td><tr>";
5029 $gt+=$t;
5030 }
5031echo "</table>";
5032echo "<br><b> Gross Ammount is :: ".$gt."</b>";
5033echo "<center>";
5034mysql_close();
5035?>
5036
5037
5038
5039------------------------------------------------------------------------------
5040
5041
5042SLIP_24
5043
5044
5045
5046
5047
5048Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5049
5050
5051<html>
5052<body>
5053<%@ page language="java" %>
5054<%
5055 String email=request.getParameter("t1");
5056 if(email.contains("@") && email.contains("."))
5057 {
5058 out.println("Given Email Id is Valid");
5059 }
5060 else
5061 {
5062 out.println("Given Email id is not Valid");
5063 }
5064 %>
5065</body>
5066</html>
5067
5068
5069XXXXXXXXXXXXXXXXXX HTML
5070
5071<html>
5072<body>
5073<form name=f1 action="EmailCheck.jsp">
5074<fieldset>
5075<legend>Enter Email Id...!!!</legend>
5076 Enter Email Id:<input type="text" name="t1" >
5077</fieldset>
5078<div align=center>
5079<input type="submit" name="Submit" value="Submit">
5080</div>
5081</form>
5082</body>
5083</html>
5084
5085
5086Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5087
5088
5089
5090import java.sql.*;
5091import java.awt.*;
5092import java.awt.event.*;
5093import javax.swing.*;
5094
5095class College extends JFrame
5096{
5097 private JLabel lblID,lblName,lblAddr,lblYear;
5098 private JTextField txtID,txtName,txtAddr,txtYear;
5099 private JButton btnSave,btnClose;
5100 private JPanel panCenter,panSouth;
5101
5102 private Connection con;
5103 private PreparedStatement ps;
5104
5105 public College()
5106 {
5107 lblID = new JLabel("College ID:");
5108 lblName = new JLabel("College Name:");
5109 lblAddr = new JLabel("Address:");
5110 lblYear = new JLabel("Year:");
5111
5112 txtID = new JTextField();
5113 txtName = new JTextField();
5114 txtAddr = new JTextField();
5115 txtYear = new JTextField();
5116
5117 panCenter = new JPanel();
5118 panCenter.setLayout(new GridLayout(4,2));
5119 panCenter.add(lblID);
5120 panCenter.add(txtID);
5121 panCenter.add(lblName);
5122 panCenter.add(txtName);
5123 panCenter.add(lblAddr);
5124 panCenter.add(txtAddr);
5125 panCenter.add(lblYear);
5126 panCenter.add(txtYear);
5127
5128 btnSave = new JButton("Save");
5129 btnClose = new JButton("Close");
5130
5131 panSouth = new JPanel();
5132 panSouth.add(btnSave);
5133 panSouth.add(btnClose);
5134
5135 setTitle("College Information");
5136 setSize(400,200);
5137 setLocation(100,100);
5138 add(panCenter,"Center");
5139 add(panSouth,"South");
5140 setVisible(true);
5141 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5142
5143 try{
5144 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
5145 con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
5146 }
5147 catch(Exception e)
5148 {
5149 JOptionPane.showMessageDialog(null,e);
5150 dispose();
5151 }
5152
5153 btnSave.addActionListener(new ActionListener(){
5154 public void actionPerformed(ActionEvent ae){
5155 try{
5156 int cid = Integer.parseInt(txtID.getText());
5157 String cname = txtName.getText();
5158 String addr = txtAddr.getText();
5159 int yr = Integer.parseInt(txtYear.getText());
5160
5161 ps = con.prepareStatement("insert into college values(?,?,?,?)");
5162
5163 ps.setInt(1,cid);
5164 ps.setString(2,cname);
5165 ps.setString(3,addr);
5166 ps.setInt(4,yr);
5167
5168 ps.executeUpdate();
5169
5170 txtID.setText("");
5171 txtName.setText("");
5172 txtAddr.setText("");
5173 txtYear.setText("");
5174
5175 txtID.requestFocus();
5176 }
5177 catch(Exception e){
5178 JOptionPane.showMessageDialog(null,e);
5179 }
5180 }
5181 });
5182
5183 btnClose.addActionListener(new ActionListener(){
5184 public void actionPerformed(ActionEvent ae){
5185 dispose();
5186 }
5187 });
5188 }
5189
5190 public static void main(String args[]){
5191 new College();
5192 }
5193}
5194
5195
5196
5197Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5198
5199
520024. Write a simple PHP program which implements Ajax for addition of two numbers
5201
5202
5203
5204Html file :
5205
5206<html>
5207<head>
5208<script type="text/javascript">
5209
5210
5211
5212function Addition()
5213 {
5214var ob=false;
5215ob=new XMLHttpRequest();
5216
5217var no1=document.getElementById("no1").value;
5218var no2=document.getElementById("no2").value;
5219
5220ob.open("GET","Que25.php?num1="+no1+"&num2="+no2);
5221ob.send();
5222
5223ob.onreadystatechange=function()
5224 {
5225if(ob.readyState==4 &&ob.status==200)
5226document.getElementById("add").innerHTML=ob.responseText; }
5227 }
5228
5229</script>
5230</head>
5231
5232<body>
5233
5234Enter first no :<input type=text name=no1 id="no1"><br>
5235Enter second no :<input type=text name=no2 id="no2"><br>
5236<input type=button name=submit value=add onClick="Addition()"><br>
5237<span id="add"></span>
5238
5239<body>
5240</html>
5241
5242PhpFile :
5243
5244<?php
5245 $n1=$_GET['num1'];
5246 $n2=$_GET['num2'];
5247
5248if((!empty($n1)) && (!empty($n2)))
5249 {
5250 $add=$n1+$n2;
5251echo "Addition = ".$add;
5252 }
5253else "enter both nos";
5254?>
5255
5256
5257
5258Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5259
5260
526124. Create an application that reads “Book.xml†file into simple XML object. Display attributes
5262and elements(Hint: use simple_xml_load_file() function)
5263XML file :
5264<?xml version='1.0' encoding ='UTF-8' ?>
5265<bookstore>
5266<books category="technical">
5267<book_no>1</book_no>
5268<book_name>def</book_name>
5269<author_name>xxx</author_name>
5270<price>100</price>
5271<year>1990</year>
5272</books>
5273<books category="Cooking">
5274<book_no>2</book_no>
5275<book_name>ccc</book_name>
5276<author_name>aaa</author_name>
5277<price>200</price>
5278<year>1950</year>
5279</books>
5280<books category="YOGA">
5281<book_no>3</book_no>
5282<book_name>ddd</book_name>
5283<author_name>zzz</author_name>
5284<price>150</price>
5285<year>2016</year>
5286</books>
5287</bookstore>
5288
5289Phpfile :
5290<?php
5291$xml=simplexml_load_file("slip_24.xml") or die("eror:cannot create object");
5292var_dump($xml);
5293?>
5294
5295
5296
5297----------------------------------------------------------------------------------------------------
5298
5299SLIP_25
5300
5301
5302Q1XXXXXXXXXXXXXXXXXXX
5303
5304<html>
5305<body>
5306<%!
5307 int cnt=0;
5308 String uname,nname;
5309%>
5310<%
5311 uname=request.getParameter("uname");
5312 nname=request.getParameter("nname");
5313 cnt++;
5314 if(cnt%2==0)
5315 out.println("Hello "+nname+"......... Visit Count "+cnt);
5316 else
5317 out.println("Hello "+uname+"......... Visit Count "+cnt);
5318%>
5319<br><br>
5320<a href="visitpage.html">VISIT</a>
5321</body>
5322</html>
5323
5324
5325Q1XXXXXXXXXXXXXXXXXXX HTML
5326
5327
5328<html>
5329<body>
5330<form method=get action="visitpage.jsp">
5331Enter User Name : <input type=text name=uname><br><br>
5332Enter Nick Name : <input type=text name=nname><br><br>
5333<input type=submit value="visit">
5334</form>
5335<body>
5336</html>
5337
5338
5339Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5340
5341
5342import java.io.*;
5343import java.sql.*;
5344
5345 public class slip6
5346 {
5347 public static void main(String args[])
5348 {
5349 try
5350 {
5351 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
5352 Connection con=null;
5353 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
5354 con = DriverManager.getConnection("jdbc:odbc:lab");
5355
5356 Statement sta=con.createStatement();
5357
5358
5359 sta=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
5360 ResultSet rs=sta.executeQuery("select * from employee");
5361
5362 for(;;)
5363 {
5364 System.out.println("---------MAIN MENU---------");
5365 System.out.println("1:Next");
5366 System.out.println("2:First");
5367 System.out.println("3:Previous");
5368 System.out.println("4:Last");
5369 System.out.println("5:Exit");
5370 System.out.println("ENTER your choice :");
5371 int choice=Integer.parseInt(br.readLine());
5372
5373 switch(choice)
5374 {
5375 case 1:
5376 System.out.println("Display next record");
5377 rs.next();
5378 System.out.println(" eNo:"+rs.getInt(1));
5379 System.out.println("eName:"+rs.getString(2));
5380 System.out.println("sal:"+rs.getFloat(3));
5381 break;
5382 case 2:
5383 System.out.println("Display first record");
5384 rs.first();
5385 System.out.println("eNo:"+rs.getInt(1));
5386 System.out.println("eName:"+rs.getString(2));
5387 System.out.println("sal:"+rs.getFloat(3));
5388 break;
5389 case 3:
5390 System.out.println("Display previous record");
5391 rs.previous();
5392 System.out.println("eNo:"+rs.getInt(1));
5393 System.out.println("eName:"+rs.getString(2));
5394 System.out.println("sal:"+rs.getFloat(3));
5395 break;
5396 case 4:
5397 System.out.println("Display last record");
5398 rs.last();
5399 System.out.println("eNo:"+rs.getInt(1));
5400 System.out.println("eName:"+rs.getString(2));
5401 System.out.println("sal:"+rs.getFloat(3));
5402 break;
5403 case 5:
5404 System.exit(0);
5405 break;
5406 }
5407 }
5408 }
5409 catch(Exception e)
5410 {
5411 System.out.println(e);
5412 }
5413 }
5414 }
5415
5416
5417
5418Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5419
5420
542125. Write PHP script to demonstrate the concept of introspection for examining object.
5422
5423<?php
5424class intro
5425{
5426var $i;
5427function f1() {}
5428function f2() {}
5429}
5430class intro_1 extends intro
5431{
5432var $j,$k;
5433function f3() {}
5434function f4() {}
5435}
5436$ob=new intro_1();
5437if(is_object($ob)) //returns boolean value true if an object ob is created
5438{
5439echoget_class($ob); //returns class name of given object
5440}
5441if(method_exists($ob,'f4')) //returns tru if the method f4 exists for the object ob
5442{
5443echo "method f4 exists";
5444}
5445var_dump(get_object_vars($ob)); //retuns an array of parameter / variables for given object
5446?>
5447
5448
5449
5450Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5451
5452
545325. Create a XML file which gives details of books available in “ABC Bookstore†from
5454following categories.
54551) Technical 2) Cooking 3) Yoga
5456and elements in each category are in the following format
5457--------------
5458--------------
5459---------------
5460Save the file as “Book.xmlâ€. Create an application that reads “Book.xml†file into simple XML object. Display attributes and elements. (Hint: Use simple_xml_load_file() function)
5461XML file :
5462
5463<?xml version='1.0' encoding ='UTF-8' ?>
5464<bookstore>
5465<books category="technical">
5466<book_no>1</book_no>
5467<book_name>def</book_name>
5468<author_name>xxx</author_name>
5469<price>100</price>
5470<year>1990</year>
5471</books>
5472<books category="Cooking">
5473<book_no>2</book_no>
5474<book_name>ccc</book_name>
5475<author_name>aaa</author_name>
5476<price>200</price>
5477<year>1950</year>
5478</books>
5479<books category="YOGA">
5480<book_no>3</book_no>
5481<book_name>ddd</book_name>
5482<author_name>zzz</author_name>
5483<price>150</price>
5484<year>2016</year>
5485</books>
5486</bookstore>
5487
5488Phpfile :
5489<?php
5490$xml=simplexml_load_file("slip_24.xml") or die("eror:cannot create object");
5491var_dump($xml);
5492?>
5493
5494
5495
5496--------------------------------------------------------------------------------------
5497
5498SLIP_26
5499
5500
5501
5502Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5503
5504import java.io.*;
5505import java.util.*;
5506class slip26 implements Runnable
5507{
5508 Thread t;
5509 public slip26()
5510 {
5511 t=new Thread(this);
5512 t.start();
5513
5514 }
5515 public void run()
5516 {
5517 char ch;
5518 for (ch='a';ch<='z';ch++)
5519 {
5520 System.out.println(ch);
5521 try
5522 {
5523 Thread.sleep(300);
5524 }
5525 catch(Exception e)
5526 {
5527 }
5528 }
5529 }
5530public static void main(String args[])
5531 {
5532
5533slip26 s=new slip26();
5534
5535 }
5536}
5537
5538
5539
5540Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5541
5542
5543
5544import java.awt.*;
5545import java.awt.event.*;
5546import javax.swing.*;
5547import javax.swing.table.*;
5548import java.sql.*;
5549import java.util.*;
5550import java.text.*;
5551
5552class SalesReport extends JFrame{
5553 private JLabel lblStart,lblEnd;
5554 private JComboBox cmbStart,cmbEnd;
5555 private JPanel panNorth;
5556 private JButton btnShow;
5557 private JTable tabReport;
5558 private DefaultTableModel dtm;
5559
5560 public SalesReport(){
5561 lblStart = new JLabel("Start Date:");
5562 lblEnd = new JLabel("End Date:");
5563
5564 cmbStart = new JComboBox();
5565 cmbEnd = new JComboBox();
5566
5567 Calendar calendar = new GregorianCalendar();
5568 java.util.Date d = new java.util.Date();
5569 System.out.println(d.getDate());
5570 calendar.set(Calendar.YEAR, d.getYear()+1900);
5571 calendar.set(Calendar.MONTH, d.getMonth());
5572 calendar.set(Calendar.DAY_OF_MONTH, d.getDate());
5573
5574 for(int i=1000;i>=1;i--){
5575 String str = calendar.get(Calendar.YEAR)+"-"+
5576 (calendar.get(Calendar.MONTH)+1)+"-"+
5577 calendar.get(Calendar.DAY_OF_MONTH);
5578 cmbStart.addItem(str);
5579 cmbEnd.addItem(str);
5580 calendar.add(Calendar.DAY_OF_MONTH, -1);
5581 }
5582
5583 btnShow = new JButton("Show");
5584
5585 panNorth = new JPanel(new GridLayout(1,4));
5586 panNorth.add(lblStart);
5587 panNorth.add(cmbStart);
5588 panNorth.add(lblEnd);
5589 panNorth.add(cmbEnd);
5590 panNorth.add(btnShow);
5591
5592 dtm = new DefaultTableModel();
5593 dtm.addColumn("PID");
5594 dtm.addColumn("PName");
5595 dtm.addColumn("Amount");
5596 dtm.addColumn("Date");
5597
5598 tabReport = new JTable(dtm);
5599
5600 setTitle("Sales Report");
5601 setSize(400,400);
5602 add(panNorth,"North");
5603 add(new JScrollPane(tabReport),"Center");
5604 setVisible(true);
5605 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5606
5607 btnShow.addActionListener(new ActionListener(){
5608 public void actionPerformed(ActionEvent ae){
5609 try{
5610 for(int i=0;i<dtm.getRowCount();i++)
5611 dtm.removeRow(0);
5612
5613 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
5614 con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
5615
5616 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
5617 String sdate = cmbStart.getSelectedItem().toString();
5618 String edate = cmbEnd.getSelectedItem().toString();
5619
5620 java.util.Date d = sdf.parse(sdate);
5621 java.sql.Date newsdate = new java.sql.Date(d.getTime());
5622
5623 d = sdf.parse(edate);
5624 java.sql.Date newedate = new java.sql.Date(d.getTime());
5625
5626 PreparedStatement ps = con.prepareStatement("select * from prod_sales where sale_date between ? and ?");
5627 ps.setDate(1,newsdate);
5628 ps.setDate(2,newedate);
5629
5630 ResultSet rs = ps.executeQuery();
5631 while(rs.next()){
5632 Vector v = new Vector();
5633 v.add(rs.getString(1));
5634 v.add(rs.getString(2));
5635 v.add(rs.getString(3));
5636 v.add(rs.getString(4));
5637 dtm.addRow(v);
5638 }
5639 }
5640 catch(Exception e){
5641 JOptionPane.showMessageDialog(null,e);
5642 }
5643 }
5644 });
5645 }
5646
5647 public static void main(String args[]){
5648 new SalesReport();
5649 }
5650}
5651
5652
5653
5654
5655Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5656
5657
565826. Write a PHP script to accept student details(rno, name, class) and store them in student table (Max 10) , print them in sorted order of name on the browser in table format
5659
5660
5661
5662html file :
5663
5664<html>
5665
5666<body>
5667
5668<form action=Que26.php method=GET>
5669
5670enter student roll no :<input type=text name=rno><br>
5671
5672enter student name : <input type=text name=s_name><br>
5673
5674enter class : <input type=text name=cls><br>
5675
5676<input type=submit name=submit value=submit >
5677
5678</form>
5679
5680</body>
5681
5682</html>
5683
5684Phpfile :
5685
5686<?php
5687
5688<?php
5689
5690$rno=$_GET['rno'];
5691
5692$s_name=$_GET['s_name'];
5693
5694$cls=$_GET['cls'];
5695
5696
5697
5698$con=mysql_connect("localhost","root","");
5699
5700$d=mysql_select_db("bca_programs",$con);
5701
5702$q=mysql_query("insert into stud values($rno,'$s_name','$cls')");
5703
5704
5705
5706$q1=mysql_query("select * from stud order by sname");
5707
5708echo "<table>";
5709
5710echo "<tr><td>Roll no.</td><td>Name</td><td>Class</td></tr>";
5711
5712
5713
5714while($row=mysql_fetch_array($q1))
5715
5716{
5717echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
5718
5719}
5720
5721echo "</table>";
5722
5723mysql_close();
5724
5725?>
5726
5727
5728
5729
5730Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5731
5732
573326. Write a script to solve following questions (Use “Book.xml†file)
5734a) Create a DOM Document object and load this XML file.
5735b) Get the output of this Document to the browser
5736c) Save this [. XML] document in another format i.e. in [.doc]
5737d) Write a XML program to print the names of the books available in “Book.xml†file.
5738XML file :
5739Same as Q.24
5740Phpfile :
5741<?php
5742$doc=new DOMDocument();
5743$doc->load("slip_18.xml");
5744$name=$doc->getElementsByTagName("book_name");
5745echo "Books Names";
5746foreach($name as $val)
5747{
5748echo "<br>".$val->textContent;
5749}
5750?>
5751
5752
5753
5754
5755------------------------------------------------------------------------------------------------
5756
5757SLIP_27
5758
5759
5760Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5761
5762import java.io.*;
5763import java.sql.*;
5764class Empdisplay
5765{
5766 static Connection cn;
5767 static Statement st;
5768 static ResultSet rs;
5769 static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
5770 public static void main(String args[])
5771 {
5772 int e,k,ch,sal;
5773 String en;
5774 try
5775 {
5776 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
5777 cn=DriverManager.getConnection("jdbc:odbc:Emp","","");
5778 st=cn.createStatement();
5779 System.out.println("1. Display ");
5780 System.out.println("Enter Your Choice");
5781 ch=Integer.parseInt(br.readLine());
5782 rs=st.executeQuery ("select * from emp where Ename like 'S%'");
5783 while(rs.next())
5784 {
5785 System.out.println(rs.getInt("eno") + "\t" +rs.getString("ename")+"\t"+rs.getInt("sal"));
5786 }
5787 }
5788 catch(Exception et)
5789 {
5790 System.out.println(et);
5791 }
5792 }
5793
5794}
5795
5796
5797
5798
5799Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5800
5801Slip27_2.java
5802import java.awt.*;
5803import java.awt.event.*;
5804import javax.swing.*;
5805import java.util.*;
5806class MyThread extends Thread
5807{
5808JTextField tf;
5809MyThread(JTextField tf)
5810{
5811this.tf = tf;
5812}
5813public void run()
5814{
5815while(true)
5816{
5817Date d = new Date();
5818int h = d.getHours();
5819int m = d.getMinutes();
5820int s = d.getSeconds();
5821tf.setText(h+":"+m+":"+s);
5822try
5823{
5824Thread.sleep(300);
5825}
5826NR CLASSES, PUNE (8796064387/90)
5827catch(Exception e){}
5828}
5829}
5830}
5831class Slip27_2 extends JFrame implements ActionListener
5832{
5833JTextField txtTime;
5834JButton btnStart,btnStop;
5835MyThread t;
5836Slip27_2()
5837{
5838txtTime = new JTextField(20);
5839btnStart = new JButton("Start");
5840btnStop = new JButton("Stop");
5841setTitle("Stop Watch");
5842setLayout(new FlowLayout());
5843setSize(300,100);
5844add(txtTime);
5845add(btnStart);
5846add(btnStop);
5847setVisible(true);
5848setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5849btnStart.addActionListener(this);
5850btnStop.addActionListener(this);
5851t = new MyThread(txtTime);
5852}
5853public void actionPerformed(ActionEvent ae)
5854{
5855if(ae.getSource()==btnStart)
5856{
5857if(!t.isAlive()) t.start();
5858else t.resume();
5859}
5860if(ae.getSource()==btnStop)
5861{
5862t.suspend();
5863}
5864}
5865public static void main(String a[])
5866{
5867new Slip27_2();
5868}
5869}
5870
5871
5872Q2XXXXXXXXXXXXXXX
5873
5874import java.awt.*;
5875import java.awt.event.*;
5876import java.util.*;
5877public class slip27 extends Frame implements ActionListener,Runnable
5878 {
5879 Button start,stop;
5880 TextField tf;
5881 int x=0,y=0;
5882 String msg="";
5883 Thread t1=new Thread(this);
5884 public slip27()
5885 {
5886 setLayout(new FlowLayout());
5887 tf=new TextField();
5888 start=new Button("start");
5889 stop=new Button("stop");
5890 add(tf);
5891 add(start);
5892 add(stop);
5893 start.addActionListener(this);
5894 stop.addActionListener(this);
5895 /** addWindowListener(new WindowAdapter()
5896 {
5897 public void windowClosing(WindowEvent e)
5898 {
5899 System.exit(0);
5900 }
5901 });*/
5902 setSize(200,200);
5903 setVisible(true);
5904 }
5905 public void actionPerformed(ActionEvent ae)
5906 {
5907 Button btn=(Button)ae.getSource();
5908 if(btn==start)
5909 {
5910 t1.start();
5911 }
5912 if(btn==stop)
5913 {
5914 t1.stop();
5915 }
5916 }
5917 public void run()
5918 {
5919 try
5920 {
5921 while(true)
5922 {
5923 repaint();
5924 Thread.sleep(350);
5925 }
5926 }
5927 catch(Exception e){ }
5928 }
5929 public void paint(Graphics g)
5930 {
5931 int sec,min,hr;
5932 GregorianCalendar date = new GregorianCalendar();
5933 sec = date.get(Calendar.SECOND);
5934 min = date.get(Calendar.MINUTE);
5935 hr = date.get(Calendar.HOUR);
5936 msg = hr+":"+min+":"+sec;
5937
5938 tf.setText(msg);
5939 }
5940 public static void main(String args[])
5941 {
5942 new slip27();
5943 }
5944}
5945
5946
5947Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5948
594927. Write an Ajax program to display list of games stored in an array on clicking OK button.
5950
5951Html file :
5952
5953<html>
5954<head>
5955<script>
5956
5957function dis()
5958 {
5959varob=false;
5960ob=new XMLHttpRequest();
5961vargm=document.getElementById("gm").value;
5962ob.open("GET","slip27.php?game="+gm);
5963ob.send();
5964
5965ob.onreadystatechange=function()
5966 { if(ob.readyState==4 &&ob.status==200)
5967 {
5968document.getElementById("game").innerHTML=ob.responseText;
5969 }
5970 }
5971Phpfile :
5972 }
5973</script>
5974</head>
5975
5976<body>
5977
5978<h2>Display the list of Games<input type=button name=submit value=OK id="gm" onClick="dis()"></h2>
5979<span id="game"></span>
5980
5981</body>
5982</html>
5983
5984Phpfile :
5985
5986<?php
5987 $gm=$_GET['game'];
5988
5989 $a=array("Hockey","Football","Cricket","Basket Ball","Kho-Kho","Tennis","Dough Ball");
5990
5991echo "<h3>List of Games<br></h3>";
5992for($i=0;$i<count($a);$i++)
5993 {
5994echo $a[$i]."<br>";
5995 }
5996?>
5997
5998
5999
6000Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6001
600227 .Write a script to create “cricket.xml†file with multiple elements as shown below:
6003<CricketTeam>
6004<Team country=â€Indiaâ€>
6005<player>____</player>
6006<runs>______</runs>
6007<wicket>____</wicket>
6008</Team>
6009</CricketTeam>
6010
6011Write a script to add multiple elements in “cricket.xml†file of category, country=â€Australiaâ€.
6012XML file :
6013<?xml version='1.0' encoding='UTF-8' ?>
6014<CricketTeam>
6015<Team country='India'>
6016<player>Mahi</player>
6017<runs>100</runs>
6018<wicket>4</wicket>
6019</Team>
6020<Team country='Austrelia'>
6021<player>smith</player>
6022<runs>10</runs>
6023<wicket>1</wicket>
6024</Team>
6025</CricketTeam>
6026
6027
6028--------------------------------------------------------------------------------
6029
6030SLIP_28
6031
6032
6033Q1XXXXXXXXXXXXXXXXXXXXXXX
6034
6035<html>
6036<body>
6037<%! int n,m,sum=0,rem; %>
6038<% n=Integer.parseInt(request.getParameter("t1"));
6039m=n;
6040while(n>0)
6041{
6042 rem=n%10;
6043 sum=sum+(rem*rem*rem);
6044 n=n/10;
6045}
6046if(sum==m)
6047out.print("the no. is armstrong "+sum);
6048else
6049out.print("the no. is not armstrong "+sum);
6050%>
6051</body>
6052</html>
6053
6054Q1XXXXXXXXXXXXXXXXXXX HTML
6055
6056
6057
6058<html>
6059<body>
6060<form method=post action="Armstrong.jsp">
6061Enter Number : <input type=text name=t1><br>
6062<input type=submit>
6063</form>
6064</body>
6065</html>
6066
6067Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6068
6069
6070import java.awt.*;
6071import java.awt.event.*;
6072import javax.swing.*;
6073import javax.swing.table.*;
6074import java.util.*;
6075import java.sql.*;
6076class slip28 extends JFrame
6077{
6078 private JTable tabRecord;
6079 private JLabel lblEmp;
6080 private JComboBox cmbEmp;
6081 private JPanel panNorth;
6082 private DefaultTableModel dtm;
6083 private Connection con;
6084 private PreparedStatement ps;
6085 private Statement s;
6086 private ResultSet rs;
6087 public slip28()
6088 {
6089 lblEmp = new JLabel("Employee:");
6090 cmbEmp = new JComboBox();
6091 panNorth = new JPanel();
6092 panNorth.add(lblEmp);
6093 panNorth.add(cmbEmp);
6094 dtm = new DefaultTableModel();
6095 dtm.addColumn("EmpNo");
6096 dtm.addColumn("Name");
6097 dtm.addColumn("Salary");
6098 //dtm.addColumn("Designation");
6099 tabRecord = new JTable(dtm);
6100 setTitle("View Employee");
6101 setSize(500,150);
6102 add(panNorth,"North");
6103 add(new JScrollPane(tabRecord),"Center");
6104 setVisible(true);
6105 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
6106 try
6107 {
6108 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
6109 con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
6110 s = con.createStatement();
6111 rs = s.executeQuery("select * from emp");
6112 cmbEmp.addItem("---");
6113 while(rs.next()){
6114 cmbEmp.addItem(rs.getString(2));
6115 }
6116 }
6117 catch(Exception e)
6118 {
6119 JOptionPane.showMessageDialog(null,e);
6120 }
6121 cmbEmp.addItemListener(new ItemListener()
6122 {
6123 public void itemStateChanged(ItemEvent ie)
6124 {
6125 try
6126 {
6127 String name = cmbEmp.getSelectedItem().toString();
6128 ps = con.prepareStatement("select * from emp where name=?");
6129 ps.setString(1,);
6130 rs = ps.executeQuery();
6131 if(rs.next())
6132 {
6133 Vector rec = new Vector();
6134 rec.add(rs.getString(1));
6135 rec.add(rs.getString(2));
6136 rec.add(rs.getString(3));
6137 // rec.add(rs.getString(4));
6138 if(dtm.getRowCount()>0)
6139 dtm.removeRow(0);
6140 dtm.addRow(rec);
6141 }
6142 }
6143 catch(Exception e)
6144 {
6145 JOptionPane.showMessageDialog(null,e);
6146 }
6147 }
6148 });
6149 }
6150 public static void main(String args[])
6151 {
6152 new slip28();
6153 }
6154}
6155
6156
6157
6158Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6159
6160
6161
616228. Change the preferences of your web page like font style, font size, font color, background color using cookie. Display selected settings on next web page and actual implementation (with new settings) on third web page.
6163
6164
6165
6166
6167Html file :
6168
6169
6170<html>
6171<body>
6172<form action="slip_28_Q3-1.php" method="get">
6173<center>
6174<b>Select font style :</b><input type=text name=s1><br>
6175<b>Enter font size : </b><input type=text name=s><br>
6176<b>Enter font color : </b><input type=text name=c><br>
6177<b>Enter background color :</b><input type=text name=b><br>
6178<input type=submit value="Next">
6179</center>
6180</form>
6181</body>
6182</html>
6183
6184Phpfile :
6185slip_28_1.php
6186<?php
6187echo "style is ".$_GET['s1']."<br>color is ".$_GET['c']."<br>Background color is ".$_GET['b']."<br>size is ".$_GET['s'];
6188
6189setcookie("set1",$_GET['s1'],time()+3600);
6190setcookie("set2",$_GET['c'],time()+3600);
6191setcookie("set3",$_GET['b'],time()+3600);
6192setcookie("set4",$_GET['s'],time()+3600);
6193?>
6194
6195<html>
6196<body>
6197<form action="slip28_2.php">
6198<input type=submit value=OK>
6199</form>
6200</body>
6201</html>
6202php file :
6203slip28_2.php
6204<?php
6205$style=$_COOKIE['set1'];
6206$color=$_COOKIE['set2'];
6207$size=$_COOKIE['set4'];
6208$b_color=$_COOKIE['set3'];
6209$msg="NR Classes";
6210echo "<body bgcolor=$b_color>";
6211echo "<font color=$color size=$size>$msg";
6212echo "</font></body>";
6213
6214?>
6215
6216
6217
6218
6219Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6220
622128. Write a PHP script to accept an .XML file which should comprise the following:
6222<cricket>
6223<player>abc</player>
6224<runs>1000</runs>
6225<wickets>50</wickets>
6226<noofnotout>10</noofnotout>
6227</cricket>
6228For at least 5 players.
6229Display the details of players who have scored more than 1000 runs and at least 50 wickets.
6230XML file :
6231<?xml version='1.0' encoding='UTF-8'?>
6232<cricketinfo>
6233<cricket>
6234<player>abc</player>
6235<runs>1000</runs>
6236<wickets>50</wickets>
6237<noofnotout>10</noofnotout>
6238</cricket>
6239<cricket>
6240<player>def</player>
6241<runs>100</runs>
6242<wickets>40</wickets>
6243<noofnotout>10</noofnotout>
6244</cricket>
6245<cricket>
6246<player>pqr</player>
6247<runs>1020</runs>
6248<wickets>60</wickets>
6249<noofnotout>10</noofnotout>
6250</cricket>
6251<cricket>
6252<player>xyz</player>
6253<runs>9000</runs>
6254<wickets>90</wickets>
6255<noofnotout>40</noofnotout>
6256</cricket>
6257<cricket>
6258<player>lmn</player>
6259<runs>170</runs>
6260<wickets>80</wickets>
6261<noofnotout>8</noofnotout>
6262</cricket>
6263</cricketinfo>
6264Phpfile :
6265<?php
6266$d=new DOMDocument();
6267$d->load("slip_29.xml");
6268$run=$d->getElementsByTagName('runs');
6269$wic=$d->getElementsByTagName('wickets');
6270$name=$d->getElementsByTagName('player');
6271foreach($name as $n)
6272{
6273if($run=='1000' && $wic>='50')
6274echo "<br>".$n->textContent;
6275else "not";
6276}
6277?>
6278
6279
6280---------------------------------------------------------------------------------------------------
6281
6282
6283SLIP_29
6284
6285
6286Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6287
6288<html>
6289<body>
6290<%! int n; %>
6291<% n=Integer.parseInt(request.getParameter("t1"));
6292if(n>=18)
6293out.print("You are eligible for voting....!");
6294else
6295out.print("You are not eligible for voting....!");
6296%>
6297</body>
6298</html>
6299
6300Q1XXXXXXXXXXXXXXXXX HTML
6301
6302
6303<html>
6304<body>
6305<form method=post action="Voter.jsp">
6306Enter Your Age : <input type=text name=t1><br>
6307<br>
6308<input type=submit>
6309</form>
6310</body>
6311</html>
6312
6313
6314Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6315
6316import java.sql.*;
6317import java.io.*;
6318class slip29
6319{
6320 public static void main(String args[])
6321 {
6322 Connection con;
6323 Statement state;
6324 ResultSet rs;
6325 int ch,k;
6326 boolean flag=true;
6327 String decision;
6328 int rno;
6329 try
6330 {
6331 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
6332 con = DriverManager.getConnection("jdbc:odbc:dsn");
6333 System.out.println("Statement object created");
6334 do
6335 {
6336 System.out.println("\n");
6337 System.out.println("Menu:");
6338 System.out.println("1.Insert Record into the Table");
6339 System.out.println("2.Update The Existing Record.");
6340 System.out.println("3.Display all the Records from the Table");
6341 System.out.println("4.Delete Record into the Table");
6342 System.out.println("5.Search The Existing Record.");
6343 System.out.println("6.Exit");
6344 System.out.println("Enter your choice: ");
6345 DataInputStream br=new DataInputStream(System.in);
6346 // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6347 ch=Integer.parseInt(br.readLine());
6348 switch(ch)
6349 {
6350 case 1:
6351 System.out.println("Enter Student Number: ");
6352 rno=Integer.parseInt(br.readLine());
6353 System.out.println("Enter Student Name: ");
6354 String name=br.readLine();
6355 System.out.println("Enter Percentage: ");
6356 int per=Integer.parseInt(br.readLine());
6357 String sql="insert into Student values(?,?,?)";
6358 PreparedStatement p=con.prepareStatement(sql);
6359 p.setInt(1,rno);
6360 p.setString(2,name);
6361 p.setInt(3,per);
6362 p.executeUpdate();
6363 System.out.println("Record Added");
6364 break;
6365 case 2:
6366 state=con.createStatement();
6367 System.out.println("Enter the rno");
6368 rno=Integer.parseInt(br.readLine());
6369 System.out.println("Enter the per");
6370 per=Integer.parseInt(br.readLine());
6371 String ss="update Student set Student.per="+per+" where(((Student.[rno])="+rno+"))";
6372 k=state.executeUpdate(ss);
6373 System.out.println(ss);
6374 if(k>0)
6375 {
6376 System.out.println("Record Is Updated");
6377 }
6378 break;
6379 case 3:
6380 state=con.createStatement();
6381 sql="select * from Student";
6382 rs=state.executeQuery(sql);
6383 while(rs.next())
6384 {
6385 System.out.println("\n");
6386 System.out.print("\t" +rs.getInt(1));
6387 System.out.print("\t" +rs.getString(2));
6388 System.out.print("\t" +rs.getInt(3));
6389 }
6390 break;
6391 case 4:
6392 state =con.createStatement();
6393 while(flag)
6394 {
6395 System.out.println("Enter Student Number for the record you wish to Delete: ");
6396 rno=Integer.parseInt(br.readLine());
6397 sql="delete from Student where rno="+rno;
6398 System.out.println(sql);
6399 int rows=state.executeUpdate(sql);
6400 System.out.println(rows+"rows sucessfully Deleted");
6401 System.out.println("Do u want to Delete more data:y/n:");
6402 decision=br.readLine().toLowerCase();
6403 if(decision.charAt(0)=='n')
6404 flag=false;
6405 }
6406 break;
6407 case 5:
6408 state=con.createStatement();
6409 System.out.println("enter roll no u want to search");
6410 rno=Integer.parseInt(br.readLine());
6411 sql="select * from Student where rno="+rno;
6412 rs=state.executeQuery(sql);
6413 System.out.println("success");
6414 while(rs.next())
6415 {
6416 System.out.println("RollNo="+rs.getInt(1)+""+"name="+rs.getString(2)+" "+"per="+rs.getInt(3));
6417 }
6418 break;
6419 case 6:
6420 System.exit(0);
6421 default:
6422 System.out.println("Invalid Choice");
6423 break;
6424 }//switch
6425 }while(ch!=6);
6426 }catch(Exception e)
6427 {
6428 System.out.println(e);
6429 }
6430 }
6431}
6432
6433
6434
6435Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6436
6437
643829.Write a script to create XML file named “Course.xml†....... ...... ..... Store the details of 5 students who are in TYBCA.
6439
6440<?xml version='1.0' encoding='UTF-8' ?>
6441
6442<Course>
6443<ComputerScience>
6444<Studentname>resh</Studentname>
6445<Classname>ty</Classname>
6446<percentage>60</percentage>
6447</ComputerScience>
6448<ComputerScience>
6449<Studentname>tej</Studentname>
6450<Classname>ty</Classname>
6451<percentage>55</percentage>
6452</ComputerScience>
6453<ComputerScience>
6454<Studentname>praj</Studentname>
6455<Classname>sy</Classname>
6456<percentage>55</percentage>
6457</ComputerScience>
6458<ComputerScience>
6459<Studentname>pooja</Studentname>
6460<Classname>fy</Classname>
6461<percentage>78</percentage>
6462</ComputerScience>
6463<ComputerScience>
6464<Studentname>sweety</Studentname>
6465<Classname>LKG</Classname>
6466<percentage>50</percentage>
6467</ComputerScience>
6468<ComputerScience>
6469<Studentname>akshada</Studentname>
6470<Classname>fy</Classname>
6471<percentage>79</percentage>
6472</ComputerScience>
6473</Course>
6474
6475
6476Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6477
647829. Write a PHP script using AJAX concept, to check user name and password are valid or
6479Invalid (use database to store user name and password).
6480Html file :
6481<html>
6482<head>
6483<script type="text/javascript">
6484function validate()
6485{
6486uname=document.getElementById('uname').value;
6487pwd=document.getElementById('pwd').value;
6488}
6489</script>
6490</head>
6491<body>
6492<form action="slip_29-1.php" method=get>
6493Enter UserName<input type=text name=uname id=uname><span id=a></span><br>
6494Enter Password<input type=password name=pwd id=pwd><br>
6495<input type=SUBMIT value=SUBMIT onClick=validate()>
6496</form>
6497</body>
6498</html>
6499
6500Phpfile :
6501<?php
6502$uname=$_GET['uname'];
6503$password=$_GET['pwd'];
6504$con=mysql_connect("localhost","root","") or die("I cannot connect");
6505$d=mysql_select_db("bca_programs",$con);
6506$q=mysql_query("select * from login");
6507$n=0;
6508while($row=mysql_fetch_array($q))
6509{
6510if($row[0]==$uname&& $row[1]==$password)
6511 $n=1;
6512}
6513if($n==0)
6514echo "invalid username or password";
6515?>
6516
6517
6518
6519
6520------------------------------------------------------------------------------------
6521
6522SLIP_30
6523
6524
6525Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6526
6527
6528<html>
6529<body>
6530<%! int n,cnt,i,j; %>
6531<% n=Integer.parseInt(request.getParameter("t1"));
6532for(i=1;i<=n;i++)
6533{
6534 cnt=0;
6535 for(j=2;j<i;j++)
6536 {
6537 if(i%j==0)
6538 {
6539 cnt++;
6540 }
6541 }
6542 if(cnt==0)
6543 {
6544%><br><font color=blue size=5>
6545<%
6546 out.println(" "+i);
6547 }
6548}
6549%>
6550</body>
6551</html>
6552
6553
6554
6555Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXX HTML
6556
6557
6558<html>
6559<body>
6560<form method=post action="prime.jsp">
6561Enter Limit : <input type=text name=t1><br>
6562<input type=submit>
6563</form>
6564</body>
6565</html>
6566
6567
6568Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6569
6570import java.io.*;
6571import javax.servlet.*;
6572import javax.servlet.http.*;
6573import java.sql.*;
6574public class slip30 extends HttpServlet
6575{
6576 private Connection con;
6577 private Statement s;
6578 private ResultSet rs;
6579 public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
6580 {
6581 res.setContentType("text/html");
6582 PrintWriter out = res.getWriter();
6583 try
6584 {
6585 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
6586 con = DriverManager.getConnection("jdbc:odbc:dsn");
6587 s = con.createStatement();
6588 rs = s.executeQuery("select * from product");
6589 out.print("<table border=1 bgcolor='yellow'>"+"<tr bgcolor='red'>"+"<th>Code</th><th>Name</th><th>Price</th></tr>");
6590 while(rs.next())
6591 {
6592 out.print("<tr>"+"<td>"+rs.getInt(1)+"</td>"+"<td>"+rs.getString(2)+"</td>"+"<td>"+rs.getFloat(3)+"</td>"+"</tr>");
6593 }
6594 out.print("</table>");
6595 }
6596 catch(Exception e){out.print(e);}
6597 }
6598}