Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- slip_1
- Slip 1 : Write a JSP script to accept username, store it into the session, compare it with
- password in another jsp file, if username matches with password then display appropriate
- message in html file.
- Slip1_checklogin.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- out.println("Checking login<br>");
- if (username == null || password == null) {
- out.print("Invalid paramters ");
- }
- // Here you put the check on the username and password
- if (username.toLowerCase().trim().equals("admin")&&
- password.toLowerCase().trim().equals("admin")) {
- out.println("Welcome " + username + " <a href=\"Slip1.jsp\">Back to main</a>");
- session.setAttribute("username", username);
- }
- else
- {
- out.println("Invalid username and password");
- }
- %>
- Slip1.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <HTML>
- <HEAD>
- <TITLE>Login using jsp</TITLE>
- </HEAD>
- <BODY>
- <H1>LOGIN FORM</H1>
- <%
- String myname = (String)session.getAttribute("username");
- if(myname!=null)
- {
- out.println("Welcome "+myname+" , <a href=\"Slip1_logout.jsp\" >Logout</a>");
- }
- else
- {
- %>
- <form action="Slip1_checkLogin.jsp">
- <table>
- <tr>
- <td> Username : </td><td><input name="username" size=15 type="text"
- /></td>
- </tr>
- <tr>
- <td> Password : </td><td><input name="password" size=15
- type="password" /></td>
- </tr>
- </table>
- <input type="submit" value="login" />
- </form>
- <%
- }
- %>
- </BODY>
- </HTML>
- Slip1_logout.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- String username=(String)session.getAttribute("username");
- if(username!=null)
- {
- out.println(username+" loged out, <a href=\"Slip1.jsp\">Back</a>");
- session.removeAttribute("username");
- }
- else
- {
- out.println("You are already not login <a href=\"Slip1.jsp\">Back</a>");
- }
- %>
- q1---------------------
- SLIP 1: Write a java program to display IP Address and Name of client machine.
- SERVER:
- import java.io.*;
- import java.net.*;
- class S_Slip1_1
- {
- public static void main(String a[]) throws Exception
- {
- ServerSocketss = new ServerSocket(1000);
- System.out.println("Server is waiting for client : ");
- Socket s =ss.accept();
- System.out.println("Client is connected");
- }
- }
- CLIENT:
- import java.io.*;
- import java.net.*;
- class C_Slip1_1
- {
- public static void main(String a[]) throws Exception
- {
- Socket ss = new Socket("localhost",1000);
- System.out.println("IP Address = "+ss.getInetAddress());
- System.out.println("Client port = "+ss.getPort());
- }
- }
- q1------
- SLIP 1: Write a java program to display IP Address and Name of client machine.
- SERVER:
- import java.io.*;
- import java.net.*;
- class S_Slip1_1
- {
- public static void main(String a[]) throws Exception
- {
- ServerSocketss = new ServerSocket(1000);
- System.out.println("Server is waiting for client : ");
- Socket s =ss.accept();
- System.out.println("Client is connected");
- }
- }
- CLIENT:
- import java.io.*;
- import java.net.*;
- class C_Slip1_1
- {
- public static void main(String a[]) throws Exception
- {
- Socket ss = new Socket("localhost",1000);
- System.out.println("IP Address = "+ss.getInetAddress());
- System.out.println("Client port = "+ss.getPort());
- }
- }
- ---------------------------------------------------------------------------------------------------------------
- slip_2
- q1
- SLIP 2: Write a multithreading program in java to display all the vowels from a given String.
- import java.util.*;
- import java.io.*;
- class Slip2_1 extends Thread
- {
- String s1;
- Slip2_1(String s)
- {
- s1=s;
- start();
- }
- public void run()
- {
- System.out.println("Vowels are ");
- for(int i=0;i<s1.length();i++)
- {
- char ch=s1.charAt(i);
- if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
- System.out.print(" "+ch);
- }
- }
- public static void main(String a[]) throws Exception
- {
- DataInputStreamReader di = new DataInputStreamReader(System.in);
- System.out.println("Enter a string");
- String str=di.readLine();
- Slip2_1 s=new Slip2_1(str);
- }
- }
- q2
- SLIP 2 :
- Write a servlet which counts how many times a user has visited a web page. If the user is
- visiting the page for the first time, display a welcome message. If the user is revisiting the
- page, display the number of times visited. (Use cookies)
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class slip2 extends HttpServlet
- {
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException,IOException
- {
- res.setContentType("text/html");
- PrintWriter out = res.getWriter();
- Cookie c[]=req.getCookies();
- if(c==null)
- {
- Cookie cookie = new Cookie("count","1");
- res.addCookie(cookie);
- out.println("<h3>Welcome Servlet<h3>"+ "slip2:<b>1</b>"); }
- else
- {
- int val=Integer.parseInt(c[0].getValue())+1; c[0].setValue(Integer.toString(val));
- res.addCookie(c[0]);
- out.println("slip2:<b>"+val+"</b>");
- }
- }
- }
- q3
- 2. 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
- <html>
- <body>
- <form action="Q2.php" method='get'>
- <table>
- <tr>
- <td>Enter Your Roll No. </td><td><input type=text name=roll_no placeholder="ex. 112001"><input type=Submit value="Submit"></td>
- </tr>
- <tr>
- <td></td><td><font color="red" size="2">
- format of Roll No: first two digits is 11 for B.sc.,
- 12 for Bcom,
- 13 for BA<br>third digit
- 1/2/3 for respective year<br>last three are for actual roll no.</font></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $roll_no=$_GET['roll_no'];
- echo "Your Roll Number Is :$roll_no<br>";
- $fac=substr($roll_no,0,2);
- if($fac==11)
- echo "Faculty is B.Sc<br>";
- else if($fac==12)
- echo "Faculty is Bcom<br>";
- else if($fac==13)
- echo "Faculty is BA<br>";
- $year=substr($roll_no,2,1);
- if($year==1)
- echo "Year is First Year<br>";
- else if($year==2)
- echo "Year is Second Year<br>";
- else if($year==3)
- echo "Year is Third Year<br>";
- echo "Your Roll No. is".substr($roll_no,3)."<br>";
- ?>
- q4
- 2. Define an interface which has methods area(), volume(). Define constant PI. Create a
- class cylinder which implements this interface and calculate area and volume. (Use define())
- html file :
- <html>
- <body bgcolor="gold">
- <center>
- <h2> Calculate area and value of cylinder</h2>
- <form action="slip_2.php" method="GET">
- <h3> Enter radius : <input type=text name=r><br></h3>
- <h3> Enter height : <input type=text name=h><br><br></h3>
- <input type=submit value=submit name=Show>
- <input type=reset value=Reset name=Reset>
- </form>
- </center>
- </body>
- </html>
- Phpfile :
- <?php
- $r = $_GET['r'];
- $h = $_GET['h'];
- define('PI','3.14');
- interface cal
- {
- function area($r,$h);
- function vol($r,$h);
- }
- class cylinder implements cal
- {
- function area($r,$h)
- {
- $area = 2*PI*$r*($r+$h);
- echo "<h3>The area of cylinder is :$area</h3>";
- }
- function vol($r,$h)
- {
- $vol = PI*$r*$r*$h;
- echo "<h3>The volume of cylinder is :$vol</h3>";
- }
- }
- $c = new cylinder;
- $c->area($r,$h);
- $c->vol($r,$h);
- ?>
- -----------------------------------------------------------------------------------------------------------------------------------------------
- slip_3
- q1
- SLIP 3: Write a JDBC program to display the details of employees (eno, ename, department,
- sal) whose department is “Computer Science”.
- import java.sql.*;
- import java.io.*;
- public class Slip3_1
- {
- public static void main(String args[])thorws IOException
- {
- Connection con;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed....");
- System.exit(1);
- }
- System.out.println("Connection established...");
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * From employee Where dept='computer science'");
- System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
- while(rs.next())
- {
- System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+""+rs.getInt(4));
- }
- con.close();
- rs.close();
- stmt.close();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- q2 ----------
- Slip 3 :Write a java program to simulate traffic signal using multithreading.
- Slip3_2.java
- import java.applet.*;
- import java.awt.*;
- /*<applet code="Slip3_2.java" height="600" width="500">*/
- class Slip3_2 extends Applet implements Runnable
- {
- Thread t;
- int r,g,y,i;
- public void init()
- {
- r=0; g=0; y=0;
- t=new Thread(this);
- t.start();
- }
- public void run()
- {
- try
- {
- for(i=24;i>=1;i--)
- {
- t.sleep(100);
- if(i>=16 && i<24)
- {
- g=1;
- repaint();
- }
- if(i>=8 && i<16)
- {
- y=1;
- repaint();
- }
- if(i>=1 && i<8)
- {
- r=1;
- repaint();
- }
- }
- if(i==0)
- {
- run();
- }
- }
- catch(Exception e)
- {}
- }
- public void paint(Graphics g)
- {
- g.drawOval(100,100,100,100);
- g.drawOval(100,225,100,100);
- g.drawOval(100,350,100,100);
- g.drawString("start" 200,200);
- if(r==1)
- {
- g.setColor(color.red);
- g.fillOval(100,100,100,100);
- g.drawOval(100,100,100,100);
- r=0;
- g.drawString("stop" 200,200);
- if(g==1)
- {
- g.setColor(color.green);
- g.fillOval(100,225,100,100);
- g.drawOval(100,225,100,100);
- g=0;
- if(y==1)
- {
- g.drawString("slow" 200,200);
- g.setColor(color.yellow);
- g.fillOval(100,350,100,100);
- g.drawOval(100,350,100,100);
- y=0;
- }
- }
- }
- q3----------------
- 3. Write a PHP script to demonstrate the introspection for examining class(use function get_declared_classes() ,get_class_methods() and get_class_vars()).
- Phpfile :
- <?php
- class intro
- {
- var $i;
- function f1() {}
- function f2() {}
- }
- class intro_1 extends intro
- {
- var $j,$k;
- function f3() {}
- function f4() {}
- }
- echo class_exists('intro'); //returns true if class is exist
- var_dump(get_declared_classes()); //returns an array of all the class are define & declared in php including classes name
- var_dump(get_class_methods('intro_1')); //returns an array of methods in class intro_1
- var_dump(get_class_methods('Exception')); //returns an array of methods in class Exception
- var_dump(get_class_vars('intro_1')); //returns parent class of given class intro_1 if it is exists
- var_dump(get_parent_class('intro_1')); //reurns parent class of given class if it exist
- var_dump(get_object_vars($ob)); //retuns an array of parameter / variables for given object
- ?>
- q4-------------
- 3. 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.
- Html file :
- <html>
- <body>
- <form action="slip_3.php" method="get">
- <h2> Square : </h2>
- Enter side for Square : <input type="text" name=s>
- <h2> Rectangle : </h2>
- Enter length :<input type="text" name=l><br>
- Enter breath : <input type="text" name=b>
- <h2> Circle : </h2>
- Enter radius : <input type="text" name=r><br>
- <input type="submit" name=submit value=Submit>
- <input type="reset" name=reset value=reset>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $s = $_GET['s'];
- $l = $_GET['l'];
- $b = $_GET['b'];
- $r = $_GET['r'];
- interface findarea
- {
- function area($l,$c);
- }
- class rectangle implements findarea
- {
- function area($l,$b)
- {
- $area = $l*$b;
- echo "Area of Rectanle :".$area."<br>";
- }
- }
- class square extends rectangle
- {
- function area($s,$s)
- {
- $area = $s*$s;
- echo "Area of Square :". $area."<br>";
- }
- }
- class circle
- {
- function area($r)
- {
- $area = 0.5*$r*$r;
- echo "Area of Circle :". $area."<br>";
- }
- }
- $fr = new rectangle;
- $fr->area($l,$b);
- $fs = new square;
- $fs->area($s,$s);
- $fc = new circle();
- $fc->area($r)
- ?>
- ------------------------------------------------------------------------------------------------------------------------------
- slip_4
- q1
- SLIP 4:
- Write a java program to display “Hello Java” message n times on the screen. (Use Runnable
- Interface).
- public class Slip4 implements Runnable
- {
- int i,no;
- Slip4(int n)
- {
- no = n;
- }
- public void run()
- {
- for(i = 1; i<=no; i++)
- {
- System.out.println("\nHello Java");
- try
- {
- Thread.sleep(50);
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- public static void main(String args[])
- {
- try
- {
- int n;
- System.out.println("\nEnter Number : ");
- BufferedReaderbr = new BufferedReader(new InputStreamReader(System.in));
- String s = br.readLine();
- n = Integer.parseInt(s);
- Thread t = new Thread(new Slip4(n));
- t.start();
- }
- catch(Exception e)
- {
- }
- }
- }
- q2-------------
- Slip 4 : Write a JSP program to create a shopping mall. User must be allowed to do
- purchase from two pages. Each page should have a page total. The third page should
- display a bill, which consists of a page total of whatever the purchase has been done and
- print the total.
- Slip4_first.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <title>JSP Page</title>
- </head>
- <body>
- <form action="Slip4_Second.jsp" method="post">
- <h1>Shopping Mall</h1>
- Rice :
- <select name="rice">
- <option value="2">2 Kg</option>
- <option value="5">5 Kg</option>
- <option value="10">10 Kg</option>
- <option value="15">15 Kg</option>
- </select>
- Wheat :
- <select name="wheat">
- <option value="2">2 Kg</option>
- <option value="5">5 Kg</option>
- <option value="10">10 Kg</option>
- <option value="15">15 Kg</option>
- </select>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- Slip4_Second.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- String rice = request.getParameter("rice");
- int r = Integer.parseInt(rice);
- String wheat = request.getParameter("wheat");
- int w = Integer.parseInt(wheat);
- int tr = r * 40;
- int wt = w * 60;
- int pt = tr + wt;
- session.setAttribute("first_Total", pt);
- %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- </head>
- <body>
- <h1>Shopping Mall</h1>
- <form action="Slip4_Third.jsp" method="post">
- Maggi :
- <select name="maggi">
- <option value="1">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- <option value="4">4</option>
- <option value="5">5</option>
- </select>
- Good Day :
- <select name="good">
- <option value="1">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- <option value="4">4</option>
- <option value="5">5</option>
- </select>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- Slip4_Third.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- String m = request.getParameter("maggi");
- String g = request.getParameter("good");
- int mp = Integer.parseInt(m);
- int gp = Integer.parseInt(g);
- int mpt = mp * 10;
- int gpt = gp * 10;
- int secont_total = mpt + gpt;
- int first_Total = (Integer)request.getSession().getAttribute("first_Total");
- NR CLASSES, PUNE (8796064387/90)
- int grand_Total = first_Total + secont_total;
- %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- </head>
- <body>
- <h1>Shopping Mall</h1>
- <h1>First Page Total <%=first_Total%></h1><br>
- <h1>Second Page Total <%=secont_total%></h1><br>
- <h1>Total Bill<%=grand_Total%></h1><br>
- </body>
- </html>
- q3-----------------
- 4. Write a Calculator class that can accept two values, then add them, subtract them, multiply them together, or divide them on request. For example:
- $calc = new Calculator( 3, 4 );
- echo $calc- >add(); // Displays “7”
- echo $calc- >multiply(); // Displays “12”
- html file :
- <html>
- <body>
- <form action="slip_4_Q3.php" method=get>
- <center>
- <table>
- <tr><td>Enter No1</td><td><input type="text" name="a"></td></tr>
- <tr><td>Enter No2</td><td><input type="text" name="b"></td></tr>
- <tr><td></td><td><input type="submit" value="SUBMIT"></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html
- php file :
- <?php
- class Calculate
- {
- public $a;
- public $b;
- function __construct($a,$b)
- {
- $this->a=$a;
- $this->b=$b;
- }
- public function add()
- {
- $c=$this->a+$this->b;
- echo"Addition = $c<br>";
- }
- public function subtract()
- {
- $c=$this->a-$this->b;
- echo"Subtract = $c<br>";
- }
- public function multiply()
- {
- $c=$this->a*$this->b;
- echo"Multiplication = $c<br>";
- }
- public function div()
- {
- $c=$this->a/$this->b;
- echo"Division = $c";
- }
- }
- $x=$_GET['a'];
- $y=$_GET['b'];
- $calc=new Calculate($x,$y);
- $calc->add();
- $calc->subtract();
- $calc->multiply();
- $calc->div();
- ?>
- q4-----------
- 4. 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)
- Html file :
- <html>
- <body>
- <form action="slip_4-1.php" method="post">
- <center>
- <h2> Enter Username : <input type="text" name="name"></h2>
- <h2> Enter Password : <input type="text" name="pwd"></h2>
- <input type="submit" value="Login">
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- slip_4-1.php :
- <?php
- session_start();
- $t=date("1,d-m-y h:i:s",time()+20);
- if($_REQUEST['name']=='xyz’ && $_REQUEST['pwd']=='xyz')
- {
- ?>
- <html>
- <body>
- <h1><u><center>enter ur details</center></u></h1>
- <form action="slip_4-2.php" method=get>
- <input type='hidden' name='etime' value="<?php echo $t?>">
- <h2> Enter Name : <input type=textbox name=uname></h2><br>
- <h2> Enter City : <input type=textbox name=city></h2><br>
- <h2> Enter Phone No : <input type=textbox name=pno></h2><br>
- <input type=submit name=submit value=DISPLAY>
- </form>
- </body>
- </html>
- <?php
- }
- else echo "<center><h1>Invalid Username Or Password</h1></center>"
- ?>
- slip_4-2.php :
- <?php
- session_start();
- $t=$_REQUEST['etime'];
- $exp=date("1,d-m-y h:i:s",time());
- if($t<$exp)
- echo "<center><h1>Page Time Expired</h1></center>";
- else
- {
- echo "<center><h2>Name : ".$_REQUEST['uname']."</h2></center>";
- echo "<center><h2>City : ".$_REQUEST['city']."</h2></center>";
- echo "<center><h2>Phone NO : ".$_REQUEST['pno']."</h2></center>";
- session_destroy();
- }
- ?>
- -----------------------------------------------------------------------------------------------------------------------------------------------------
- slip_5
- q1-----------
- SLIP 5 : Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a
- record in it.
- import java.sql.*;
- class Slip5_1
- {
- public static void main(String args[])
- {
- Connection con;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed....");
- System.exit(1);
- }
- System.out.println("Connection Established...");
- Statement stmt=con.createStatement();
- //create a table teacher
- String query="create table Teacher"+"(TNoint ,"+"
- TNamevarchar(20),"+" salint,"+" desgvarchar(20))";
- stmt.executeUpdate(query);
- System.out.println("given table created in database");
- //insert record into teacher table
- stmt.executeUpdate("insert into Teacher
- "+"values(1,'NRC',50000,'MCS')");
- stmt.executeUpdate("insert into Teacher
- "+"values(2,'ABC',10000,'MCA')");
- stmt.executeUpdate("insert into Teacher
- "+"values(3,'XYZ',40000,'MCA')");
- stmt.executeUpdate("insert into Teacher
- "+"values(4,'PQR',20000,'MCS')");
- System.out.println("Succesfully inserted in table....");
- //display details
- ResultSet rs=stmt.executeQuery("select * From Teacher");
- System.out.println("TNo\t"+"TName\t"+"sal\t"+"desg");
- while(rs.next())
- {
- System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getStr
- ing(4));
- }
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- q2-----------
- import java.awt.*;
- import java.applet.*;
- /*
- <APPLET
- code = "Flag.class"
- width = "500"
- height = "300"
- >
- </APPLET>
- */
- public class Flag extends Applet implements Runnable
- {
- Thread t;
- int x1,x2,x3,y3,x4,y4,x5,ln;
- public void init()
- {
- t=new Thread(this);
- t.start();
- ln=1;
- }
- public void run()
- {
- try
- { if(ln==1)
- {
- for(x1=200;x1>100;)
- {
- t.sleep(200);
- repaint();
- }
- }
- ln=2;
- if(ln==2)
- {
- for(x2=100;x2<150;)
- {
- t.sleep(200);
- repaint();
- }
- }
- ln=3;
- if(ln==3)
- {
- for(x3=150,y3=100;x3>125&&y3<125;)
- {
- t.sleep(200);
- repaint();
- }
- }
- ln=4;
- if(ln==4)
- {
- for(x4=125,y4=125;x4<150&&y4<150;)
- {
- t.sleep(200);
- repaint();
- }
- }
- ln=5;
- if(ln==5)
- {
- for(x5=150;x5>100;)
- {
- t.sleep(200);
- repaint();
- }
- }
- ln=1;
- }catch(Exception e)
- {
- System.out.println(e);
- }
- run();
- }
- public void paint(Graphics g)
- {
- if(ln==1&&x1>100)
- {
- g.drawLine(100,200,100,x1-=5);
- }
- if(ln==2&&x2<150)
- {
- g.drawLine(100,200,100,100);
- g.drawLine(100,100,x2+=5,100);
- }
- if(ln==3&&x3>125&&y3<125)
- {
- g.drawLine(100,200,100,100);
- g.drawLine(100,100,150,100);
- g.drawLine(150,100,x3-=5,y3+=5);
- }
- if(ln==4&&x4<150&&y4<150)
- {
- g.drawLine(100,200,100,100);
- g.drawLine(100,100,150,100);
- g.drawLine(150,100,125,125);
- g.drawLine(125,125,x4+=5,y4+=5);
- }
- if(ln==5&&x5>100)
- {
- g.drawLine(100,200,100,100);
- g.drawLine(100,100,150,100);
- g.drawLine(150,100,125,125);
- g.drawLine(125,125,150,150);
- g.drawLine(150,150,x5-=5,150);
- }
- }
- }
- q3--------------------------------------
- 5. Write an PHP script to search employee name from employee.dat file(Use AJAX concept)
- employee.dat file
- 1 Ramesh
- 2 Gopal
- 3 sandip
- HTML File
- <html>
- <head><title>Slip 5</title>
- <script>
- function search()
- {
- s=document.getElementById('txt1').value;
- ob=new XMLHttpRequest();
- ob.onreadystatechange=function()
- {
- if(ob.readyState==4 &&ob.status==200)
- {
- document.getElementById('o').innerHTML=ob.responseText;
- }
- }
- ob.open("GET","slip5.php?srch="+s);
- ob.send();
- }
- </script>
- </head>
- <body>
- <input type=text id=txt1 placeholder="Enter Employee name"></br>
- <input type=button value="Search" onclick="search()">
- <h1 id="o">Output</h1>
- </body>
- </html>
- PHP File
- <?php
- $nm=$_GET['srch'];
- $fp=fopen("employee.dat","r");
- echo "<table border=1><tr><th>EmpId</th><th>Employee Name</th></tr>";
- while($res=fscanf($fp,"%s %s"))
- {
- if($res[1]==$nm)
- {
- echo "<tr><td>".$res[0]."</td><td>".$res[1]."</td><tr>";
- }
- }
- echo "</table>";
- ?>
- q4------------------------------
- 5. 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).
- <?php
- class Employee
- {
- private $eid,$ename,$edept,$sal;
- function __construct($a,$b,$c,$d)
- {
- $this->eid=$a;
- $this->ename=$b;
- $this->edept=$c;
- $this->sal=$d;
- }
- public function getdata()
- {
- return $this->sal;
- }
- public function display()
- {
- echo $this->eid."</br>";
- echo $this->ename."</br>";
- echo $this->edept."</br>";
- }
- }
- class Manager extends Employee
- {
- private $bonus;
- public static $total1=0;
- function __construct($a,$b,$c,$d,$e)
- {
- parent::__construct($a,$b,$c,$d);
- $this->bonus=$e;
- }
- public function max($ob)
- {
- $sal=$this->getdata();
- $total=$sal+$this->bonus;
- if($total>self::$total1)
- {
- self::$total1=$total;
- return $this;
- }
- else
- {
- return $ob;
- }
- }
- public function display()
- {
- parent::display();
- echo self::$total1;
- }
- }
- $ob=new Manager(0,"ABC","",0,0);
- $ob1=new Manager(1,"ramdas","computer",28000,2000);
- $ob=$ob1->max($ob);
- $ob2=new Manager(2,"ramdas1","computer",30000,2500);
- $ob=$ob2->max($ob);
- $ob3=new Manager(3,"ramdas2","computer",32000,3000);
- $ob=$ob3->max($ob);
- $ob4=new Manager(4,"ramdas","computer",28000,4000);
- $ob=$ob4->max($ob);
- $ob5=new Manager(5,"ramdas","computer",28000,5000);
- $ob=$ob5->max($ob);
- $ob->display();
- ?>
- ---------------------------------------------------------------------------------------------------------------------------------------------
- slip_6
- q1---------------------------
- SLIP 6: Write a java program to accept the details of customer (CID, CName, Address,
- Ph_No) and store it into the database(Use PreparedStatement interface)
- import java.sql.*;
- import java.io.*;
- class Slip6_1
- {
- public static void main(String a[])
- {
- PreparedStatement ps;
- Connection con;
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn6");
- if(con==null)
- {
- System.out.println("Connection Failed......");
- System.exit(1);
- }
- System.out.println("Connection Esatablished......");
- Statement stmt=con.createStatement();
- BufferedReaderbr = new BufferedReader(new
- InputStreamReader(System.in));
- String query="insert into Customer values(?,?,?,?)";
- ps=con.prepareStatement(query);
- System.out.println("Customer Details....");
- System.out.println("Enter CID");
- int cid=Integer.parseInt(br.readLine());
- ps.setInt(1,cid);
- System.out.println("Enter name");
- String name=br.readLine();
- ps.setString(2,name);
- System.out.println("Enter Address");
- String add=br.readLine();
- ps.setString(3,add);
- System.out.println("Enter Ph_No");
- String phno=br.readLine();
- ps.setString(4,phno);
- int no=ps.executeUpdate();
- if(no!=0)
- System.out.println("Data inserted succesfully.....");
- else
- System.out.println("Data NOT inserted");
- con.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- q2----------------------
- Slip 6 : Write a socket program in java to check whether given file is present on server or
- not, If it present then display its content on the server’s machine.
- S_Slip6_2.java
- import java.io.*;
- import java.net.*;
- class S_Slip6_2
- {
- public static void main(String a[]) throws Exception
- {
- ServerSocket ss = new ServerSocket(1000);
- System.out.println("Server is waiting for client : ");
- Socket s =ss.accept();
- System.out.println("Client is connected");
- DataInputStream dis=new DataInputStream(s.getInputStream());
- DataOutputStream dos=new DataOutputStream(s.getOutputStream());
- String fname =(String)dis.readUTF();
- File f = new File(fname);
- if(f.exists())
- {
- System.out.println("file is exists");
- FileInputStream fin = new FileInputStream(fname);
- int ch;
- String msg = "";
- while((ch=fin.read())!=-1)
- {
- msg=msg+(char)ch;
- }
- dos.writeUTF(msg);
- }
- else
- dos.writeUTF("0");
- }
- }
- C_Slip6_2.java
- import java.io.*;
- import java.net.*;
- class C_Slip6_2
- {
- public static void main(String a[]) throws Exception
- {
- Socket s = new Socket("localhost",1000);
- System.out.println("client is connected : ");
- DataInputStream dis=new DataInputStream(s.getInputStream());
- DataOutputStream dos=new DataOutputStream(s.getOutputStream());
- BufferedReader br = new BufferedReader(new
- InputStreamReader(System.in));
- System.out.println("Enter file name : ");
- String fname = br.readLine();
- dos.writeUTF(fname);
- String msg = (String)dis.readUTF();
- if(msg.equals("0"))
- System.out.println("File not present ");
- else
- {
- System.out.println("Content of the file is : \n");
- System.out.println(msg);
- }
- }
- }
- q3------------------------------------
- 6. Write a PHP Script create login form and validate it (Use database and Sticky form concept)
- <html>
- <head>
- <title>Sticky Form</title>
- </head>
- <body>
- <form action="<?php echo $_SERVER['PHP_SELF']?>" method=post>
- <input type=text name=txtuname value="<?php if(isset($_POST['txtuname']))echo $_POST['txtuname'];?>" ></br>
- <input type=password name=txtupass value="<?php if(isset($_POST['txtupass']))echo $_POST['txtupass'];?>" ></br>
- <input type=submit value="Login" name=submit>
- <?php
- if(isset($_POST['submit']))
- $nm=$_POST['txtuname'];
- $ps=$_POST['txtupass'];
- $con=mysql_connect("localhost","root","rsb");
- mysql_select_db("slip6db",$con);
- $result=mysql_query("select * from login where uname='$nm' and upass='$ps'");
- $flag=0;
- while($row=mysql_fetch_array($result))
- {
- $flag++;
- }
- if($flag==1)
- echo "Login validated";
- else
- echo "username or password invalid";
- ?>
- </body>
- </html>
- Q4-----------------------
- 6. 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.
- <?php
- class vehicle
- {
- public $company,$price;
- public function __construct($a,$b)
- {
- $this->company=$a;
- $this->price=$b;
- }
- }
- class Lightmotorvehicle extends vehicle
- {
- public $milege;
- public function __construct($a,$b,$c)
- {
- $this->company=$a;
- $this->price=$b;
- $this->milege=$c;
- }
- public function display()
- {
- echo "<table border=1 width=300>
- <tr><td>".$this->company."</td>
- <td>".$this->price."</td><td>".$this->milege."</td></tr>";
- }
- }
- class Heavymotorvehicle extends vehicle
- {
- public $capacity;
- public function __construct($a,$b,$c)
- {
- $this->company=$a;
- $this->price=$b;
- $this->capacity=$c;
- }
- public function display()
- {
- echo "<table border=1 width=300>";
- echo "<tr><td>".$this->company."</td><td>".$this->price."</td><td>".$this->capacity;
- echo "</td></tr></table>";
- }
- }
- $ob1=new Lightmotorvehicle("Maruti",200000,25);
- $ob1->display();
- $ob2=new Lightmotorvehicle("Toyota",500000,20);
- $ob2->display();
- $ob3=new Lightmotorvehicle("skoda",400000,15);
- $ob3->display();
- $ob4=new Heavymotorvehicle("Tata Truck",1220000,25);
- $ob4->display();
- $ob5=new Heavymotorvehicle("Bajaj",200000,25);
- $ob5->display();
- $ob6=new Heavymotorvehicle("mahindra",900000,25);
- $ob6->display();
- ?>
- -------------------------------------------------------------------------------------------------------------------------------
- slip_7
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <body>
- <%! int n,rem,r; %>
- <% n=Integer.parseInt(request.getParameter("num"));
- if(n<10)
- {
- out.println("Sum of first and last digit is ");
- %><font size=18 color=red><%= n %></font>
- <%
- }
- else
- {
- rem=n%10;
- do{
- r=n%10;
- n=n/10;
- }while(n>0);
- n=rem+r;
- out.println("Sum of first and last digit is ");
- %><font size=18 color=red><%= n %></font>
- <%
- }
- %>
- </body>
- </html>
- q2 (1)----------------------------------------
- SLIP 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.
- HTML FILE
- <!DOCTYPE html>
- <html>
- <body>
- <form method=post action="Slip7.jsp">
- Enter Any Number : <Input type=text name=num><br><br>
- <input type=submit value=Display>
- </form>
- </body>
- </html>
- q2-------------------------------------------------------------------------------------------
- import java.awt.Color;
- import java.awt.Graphics;
- import javax.swing.*;
- /*<APPLET CODE="car.class" WIDTH=400 HEIGHT=300> </APPLET>*/
- public class car extends JApplet {
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.getContentPane().add(new car());
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(1024, 739);
- frame.setVisible(true);
- }
- public void paint(Graphics g) {
- try
- {
- int j = 0;
- while (j < 500)
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, 5000, 5000);
- g.setColor(Color.red);
- g.fillRect(250 + j, 250, 100, 50);
- g.setColor(Color.black);
- g.fillOval(260 + j, 300, 20, 20);
- g.fillOval(320 + j, 300, 20, 20);
- j++;
- Thread.sleep(2);
- }
- } catch (InterruptedException e) {
- }
- }
- }
- q3----------------------------------------
- 7.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)
- Html file :
- <html>
- <body>
- <form action="slip_7_Q3_1.php" method="post">
- <center>
- <h2>Enter Employee Details :</h2>
- <table>
- <tr><td>Name : </td><td><input type="text" name="name"></td><tr>
- <tr><td>Address : </td><td><input type="text" name="addr"></td></tr>
- <tr><td>Mobile No : </td><td><input type="text" name="mob_no"></td></tr>
- <tr><td></td><td><input type="submit" value=Next></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- slip_7_Q3_1.php
- <html>
- <body>
- <form action="slip_7_Q3_2.php" method="post">
- <center>
- <h2>Enter LIC Information :</h2>
- <table>
- <tr><td>Policy no. : </td><td><input type="text" name="p_no"></td><tr>
- <tr><td>Policy Name : </td><td><input type="text" name="p_name"></td></tr>
- <tr><td>Premium : </td><td><input type="text" name="premium"></td></tr>
- <tr><td></td><td><input type="submit" value=Next></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- <?php
- setcookie("emp1",$_POST['name'],time()+3600);
- setcookie("emp2",$_POST['addr'],time()+3600);
- setcookie("emp3",$_POST['mob_no'],time()+3600);
- ?>
- Phpfile :
- slip_7_Q3_2.php
- <?php
- echo "<h3>Employee Details</h3> ";
- echo "<b>Name : </b>".$_COOKIE['emp1']."<br>";
- echo "<b>Address : </b>".$_COOKIE['emp2']."<br>";
- echo "<b>Mobile No. : </b>".$_COOKIE['emp3']."<br>";
- echo "<b>Policy no. : </b>".$_POST['p_no']."<br>";
- echo "<b>Policy Name : </b>".$_POST['p_name']."<br>";
- echo "<b>Premium : </b>".$_POST['premium']."<br>";
- ?>
- ------------------------------------------------------------------------------------------------------
- slip_8
- q1----------------------------------------------------
- SLIP 8: Write a multithreading program using Runnable interface to blink Text on the frame.
- import java.awt.*;
- import java.awt.event.*;
- class Slip8_1 extends Frame implements Runnable
- {
- Thread t;
- Label l1;
- int f;
- Slip8_1()
- {
- t=new Thread(this);
- t.start();
- setLayout(null);
- l1=new Label("Hello JAVA");
- l1.setBounds(100,100,100,40);
- add(l1);
- setSize(300,300);
- setVisible(true);
- f=0;
- }
- public void run()
- {
- try
- {
- if(f==0)
- {
- t.sleep(200);
- l1.setText("");
- f=1;
- }
- if(f==1)
- {
- t.sleep(200);
- l1.setText("Hello Java");
- f=0;
- }
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- run();
- }
- public static void main(String a[])
- {
- new Slip8_1();
- }
- }
- q2----------------------------------------------------------------------
- save file to .html
- <html>
- <head>
- <title>New Page 1</title>
- </head>
- <body>
- <form method="POST" action="http://localhost:8080/loginslip8">
- <p>Enter Username: <input type="text" name="uname" size="20"></p>
- <p>Enter Password: <input type="text" name="pass" size="20"></p>
- <p> <input type="submit" value="Submit" name="B1"></p>
- </form>
- </body>
- </html>
- q2---------------------------------------------
- import java.io.*;
- import java.lang.*;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class loginslip8 extends HttpServlet
- {
- public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
- {
- response.setContentType("text/html");
- PrintWriter pw = response.getWriter();
- Connection conn;
- try
- {
- String uname = request.getParameter("uname");
- String pass = request.getParameter("pass");
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- conn = DriverManager.getConnection("jdbc:odbc:mydsn.dsn");
- String query = "select * from login where username='"+uname+"' and password='"+pass+"'";
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- if(rs.next())
- {
- pw.println("<br>Welcome ..."+uname);
- } else {
- pw.println("<br>Sorry, Please enter correct credentials");
- }
- }
- catch (Exception e){
- pw.println(e);
- }
- }
- q3--------------------------------------------------------------------------
- 8. Write a script to keep track of number of times the web page has been accessed
- (use $_COOKIE).
- <?php
- if(isset($_COOKIE['cnt']))
- {
- $x=$_COOKIE['cnt'];
- $x=$x+1;
- setcookie('cnt',$x);
- }
- else
- {
- setcookie('cnt',2);
- echo "you accessed this page 1st time";
- }
- echo “You accessed this page $_COOKIE['cnt'] times”;
- ?>
- q4----------------------------------------------------------------------------------------------------
- 8. 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’.
- Html file :
- <html>
- <head>
- <script type="text/javascript">
- functionval_user(str)
- {
- varob=false;
- ob=new XMLHttpRequest();
- if(str=="")
- document.getElementById("a").innerHTML="Username Should not be Empty";
- elseif(str.length<=3)
- document.getElementById('a').innerHTML="lenght is too short";
- elsedocument.getElementById('a').innerHTML="valid username";
- }
- </script>
- </head>
- <body>
- <form>
- <table align="center">
- <tr><td><b>Enter Username : </b></td><td><input type=text name=u_name id=u_name></td></tr>
- <tr><td></td><td><font color="red" size=3><span id=a></span></font></td></tr>
- <tr><thcolspan="2"><input type=button value=submit onclick="val_user(form.u_name.value)"></th></tr>
- </table>
- </form>
- </body>
- </html>
- -------------------------------------------------------------------------------------------------------------------------------------------------
- slip_9
- q1-----------------------------------------------------------------
- SLIP 9: Write a JDBC program to delete the records of employees whose names are starts with ‘A’character.
- import java.sql.*;
- class Slip9_1
- {
- public static void main(String args[])
- {
- Connection con;
- Statement stmt;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed....");
- System.exit(1);
- }
- System.out.println("Connection Established...");
- stmt=con.createStatement();
- int no = stmt.executeUpdate("Delete from employee where name like 'A%'");
- if(no!=0)
- System.out.println("Delete Data sucessfully.....");
- else
- System.out.println("Data NOT Deleted");
- con.close();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- q2----------------------------------------------------------------------------------------
- import java.applet.Applet;
- import java.awt.*;
- public class slip9b extends Applet implements Runnable
- {
- Thread t;
- int x,y,k;
- int counter=0;
- public void init()
- {
- x=10;
- k=0;
- y=200;
- t=new Thread(this);
- t.start();
- }
- public void run()
- {
- try
- {
- while(true)
- {
- repaint();
- Thread.sleep(1000);
- ++counter;
- }
- }
- catch(Exception e)
- { }
- }
- public void paint(Graphics g)
- {
- g.setFont(new Font("ariel",Font.BOLD,30));
- FontMetrics fm=g.getFontMetrics();
- String s="Vinita";
- Dimension d=getSize();
- g.drawString(s,x,y);
- if(k==0)
- {
- x=360;
- y=25;
- k=1;
- }
- else if(k==1)
- {
- x=700;
- y=200;
- k=2;
- }
- else if(k==2)
- {
- x=360;
- y=400;
- k=3;
- }
- else if(k==3)
- {
- x=10;
- y=200;
- k=0;
- }
- }
- }
- q3-------------------------------------------------------------------------------------------
- 9. 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).
- Html file :
- <html>
- <body>
- <form action="slip9.php" method=get>
- <center><h2>For Cone & Cylinder</h2>
- Enter Radius </td><td><input type="text" name="r">
- Enter Height</td><td><input type="text" name="h">
- <input type="submit" value="SUBMIT">
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- define('pi',3.14);
- abstract class shape
- {
- abstract function calc_area($r,$h);
- abstract function calc_vol($r,$h);
- }
- class sphere extends shape
- {
- functioncalc_area($r,$r)
- {
- return 4*pi*$r*$r;
- }
- functioncalc_vol($r,$r)
- {
- return (4/3)*pi*$r*$r*$r;
- }
- }
- class cylinder extends shape
- {
- functioncalc_area($r,$h)
- {
- return 2*pi*$r*($r+$h);
- }
- functioncalc_vol($r,$h)
- {
- return pi*$r*$r*$h;
- }
- }
- class cone extends shape
- {
- functioncalc_area($r,$h)
- {
- return 0.5*$r*$r*$h;
- }
- functioncalc_vol($r,$h)
- {
- return $r*$r*$r*$h;
- }
- }
- $r=$_GET['r'];
- $h=$_GET['h'];
- $ob=new cone();
- echo "Area of cone ".$ob->calc_area($r,$h);
- echo "</br>";
- echo "Volume of cone ".$ob->calc_vol($r,$h);
- echo "</br>";
- $ob=new cylinder();
- echo "Area of cylinder ".$ob->calc_area($r,$h);
- echo "</br>";
- echo "Volume of cylinder".$ob->calc_vol($r,$h);
- echo "</br>";
- $ob=new sphere();
- echo "Area of sphere ".$ob->calc_area($r,$r);
- echo "</br>";
- echo "Volume of sphere ".$ob->calc_vol($r,$r);
- ?>
- ---------------------------------------------------------------------------------------------------------------------------------------------
- slip_10
- q1-----------------------
- SLIP 10: Write a JDBC program to count the number of records in table.(Without using standard method)
- import java.sql.*;
- class Slip10_1
- {
- public static void main(String args[])
- {
- Connection con;
- Statement stmt;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed.......");
- System.exit(1);
- }
- System.out.println("Connection Established......");
- stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * from employee");
- int cnt=0;
- while(rs.next())
- {
- cnt++;
- }
- System.out.println("Number of records in Table are:"+cnt);
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- q2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Slip 10 : Write a multithreading application in java for bouncing ball.
- Slip 10_2.java
- import java.awt.*;
- class Slip10_2 extends java.applet.Applet implements Runnable
- {
- Thread t;
- int f,y,f1,f2,f3;
- public void init()
- {
- t=new Thread(this);
- t.start();
- f=0; y=0; f1=0;
- }
- public void run()
- { try
- {
- if (f==0)
- { t.sleep(10);
- y=y+5;
- repaint();
- if(f1==6)
- f1=0;
- }
- if(f==1)
- { t.sleep(10);
- y=y-5;
- repaint();
- if(f1==6)
- f1=0;
- }
- }
- catch(Exception e)
- {System.out.println(e); }
- run();
- }
- public void paint(Graphics g)
- {
- if(f==0)
- {
- if(f1==1)
- g.setColor(Color.green);
- if(f1==2)
- g.setColor(Color.blue);
- if(f1==3)
- g.setColor(Color.red);
- if(f1==4)
- g.setColor(Color.yellow);
- if(f1==5)
- g.setColor(Color.orange);
- g.fillOval(150,y+10,20,20);
- if(y==400)
- {
- f1++;
- f=1;
- }
- }
- if(f==1)
- {
- if(f1==1)
- g.setColor(Color.green);
- if(f1==2)
- g.setColor(Color.blue);
- if(f1==3)
- g.setColor(Color.red);
- if(f1==4)
- g.setColor(Color.yellow);
- if(f1==5)
- g.setColor(Color.orange);
- g.fillOval(150,y-10,20,20);
- if(y==0)
- {
- f1++; f=0;
- }
- }
- q4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- 10. Create a form to accept student information (name, class, address). Once the student
- information is accepted, accept marks in next form (Java, PHP, ST, IT, pract1, and project).
- Display the mark sheet for the student in the next form containing name, class, marks of the
- subject, total and percentage(Use $_COOKIE).
- Html file :
- <html>
- <body>
- <form action="slip_10-1.php" method="post">
- <center>
- <h2>Enter Students information :</h2>
- <table>
- <tr><td>Name : </td><td><input type="text" name="name"></td><tr>
- <tr><td>Address : </td><td><input type="text" name="addr"></td></tr>
- <tr><td>Class : </td><td><input type="text" name="class"></td></tr>
- <tr><td></td><td><input type="submit" value=Next></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- Slip_10-1.php :
- <html>
- <body>
- <form action="slip_10-2.php" method="post">
- <center>
- <h2>Enter Marks for Student:</h2>
- <table>
- <tr><td>Java : </td><td><input type="text" name="m1"></td><tr>
- <tr><td>PHP : </td><td><input type="text" name="m2"></td></tr>
- <tr><td>ST : </td><td><input type="text" name="m3"></td></tr>
- <tr><td>IT : </t d><td><input type="text" name="m4"></td></tr>
- <tr><td>Practical : </td><td><input type="text" name="m5"></td></tr>
- <tr><td>Project : </td><td><input type="text" name="m6"></td></tr>
- <tr><td></td><td><input type="submit" value=Next></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- <?php
- setcookie("stud1",$_POST['name'],time()+3600);
- setcookie("stud2",$_POST['addr'],time()+3600);
- setcookie("stud3",$_POST['class'],time()+3600);
- ?>
- Slip_10-2.php :
- <?php
- echo "<h3>Marksheet</h3> ";
- echo "Name : ".$_COOKIE['stud1']."<br>";
- echo "Address : ".$_COOKIE['stud2']."\n";
- echo "Class : ".$_COOKIE['stud3']."\n";
- echo "Java : ".$_POST['m1']."\n";
- echo "PHP : ".$_POST['m2']."\n";
- echo "ST : ".$_POST['m3']."\n";
- echo "IT : ".$_POST['m3']."\n";
- echo "Practical : ".$_POST['m3']."\n";
- echo "Project : ".$_POST['m3']."\n";
- ?>
- ----------------------------------------------------------------------------------------------------------------
- slip_11
- Q1=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP11: Write a JDBC program to remove “percentage” column from student (rno, sname, percentage) table. Student table is already created.
- import java.sql.*;
- class Slip11
- {
- public static void main(String a[])
- {
- Connection con;
- Statement stmt;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed.......");
- System.exit(1);
- }
- System.out.println("Connection Established......");
- stmt=con.createStatement();
- int no = stmt.executeUpdate("alter table student drop column per");
- if(no!=0)
- System.out.println("Drop col sucessfully");
- else
- System.out.println("NOT Drop col ");
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.util.*;
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class slip11 extends HttpServlet {
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- res.setContentType("text/html");
- PrintWriter out = res.getWriter();
- // Get the current session object, create one if necessary
- HttpSession session = req.getSession();
- out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
- out.println("<BODY><H1>Session Timer</H1>");
- // Display the previous timeout
- out.println("The previous timeout was " +
- session.getMaxInactiveInterval());
- out.println("<BR>");
- // Set the new timeout
- session.setMaxInactiveInterval(2*60*60); // two hours
- // Display the new timeout
- out.println("The newly assigned timeout is " +
- session.getMaxInactiveInterval());
- out.println("</BODY></HTML>");
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 11. Write PHP script to create a CD catalog using XML file.
- Xml file :
- <?xml version='1.0' encoding='UTF-8' ?>
- <CD>
- <cd type='music'>
- <name>silent_songs</name>
- <launch-date>5-6-2014</launch-date>
- <composer>A-R-Rehman</composer>
- </cd>
- <cd type='music'>
- <name>Hip-Hop</name>
- <launch-date>4-8-2011</launch-date>
- <composer>Yo-Yo-Honey singh</composer>
- </cd>
- <cd type='music'>
- <name>love track</name>
- <launch-date>6-9-2000</launch-date>
- <composer>Arjit Singh</composer>
- </cd>
- </CD>
- Phpfile :
- <?php
- $xml=simplexml_load_file('slip_11_Q3.xml');
- var_dump($xml);
- ?>
- -----------------------------------------------------------------------------------------------------------------------------------------
- SLIP_12
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP12: Write a java program to display the number’s between 1 to 100 continuously in a TextField by clicking on button. (use Runnable Interface)
- import java.awt.event.*;
- import javax.swing.*;
- class Message implements Runnable
- {
- JTextField t;
- public void run()
- {
- for(int i =1; i<=100;i++)
- {
- t.setText(""+i);
- try
- {
- Thread.sleep(50);
- }
- catch(Exception e)
- {
- }
- }
- }
- }
- class Slip12_1 implements ActionListener
- {
- JFrame f;
- JPanel p;
- JTextField t;
- JButton b;
- Thread t1;
- Slip12_1()
- {
- f = new JFrame();
- p = new JPanel();
- t = new JTextField(60);
- b = new JButton("Start");
- t1 = new Thread(this);
- b.addActionListener(this);
- p.add(t);
- p.add(b);
- f.add(p);
- f.setSize(400, 400);
- f.setVisible(true);
- }
- public void actionPerformed(ActionEvent e)
- {
- t1.start();
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- Slip 12 :Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it
- into database and display it in tabular form. (Use PreparedStatement interface)
- Slip12.html
- <!-- To change this template, choose Tools | Templates and open the template in the editor.
- -->
- <!DOCTYPE html>
- <html><body>
- <form method=get action="Slip12.jsp">
- Enter Account No. : <input type=text name=ano><br><br>
- Enter Account Type:<input type=text name=type><br><br>
- Enter Balance : <input type=text name=bal><br><br>
- <input type=submit value="Save">
- </form>
- </body></html>
- Slip12.jsp
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html><body>
- <%@ page import="java.sql.*;" %>
- <%! int ano,bal;
- String type; %>
- <%
- ano=Integer.parseInt(request.getParameter("ano"));
- type=request.getParameter("type");
- bal=Integer.parseInt(request.getParameter("bal"));
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection cn=DriverManager.getConnection("jdbc:odbc:acnt","","");
- PreparedStatement s=cn.prepareStatement("insert into Account values(?,?,?)");
- s.setInt(1,ano);
- s.setString(2,type);
- s.setInt(3,bal);
- s.executeUpdate();
- out.println("Record is saved");
- Statement st=cn.createStatement();
- ResultSet rs=st.executeQuery("select * from Account");
- %>
- <table border="1" width="40%">
- <% while(rs.next())
- {
- %>
- <tr><td><%= rs.getInt("ano") %></td>
- <td><%= rs.getString("type") %></td>
- <td><%= rs.getInt("bal") %></td>
- </tr>
- <%
- }
- cn.close();
- }catch(Exception e)
- {
- out.println(e);
- }
- %>
- </body></html>
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 12. Write a PHP script for the following: Design a form to accept a number from the user. Perform the operations and show the results.
- 1) Factorial of a number using Recursion.
- 2) Add the digits of that number to reduce it to single digit.
- (use the concept of self processing page.)
- <html>
- <head>
- <title>slip12</title>
- </head>
- <body>
- <?php
- if($_SERVER['REQUEST_METHOD']=="GET")
- {
- ?>
- <form action="<?php echo $_SERVER['PHP_SELF']?>" method=POST>
- <input type name=txtnumber placeholder="Enter a number ">
- <input type=submit value="calculate">
- </form>
- <?php
- }
- else if($_SERVER['REQUEST_METHOD']=="POST")
- {
- function fact($n)
- {
- if($n==1)
- {
- return 1;
- }
- else { return($n*fact($n-1));
- }
- }
- functionsingleval($n)
- {
- while($n>9)
- {$sum=0;
- while($n)
- {
- $r=$n%10;
- $sum=$sum+$r;
- $n=$n/10;
- }
- $n=$sum;
- }
- return $n;
- }
- echo fact($_POST['txtnumber']);
- echo "</br>";
- echosingleval($_POST['txtnumber']);
- }
- ?>
- </body>
- </html>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 12. Create student table as follows Student(sno, sname, per).
- Write Ajax program to select the student name and print the selected student’s details.
- Html file :
- <html>
- <body>
- <form action="slip_12.php" method="get">
- Enter student name Name:<input type="text" name=sname><br>
- <input type="submit" value=submit>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $sname=$_GET['sname'];
- $con=mysql_connect("localhost","root","");
- $d=mysql_select_db("bca_programs",$con);
- $result=mysql_query("select *from student where sname='$sname'");
- while($row=mysql_fetch_array($result))
- {
- echo $row['sno']."--".$row['sname']."--".$row['per']."<br>";
- }
- ?>
- ----------------------------------------------------------------------------------------------------------------
- SLIP_13
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP13: Write a java program to create a Mobile (Model_No, Company_Name, Price, Color) table.
- import java.sql.*;
- class Slip13_1
- {
- public static void main(String a[])
- {
- Connection con;
- Statement stmt;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed");
- System.exit(1);
- }
- System.out.println("Connection Established....");
- stmt=con.createStatement();
- String sql="create table mobile"+"(Model_No int,"+"Company_Name varchar(20),"+"price float(6,2),"+"color varchar(20))";
- stmt.executeUpdate(sql);
- System.out.println("Table Created sucessfully...");
- con.close();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CLIENT XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- GossipClient.java
- import java.io.*;
- import java.net.*;
- public class GossipClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket sock = new Socket("127.0.0.1", 3000);
- // reading from keyboard (keyRead object)
- BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
- // sending to client (pwrite object)
- OutputStream ostream = sock.getOutputStream();
- PrintWriter pwrite = new PrintWriter(ostream, true);
- // receiving from server ( receiveRead object)
- InputStream istream = sock.getInputStream();
- BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
- System.out.println("Start the chitchat, type and press Enter key");
- String receiveMessage, sendMessage;
- while(true)
- {
- sendMessage = keyRead.readLine(); // keyboard reading
- pwrite.println(sendMessage); // sending to server
- pwrite.flush(); // flush the data
- if((receiveMessage = receiveRead.readLine()) != null) //receive from server
- {
- System.out.println(receiveMessage); // displaying at DOS prompt
- }
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SERVER XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- GossipServer.java
- import java.io.*;
- import java.net.*;
- public class GossipServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket sersock = new ServerSocket(3000);
- System.out.println("Server ready for chatting");
- Socket sock = sersock.accept( );
- // reading from keyboard (keyRead object)
- BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
- // sending to client (pwrite object)
- OutputStream ostream = sock.getOutputStream();
- PrintWriter pwrite = new PrintWriter(ostream, true);
- // receiving from server ( receiveRead object)
- InputStream istream = sock.getInputStream();
- BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
- String receiveMessage, sendMessage;
- while(true)
- {
- if((receiveMessage = receiveRead.readLine()) != null)
- {
- System.out.println(receiveMessage);
- }
- sendMessage = keyRead.readLine();
- pwrite.println(sendMessage);
- pwrite.flush();
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 13. Write a PHP script using AJAX concept, to develop user-friendly and interactive search engine
- HTML File
- <html>
- <head>
- <title>Slip13.html</title>
- <script>
- function search()
- {
- srch=document.getElementById('txtsrch').value;
- ob=new XMLHttpRequest();
- ob.onreadystatechange=function()
- {
- if(ob.readyState==4 &&ob.status==200)
- {
- document.getElementById('o').innerHTML=ob.responseText;
- }
- }
- ob.open("GET","slip13.php?s="+srch);
- ob.send();
- }
- </script>
- </head>
- <body>
- <table align=center border=0>
- <tr><td><input type=text id=txtsrch placeholder="enter search string"><input type=button value="SEARCH" onclick="search()">
- </table>
- <span id=o></span>
- </body>
- </html>
- PHP File
- <?php
- $search=$_GET['s'];
- $con=mysql_connect("localhost","root","rsb");
- mysql_select_db("slip13db",$con);
- $r=mysql_query("select * from slip13 where des='$search'");
- echo "<table align=center">
- while($row=mysql_fetch_array($r))
- {
- echo "<tr><td>".$row[0]."</td></tr>";
- }
- echo "</table>";
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 13. Considerer the following entities and their relationships.
- Student (Stud_id,name,class)
- Competition (c_no,c_name,type)
- Relationship between student and competition is many-many with attribute rank and year.
- Create 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.
- Html file :
- <html>
- <body>
- <form action="slip_13.php" method="get">
- Enter the name of competition :<input type=text name=cname><br>
- <input type=submit value=SUBMIT>
- </form>
- </body>
- <html>
- Phpfile :
- <?php
- $c_name = $_GET['cname'];
- $con = mysql_connect("localhost","root","");
- $d = mysql_select_db("bca_programs",$con);
- $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");
- echo "<table>";
- echo "<tr><td>Student Id |</td><td>Student Name |</td><td>Student Class</td></tr>";
- while($row = mysql_fetch_array($q))
- {
- echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
- }
- echo "</table>";
- mysql_close();
- ?>
- -------------------------------------------------------------------------------------------------------------------------
- SLIP_14
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP 14:
- Write a client server programs which displays the server machines date and time on the
- client machine.
- /* Server_Slip14_1*/
- import java.net.*;
- import java.io.*;
- import java.util.Date;
- public class Server_Slip14_1
- {
- public static void main(String g[])throws UnknownHostException, IOException
- {
- ServerSocket ss=new ServerSocket(4444);
- System.out.println("server started");
- Socket s=ss.accept();
- System.out.println("Client connected");
- Date d=new Date();
- int m=d.getMonth();
- m=m+1;
- int y=d.getYear();
- y=y+1900;
- String time=""+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+" Date is
- "+d.getDate()+"/"+m+"/"+y;
- OutputStream os=s.getOutputStream();
- DataOutputStream dos=new DataOutputStream(os);
- dos.writeUTF(time);
- }
- }
- /* client_Slip14_1*/
- import java.net.*;
- import java.io.*;
- importjava.util.*;
- public class Client_Slip14_1
- {
- public static void main(String args[]) throws Exception
- {
- Socket s = new Socket("localhost",4444);
- DataInputStream dos = new DataInputStream(s.getInputStream());
- String time = dos.readUTF();
- System.out.println("Current date and time is "+time);
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- Slip 14_2 : Write a JDBC program in java to display details of Book_Sales(SalesID, Date,
- Amount)
- *of selected month in JTable. Book_sales table is already created. (Use JCombo
- component for Month selection)
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.sql.*;
- class Slip14_2 extends JFrame implements ItemListener
- {
- JComboBox cb;
- String head[]={"SalesID","Date","Amount"};
- String as[][]=new String[10][10];
- Slip14_2()
- {
- setLayout(null);
- cb=new JComboBox();
- cb.setBounds(350,20,100,20);
- cb.addItem("JAN");
- cb.addItem("FEB");
- cb.addItem("MARCH");
- cb.addItem("APRIL");
- cb.addItem("MAY");
- cb.addItem("JUN");
- cb.addItem("JULY");
- cb.addItem("AUG");
- cb.addItem("SEP");
- cb.addItem("OCT");
- cb.addItem("NOV");
- cb.addItem("DEC");
- add(cb);
- cb.addItemListener(this);
- setSize(500,400);
- setVisible(true);
- }
- public void itemStateChanged(ItemEvent ie)
- {
- String str=cb.getSelectedItem().toString();
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection cn=DriverManager.getConnection("jdbc:odbc:dsn");
- Statement st=cn.createStatement();
- ResultSet rs=st.executeQuery("select * from BookSales where Date like '"+str+"%'");
- int i=0;
- while(rs.next())
- {
- as[i][0]=rs.getString("SalesID");
- as[i][1]=rs.getString("Date");
- as[i][2]=rs.getString("Amount");
- i++;
- }
- cn.close();
- JTable jt=new JTable(as,head);
- JScrollPane pane=new JScrollPane(jt);
- pane.setBounds(0,0,300,400);
- add(pane);
- }catch(Exception e)
- {
- System.out.println(e);
- }
- }
- public static void main(String args[])
- {
- new Slip14_2();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 14. Create student registration form and display details in the next page. (Use sticky form concept).
- Slip14.php
- <html>
- <body>
- <table border=1>
- <tr><thcolspan=2>
- <form action="<?php echo $_SERVER['PHP_SELF']?>" method=post>
- <tr><td>Enter Name</td><td><input type="text" name="nm" value="<?php if(isset($_POST['nm']))echo $_POST['nm']?>"</td></tr>
- <tr><td>Enter Roll No</td><td><input type="text" name="rno" value="<?php if(isset($_POST['rno']))echo $_POST['rno']?>"</td></tr>
- <tr><td>Enter State</td><td><input type="text" name="st" value="<?php if(isset($_POST['st']))echo $_POST['st']?>" </td></tr>
- <tr><td>Enter City</td><td><input type="text" name="ct" value="<?php if(isset($_POST['ct']))echo $_POST['ct']?>"</td></tr>
- <tr><td>Enter Percentage</td><td><input type="text" name="per" value="<?php if(isset($_POST['per']))echo $_POST['per']?>"</td></tr>
- <tr><td><input type="submit" value="Submit" name="submit"></td>
- <td><input type="reset" value="Reset"></td></tr>
- </form>
- </table>
- <?php
- if(isset($_POST['submit']))
- {
- $nm=$_POST['nm'];
- $rno=$_POST['rno'];
- $st=$_POST['st'];
- $ct=$_POST['ct'];
- $perc=$_POST['per'];
- }
- if((!empty($nm)) && (!empty($rno)) && (!empty($st)) && (!empty($ct)) && (!empty($perc)))
- {
- setcookie('nm',$nm);
- setcookie('rno',$rno);
- setcookie('st',$st);
- setcookie('ct',$ct);
- setcookie('perc',$perc);
- header("location:slip14_1.php");
- }
- ?>
- </body>
- </html>
- SLIP14_1.php
- <?php
- echo "Your name is $_COOKIE[nm] </br>";
- echo "Your Roll No Is : $_COOKIE[rno]</br>";
- echo "Your State Is : $_COOKIE[st]</br>";
- echo "Your City Is : $_COOKIE[ct]</br>";
- echo "Your Percentage Is : $_COOKIE[perc]</br>";
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 14. 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).
- Html file :
- <html>
- <head>
- <script type="text/javascript">
- function display(a_name)
- {
- // alert("hi");
- varob=false;
- ob=new XMLHttpRequest();
- ob.onreadystatechange=function()
- {
- if(ob.readyState==4 &&ob.status==200)
- document.getElementById("place").innerHTML=ob.responseText;
- }
- ob.open("GET","slip_14.php?a_name="+a_name,true);
- ob.send();
- }
- </script>
- </head>
- <body>
- Select Actor Name :
- <select name="a_name" onchange="display(this.value)">
- <option value="">select actor</option>
- <option value="Swapnil Joshi">Swapnil Joshi</option>
- <option value="Sachit">Sachit</option>
- </select>
- <div id="place"></div>
- </body>
- </html>
- Phpfile :
- <?php
- $a_name = $_GET['a_name'];
- $con = mysql_connect("localhost","root","");
- $d = mysql_select_db("bca_programs",$con);
- $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;
- echo "<table border=1>";
- echo "<tr><th>Movie No</th><th>Movie Name</th><th>Release Year</th></tr>";
- while($row = mysql_fetch_array($q))
- {
- echo "<tr>";
- echo "<td>".$row[0]."</td>";
- echo "<td>".$row[1]."</td>";
- echo "<td>".$row[2]."</td>";
- echo "</tr>";
- }
- echo "</table>";
- ?>
- ---------------------------------------------------------------------------------------------------------------------------------------
- SLIP_15
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP15: Write a JDBC program in java to update an address of given customer(cid,cname,address) and display updated details.
- import java.sql.*;
- import java.io.*;
- class Slip15_1
- {
- public static void main(String args[])throws Exception
- {
- Connection con;
- Statement stmt;
- PreparedStatement ps;
- String name;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed....");
- System.exit(1);
- }
- System.out.println("Connection Established...");
- stmt=con.createStatement();
- String query="Update Customer set address=? where name=?";
- ps=con.prepareStatement(query);
- DataInputStream di = new DataInputStream(System.in);
- System.out.println("Enter Customer name for Update:");
- name=di.readLine();
- System.out.println("Enter new Address:");
- String addr=di.readLine();
- ps.setString(1,addr);
- ps.setString(2,name);
- int no=ps.executeUpdate();
- if(no==0)
- {
- System.out.println("Not updated in table....");
- System.out.println("Name Not match"+name);
- }
- else
- {
- System.out.println("Succesfully updated in table....");
- ps=con.prepareStatement("select * from Customer where name=?");
- ps.setString(1,name);
- ResultSet rs=ps.executeQuery();
- System.out.println("cid\t"+"Name\t"+"address\t"+"ph_no");
- while(rs.next())
- {
- System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4));
- }
- }
- con.close();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX .HTML
- <html>
- <body>
- <form method="Post" action="http://localhost:8080/Stud">
- Enter Roll No :<input type="text" name="txtsno"><br><br>
- Enter Name :<input type="text" name="txtnm"><br><br>
- Enter class : <input type="text" name="txtclass"><br><br>
- Subject 1 : <input type="text" name="txtsub1"><br><br>
- Subject 2 :<input type="text" name="txtsub2"><br><br>
- Subject 3 : <input type="text" name="txtsub3"><br><br>
- <input type="submit" value="Result">
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http*;
- public class student extends HttpServlet
- {
- public void doPost(HttpServletResponse res, HttpServletRequest req)throws IOException
- {
- int sno,s1,s2,s3,total;
- String snm,sclass;
- float per;
- res.setContentType=("text/html");
- Printwriter out.res.getWriter();
- sno=Integer.parseInt(req.getParameter("txtsno"));
- s1=Integer.parseInt(req.getParameter("txtsub1"));
- s2=Integer.parseInt(req.getParamter("txtsub2"));
- s3=Integer.parseInt(req.getParameter("txtsub3"));
- snm=req.getParameter("txtnm");
- sclass=req.getParameter("txtsclass");
- total=s1+s2+s3;
- per=(total/3);
- out.println("<html><head>");
- out.println("<body>");
- out.println("<h2>Student Details...</h2>");
- out.println("<b>Student NO: "+sno+"<br>");
- out.println("<b>Student Name: "+snm+"<br>");
- out.println("<b>Student Class: "+sclass+"<br>");
- out.println("<b><i>Subject1:</b></i>"+s1+"<br>");
- out.println("<b><i>Subject2:</b></i>"+s2+"<br>");
- out.println("<b><i>Subject3:</b></i>"+s3+"<br>");
- out.println("<b><i>Total :</b></i>"+total+"<br>");
- out.println("<b><i>Percentage :</b></i>"+per+"<br>");
- if(per<50)
- out.println("<h1><i>Pass Class</i></h1>");
- else if(per<55 && per>50)
- out.println("<h1><i>Second class</i></h1>");
- else if(per<60 && per>=55)
- out.println("<h1><i>Higher class</i></h1>");
- out.close();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- HTML File
- <html>
- <form action=slip15.php method=post enctype=multipart/form-data>
- <input type=file name=file></br>
- <input type=submit value="Upload">
- </form>
- </html>
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- PHP File
- <?php
- echo "File name : ".$_FILES['file']['name']."</br>";
- echo "File Size: ".$_FILES['file']['size']."</br>";
- echo "File Name on Sever: ".$_FILES['file']['tmp_name']."</br>";
- echo "File Error: ".$_FILES['file']['error']."</br>";
- print_r($_FILES);
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 15. 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).
- Html file :
- <html>
- <head>
- <script type="text/javascript" >
- function m1(str)
- {
- varob=false;
- ob=new XMLHttpRequest();
- ob.open("GET","slip_15.php?q="+str);
- ob.send();
- ob.onreadystatechange=function()
- {
- if(ob.readyState==4 &&ob.status==200)
- {
- document.getElementById("a").innerHTML=ob.responseText;
- }
- }
- }
- </script>
- </head>
- <body>
- <form>
- Search<input type=text name=search size="20" onkeyup="m1(form.search.value)">
- <input type=button value="submit" onclick="m1(form.search.value)">
- </form>
- suggestions :<span id="a"></span><br>
- </body>
- </html>
- Phpfile :
- <?php
- $a=array("pune","satara","nashik","sangli","mumbai","murud","akola","dound","dhule","ratnagiri","rajpur");
- $q=$_GET['q'];
- if(strlen($q)>0)
- {
- $match="";
- for($i=0;$i<count($a);$i++)
- {
- if(strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
- {
- if($match=="")
- $match=$a[$i];
- else $match=$match.",".$a[$i];
- }
- }
- if($match=="")
- echo "No Suggestios";
- else echo $match;
- }
- ?>
- -------------------------------------------------------------------------------------------------------------
- SLIP_16
- import java.sql.*;
- import java.io.*;
- class slip15
- {
- public static void main(String args[])throws IOException
- {
- Connection con;
- Statement st;
- PrparedStatement ps;
- String name;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn16");
- if(con==null)
- {
- System.out.println("Connection faild...");
- System.exit(1);
- }
- System.out.println("Connection Established");
- st.CreateStatement();
- String query("Update customer set add=? where cname=? ");
- ps=con.prepareStatement(query);
- DataInputStreamReader di=new DataInputStreamReader(System.in);
- System.out.println("Enter Cutomer Name: ");
- name=di.readLine();
- System.out.println("Enter Address: ");
- string add=di.readLine();
- ps.setString(1,add);
- ps.setstring(2,name);
- int no=ps.executeUpdate();
- if(no==0)
- {
- System.out.println("records are not Updated...");
- System.out.println("Name is not matching...."+name);
- }
- else
- System.out.println("Records are added Successfully");
- ps=con.prepareStatement("select * from customer where name=? ");
- ps.setString(1,name);
- resultSet rs=ps.executeQuery();
- System.out.println("cid "+ "cname" + "add" + "phno");
- while(rs.next())
- {
- System.out.println("\n" rs.getInt(1)+ "\t" rs.getString(2)+ "\t" rs.getString(3)+ "\t" rs.getInt(4));
- }
- con.close();
- }
- catch(Exception(e))
- {
- System.out.println(e);
- }
- }
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP16 Q1. Write a JSP page, which accepts user name in a text box and greets the user according to the time on server machine.
- HTML:
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <body>
- <form action="Slip16.jsp" method="post">
- Enter Your Name : <input type="text" name="name"><br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- ,JSP
- JSP:
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- String name = request.getParameter("name");
- Calendar rightnow = Calendar.getInstance();
- int time = rightnow.get(Calendar.HOUR_OF_DAY);
- if(time > 0 && time <= 12)
- {
- out.println("Good Morning"+name);
- }
- else if(time >12 && time <=16)
- {
- out.println("Good Afternoon"+name);
- }
- else
- {
- out.println("Good Night"+name);
- }
- %>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- slip16 Q2
- class MyThread extends Thread
- {
- public MyThread(String s)
- {
- super(s);
- }
- public void run()
- {
- System.out.println(getName()+" thread created.");
- while(true)
- {
- System.out.println(this);
- int s = (int)(Math.random()*5000);
- System.out.println(getName()+" is sleeping for "+s+"msec");
- try{
- Thread.sleep(s);
- }catch(Exception e){}
- }
- }
- }
- class ThreadLifeCycle{
- public static void main(String args[]){
- MyThread t1 = new MyThread("harshada"),
- t2 = new MyThread("visave");
- t1.start();
- t2.start();
- try{
- t1.join();
- t2.join();
- }catch(Exception e){}
- System.out.println(t1.getName()+" thread dead.");
- System.out.println(t2.getName()+" thread dead.");
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- slip 16
- Q 3
- <?php
- echo"<table border=2>";
- foreach($_SERVER as $k=>$v)
- {
- echo"<tr><td>".$k."</td><td>".$v."</td></tr>";
- }
- echo"</table>";
- ?>
- -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-----------------------------------------------
- SLIP_17
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP17: 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.
- class Slip17_1
- {
- public static void main(String a[])
- {
- String S;
- int p;
- Thread t = Thread.currentThread();
- S = t.getName();
- System.out.println("\n Current Thread name : "+S);
- p = t.getPriority();
- System.out.println("\n Current thread priority : "+p);
- t.setName("My Thread");
- S = t.getName();
- System.out.println("\nChanged Name : "+S);
- t.setPriority(2);
- p = t.getPriority();
- System.out.println("\nChanged Priority : "+p);
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.sql.*;
- class DDLOperations extends JFrame{
- private JPanel panNorth,panSouth;
- private JLabel lblQuery;
- private JTextArea txtQuery;
- private JButton btnCreate,btnAlter,btnDrop;
- public DDLOperations(){
- lblQuery = new JLabel("Type DDL Query");
- txtQuery = new JTextArea(4,50);
- panNorth = new JPanel();
- panNorth.add(lblQuery);
- panNorth.add(new JScrollPane(txtQuery));
- btnCreate = new JButton("Create Table");
- btnAlter = new JButton("Alter Table");
- btnDrop = new JButton("Drop Table");
- panSouth = new JPanel();
- panSouth.add(btnCreate);
- panSouth.add(btnAlter);
- panSouth.add(btnDrop);
- setTitle("DDL Operations");
- setSize(400,300);
- add(panNorth,"North");
- add(panSouth,"South");
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- ButtonHandler bh = new ButtonHandler();
- btnCreate.addActionListener(bh);
- btnAlter.addActionListener(bh);
- btnDrop.addActionListener(bh);
- }
- class ButtonHandler implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
- String sql = txtQuery.getText();
- Statement s = con.createStatement();
- s.execute(sql);
- txtQuery.setText("");
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,e);
- }
- }
- }
- public static void main(String args[]){
- new DDLOperations();
- }
- }
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 17. 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.
- Html file :
- <html>
- <head>
- <title>login</title>
- </head>
- <body>
- <center>
- <form action="slip_16.php" method="post">
- <table>
- <tr><td><label>Email id :</label></td><td><input type=text name=emailid></td></tr>
- <tr><td><label >Password :</label></td><td><input type=password name=password></td></tr>
- <tr><td><input type=submit value="login & continue"></td><td></td></tr>
- </table>
- </form>
- </center>
- </body>
- </html>
- Phpfile :
- <?php
- $con=mysql_connect("localhost","root","") or die("I cannot connect"); //echo "connected successfuly";
- $d=mysql_select_db("bca_programs",$con);
- $q=mysql_query("select * from login");
- $emailid=$_REQUEST['emailid']; //echo $emailid;
- $password=$_REQUEST['password'];
- $n=0;
- while($row=mysql_fetch_array($q))
- {
- if($row[0]==$emailid&& $row[1]==$password)
- $n=1;
- }
- if($n==1)
- echo "<center><h3>WELCOME USER</h3><center>";
- else
- echo "<i>Emailid or Password Missmatch</i>";
- ?>
- ----------------------------------------------------------------------------------------------
- SLIP_18
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP18 : Write a java program using multithreading to execute the threads sequentially.(Use Synchronized Method)
- class PrintDemo
- {
- public void printCount()
- {
- try
- {
- for(int i = 5; i > 0; i--)
- {
- System.out.println("Counter --- " + i );
- }
- }
- catch (Exception e)
- {
- System.out.println("Thread interrupted.");
- }
- }
- }
- class ThreadDemo extends Thread
- {
- private Thread t;
- private String threadName;
- PrintDemo PD;
- ThreadDemo( String name, PrintDemo pd)
- {
- threadName = name;
- PD = pd;
- }
- public void run()
- {
- synchronized(PD)
- {
- PD.printCount();
- }
- System.out.println("Thread " + threadName + " exiting.");
- }
- public void start ()
- {
- System.out.println("Starting " + threadName );
- if (t == null)
- {
- t = new Thread (this, threadName);
- t.start ();
- }
- }
- }
- public class Slip18_1
- {
- public static void main(String a[])
- {
- PrintDemo PD = new PrintDemo();
- ThreadDemo T1 = new ThreadDemo( "Thread - 1 ", PD );
- ThreadDemo T2 = new ThreadDemo( "Thread - 2 ", PD );
- T1.start();
- T2.start();
- // wait for threads to end
- try
- {
- T1.join();
- T2.join();
- }
- catch( Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- mport java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.util.*;
- public class info_check extends HttpServlet
- {
- public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- try
- {
- res.setContentType("text/html");
- PrintWriter out = res.getWriter();
- out.println("<html>");
- out.println("<body>");
- java.util.Properties p=System.getProperties();
- out.println("Server Name :"+req.getServerName()+"<br>");
- out.println("Operating System Name :"+p.getProperty("Linux")+"<br>");
- out.println("IP Address :"+req.getRemoteAddr()+"<br>");
- out.println("Remote User:"+req.getRemoteUser()+"<br>");
- out.println("Remote Host:"+req.getRemoteHost()+"<br>");
- out.println("Local Name :"+req.getLocalName()+"<br>");
- out.println("Server Port:"+req.getServerPort()+"<br>");
- out.println("Servlet Name :"+this.getServletName()+"<br>");
- out.println("Protocol Name :"+req.getProtocol()+"<br>");
- out.println("</html>");
- out.println("</body>");
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 18. Create a XML file which gives details of books available in “ABC Bookstore” from following categories
- 1) Technical
- 2) Cookin
- 3) YOGA
- Xml file :
- <?xml version='1.0' ?>
- <ABC_Bookstore>
- <books category="technical">
- <book_no>1</book_no>
- <book_name>def</book_name>
- <author_name>xxx</author_name>
- <price>100</price>
- <year>1990</year>
- </books>
- <books category="Cooking">
- <book_no>2</book_no>
- <book_name>ccc</book_name>
- <author_name>aaa</author_name>
- <price>200</price>
- <year>1950</year>
- </books>
- <books category="YOGA">
- <book_no>3</book_no>
- <book_name>ddd</book_name>
- <author_name>zzz</author_name>
- <price>150</price>
- <year>2016</year>
- </books>
- </ABC_Bookstore>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 18. Write a PHP program to implement Create, Read, Update and Display operations on
- Teacher table with attributes(tid, tname,address, subject). (Use Radio Buttons).
- Html file :
- <slip_18.html>
- <html>
- <body>
- <form action="slip_18.php" method="get">
- <center><h2>Teacher Details :</h2><br>
- <table>
- <tr><td><input type=radio name=r value="1"></td><td><b>Create Teacher Table:</b></td></tr>
- <tr><td><input type=radio name=r value="2"></td><td><b> Insert Values :</b></td></tr>
- <tr><td><input type=radio name=r value="3"></td><td><b>Update Values :</b></td></tr>
- <tr><td><input type=radio name=r value="4"></td><td><b>Display :</b></td></tr>
- </table>
- <br><input type=submit value=Submit name=submit>
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- (slip_18.php)
- <?php
- $r=$_GET['r'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- if($r==1)
- {
- $q=mysql_query("create table teacher_slip_18(tidint,tnamevarchar(10),subjectvarchar(10),addressvarchar(20))");
- echo "<center><b><h2> Table Created Successfully.....!!!</h2><b></center>";
- }
- else if($r==2)
- {
- header("location:slip_18_insert.html");
- }
- else if($r==3)
- {
- header("location:slip_18update.html");
- }
- else if($r==4)
- {
- $q1=mysql_query("select *from teacher_slip_18");
- echo "<center>";
- echo "<table border=1 width=30% height=20%>";
- echo "<h2><tr><td><b>Teacher id </b></td>
- <td><b>Teacher Name<b></td>
- <td><b>Subject<b></td>
- <td><b>Address<b></td></tr></h2>";
- while($row=mysql_fetch_array($q1))
- {
- Echo"<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td></tr>";
- }
- echo "</table>";
- echo "</center>";
- }
- ?>
- <slip_18_insert.html>
- <html>
- <body>
- <form action="slip_18_insert.php" method="get">
- <center><h2>Enter Teacher Details :</h2><br>
- <table>
- <tr><td>Enter Teacher id :</td><td><input type=text name=tid></td></tr>
- <tr><td>Enter Teacher name :</td><td><input type=text name=tname></td></tr>
- <tr><td>Enter Subject :</td><td><input type=text name=subject></td></tr>
- <tr><td>Enter Address :</td><td><input type=text name=add></td></tr>
- <tr><td><input type=submit value=Show name=submit></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- (slip_18_insert.php)
- <?php
- $tid=$_GET['tid'];
- $tname=$_GET['tname'];
- $subjectt=$_GET['subject'];
- $add=$_GET['add'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- $q2=mysql_query("insert into teacher_slip_18 values($tid,'$tname',$subject,'$add')");
- echo "<center><b><h2> Values Inserted Successfully.....!!!</h2><b></center>";
- ?>
- (slip_18_update.html)
- <?php
- $edit=$_GET['edit'];
- $c=mysql_connect("localhost","root","");
- $d=mysql_select_db("bca_programs",$c);
- $q=mysql_query("select * from emp_slip_18");
- $row=mysql_fetch_array($q);
- ?>
- <html>
- <body>
- <form action="slip_18_update.php" method="get">
- <center><h2>Update teacher Details :</h2><br>
- <table>
- <tr><td> Teacher id :</td><td><input type=text name=tid value="<?php echo $row[0];?>"></td></tr>
- <tr><td> Teacher name :</td><td><input type=text name=tname value="<?php echo $row[1];?>"></td></tr>
- <tr><td> Subject :</td><td><input type=text name=subject value="<?php echo $row[3];?>"></td></tr>
- <tr><td> Address :</td><td><input type=text name=add value="<?php echo $row[4];?>"></td></tr>
- <tr><td><input type=submit value=Show name=submit></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- (slip_18_update1.php)
- <?php
- $a_no=$_GET['tid'];
- $a_name=$_GET['tname'];
- $a_sal=$_GET['subject'];
- $a_add=$_GET['add'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- $r=mysql_query("update teacher_slip_18 set tid=$tid,tname='$tname',subject='$subject',address='$add' where tid=$tid");
- ?>
- --------------------------------------------------------------------------------
- SLIP_19
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- JSP FILE:
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <body>
- <font color=red>
- <%! int i,n;
- String s1;
- %>
- <% s1=request.getParameter("num");
- n=s1.length();
- i=0;
- do
- {
- char ch=s1.charAt(i);
- switch(ch)
- {
- case '0': out.println("Zero ");break;
- case '1': out.println("One ");break;
- case '2': out.println("Two ");break;
- case '3': out.println("Three ");break;
- case '4': out.println("Four ");break;
- case '5': out.println("Five ");break;
- case '6': out.println("Six ");break;
- case '7': out.println("Seven ");break;
- case '8': out.println("Eight ");break;
- case '9': out.println("Nine ");break;
- }
- i++;
- }while(i<n);
- %>
- </font>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTML
- SLIP19: 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.
- HTML FILE :
- <!DOCTYPE html>
- <html>
- <body>
- <form method=get action="Slip19.jsp">
- Enter Any Number : <input type=text name=num><br><br>
- <input type=submit value="Display">
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.applet.Applet;
- import java.io.*;
- import java.awt.*;
- import java.util.*;
- /*
- <applet code="Smile.java" height=200 width=200>
- </applet>
- */
- public class Smile extends Applet implements Runnable
- {
- Thread t;
- int x=0;
- public void run()
- {
- repaint();
- }
- public void init()
- {
- Smile s1=new Smile();
- t=new Thread(s1);
- t.start();
- setSize(500,500);
- setBackground(Color.blue);
- }
- public void paint(Graphics g)
- {
- if(x==0)
- {
- g.drawOval(40,40,130,130);
- g.drawOval(57,75,20,20);
- g.drawOval(110,75,20,20);
- g.drawArc(60,110,80,40,180,180);
- x=1;
- }
- else if(x==1)
- {
- g.drawOval(40,40,130,130);
- g.drawOval(57,75,20,20);
- g.drawOval(110,75,20,20);
- g.drawArc(60,110,80,40,-180,-180);
- x=0;
- }
- try
- {
- Thread.sleep(2000);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- repaint();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 19. Write a PHP script to accept a string and then display each word of string in reverse order. (use concept of self processing form)
- php file :
- <html>
- <body>
- <form method=post action="<?php echo $_SERVER['PHP_SELF'] ?>">
- Enter String : <input type=text name=str1><br>
- <input type=submit name=submit>
- </form>
- <?php
- if(isset($_POST['submit']))
- {
- $str=$_POST['str1'];
- $str2=strrev($str);
- echo"<br>".$str2;
- }
- ?>
- </body>
- </html>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 19. Consider the following relational database:
- Project (P_Group_No, Project_Title)
- Student (Seat no, Name, Class, P_Group_No)
- Write a PHP script to accept project title and display list of students those who are
- working in a particular project.
- Html file :
- <html>
- <body>
- <form action="slip_19.php" method="get">
- <b>Enter the title of project :: </b><input type=text name=ptitle><br>
- <input type=submit value=SUBMIT>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $ptitle = $_GET['ptitle'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- $q =mysql_query("select s_name from student_slip19,project where project_title='$ptitle' && student_slip19.p_group_no=project.p_group_no");
- echo "Student Name :<br>";
- while($row = mysql_fetch_array($q))
- {
- echo $row['s_name'];
- }
- mysql_close();
- ?>
- ------------------------------------------------------------------------------------
- SLIP_20
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP 20: Write a JSP program to display the details of Hospital (HNo, HName, Address) in tabular form on browser
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html><body>
- <%@ page import="java.sql.*;" %>
- <%! int hno;
- String hname,address; %>
- <%
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection cn=DriverManager.getConnection("jdbc:odbc:hospital_data","","");
- Statement st=cn.createStatement();
- ResultSet rs=st.executeQuery("select * from Hospital");
- %>
- <table border="1" width="40%">
- <tr>
- <td>Hospital No</td>
- <td>Name</td>
- <td>Address</td>
- </tr>
- <% while(rs.next())
- {
- %>
- <tr> <td><%= rs.getInt("hno") %></td>
- <td><%= rs.getString("hname") %></td>
- <td><%= rs.getString("address") %></td>
- </tr>
- <%
- }
- cn.close();
- }catch(Exception e)
- {
- out.println(e);
- }
- %>
- </body></html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CLEINT
- client side:
- import java.io.*;
- import java.net.*;
- import java.awt.*;
- import java.awt.event.*;
- class ChatClient extends Frame{
- private TextArea taMsgs;
- private TextField txtMsg;
- private Button btnSend;
- private Panel panSouth;
- private MyThread t;
- private Socket s;
- private DataInputStream fromServer;
- private DataOutputStream toServer;
- public ChatClient(){
- taMsgs = new TextArea();
- txtMsg = new TextField(40);
- btnSend = new Button("Send");
- panSouth = new Panel();
- panSouth.add(txtMsg);
- panSouth.add(btnSend);
- setTitle("Client");
- setSize(300,400);
- setLocation(100,100);
- add(taMsgs,"Center");
- add(panSouth,"South");
- setVisible(true);
- addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent we){
- System.exit(0);
- }
- });
- try{
- s = new Socket("localhost",5060);
- fromServer = new DataInputStream(s.getInputStream());
- toServer = new DataOutputStream(s.getOutputStream());
- t = new MyThread();
- t.start();
- }
- catch(Exception e){
- System.out.println(e);
- System.exit(0);
- }
- btnSend.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- try{
- String str = txtMsg.getText();
- toServer.writeBytes(str+"\n");
- taMsgs.append("Me:"+str+"\n");
- txtMsg.setText("");
- txtMsg.requestFocus();
- }catch(Exception e){}
- }
- });
- }
- class MyThread extends Thread{
- public void run(){
- while(true){
- try{
- String str = fromServer.readLine();
- if(str!=null)
- taMsgs.append("You:"+str+"\n");
- }catch(Exception e){}
- }
- }
- }
- public static void main(String args[]){
- new ChatClient();
- }
- }
- Q2XXXXXXXXXXXXXXXXXXX SERVER
- server:
- import java.io.*;
- import java.net.*;
- import java.awt.*;
- import java.awt.event.*;
- class ChatServer extends Frame{
- private TextArea taMsgs;
- private TextField txtMsg;
- private Button btnSend;
- private Panel panSouth;
- private MyThread t;
- private Socket s;
- private ServerSocket ss;
- private DataInputStream fromClient;
- private DataOutputStream toClient;
- public ChatServer(){
- taMsgs = new TextArea();
- txtMsg = new TextField(40);
- btnSend = new Button("Send");
- panSouth = new Panel();
- panSouth.add(txtMsg);
- panSouth.add(btnSend);
- setTitle("Server");
- setSize(300,400);
- setLocation(100,100);
- add(taMsgs,"Center");
- add(panSouth,"South");
- setVisible(true);
- addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent we){
- System.exit(0);
- }
- });
- try{
- ss = new ServerSocket(5060);
- s = ss.accept();
- fromClient = new DataInputStream(s.getInputStream());
- toClient = new DataOutputStream(s.getOutputStream());
- t = new MyThread();
- t.start();
- }
- catch(Exception e){
- System.out.println(e);
- System.exit(0);
- }
- btnSend.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- try{
- String str = txtMsg.getText();
- toClient.writeBytes(str+"\n");
- taMsgs.append("Me:"+str+"\n");
- txtMsg.setText("");
- txtMsg.requestFocus();
- }catch(Exception e){}
- }
- });
- }
- class MyThread extends Thread{
- public void run(){
- while(true){
- try{
- String str = fromClient.readLine();
- if(str!=null)
- taMsgs.append("You:"+str+"\n");
- }catch(Exception e){}
- }
- }
- }
- public static void main(String args[]){
- new ChatServer();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 20. Write PHP program to select list of subjects (use multivalued parameter) displays on next page.
- HTML File
- <html>
- <head><title>Slip20
- </title>
- </head>
- <form action=slip20.php method=get>
- Select List of subjects
- <select multiple name="subjects[]">
- <option value="VB.NET">Vb.NET</option>
- <option value="PHP">PHP</option>
- <option value="JAVA">JAVA</option>
- </select>
- <input type=submit value="submit">
- </form>
- </html>
- PHP File
- <?php
- echo "You selected subjects are";
- echo "</br>";
- foreach($_GET['subjects'] as $s)
- {
- echo "$s</br>";
- }
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 20. Consider the following entities and their relationships
- Emp (emp_no,emp_name,address,phone,salary)
- Dept (dept_no,dept_name,location)
- Emp-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
- a) Insert employee records in table .
- b) Print a salary statement in the format given below, for a given department. (Accept department name from the user).
- Html file :
- <html>
- <body>
- <form action="slip_20.php" method="get">
- <center><h2>Fill Employee Details : </h2>
- <table>
- <tr><td>Enter Employee No :</td><td><input type=text name=e_no></td></tr>
- <tr><td>Enter Employee Name :</td><td><input type=text name=e_nm></td></tr>
- <tr><td>Enter Address :</td><td><input type=text name=add></td></tr>
- <tr><td>Enter Phone :</td><td><input type=text name=ph></td></tr>
- <tr><td>Enter Salary :</td><td><input type=text name=sal></td></tr>
- <tr><td>Enter Department no :</td><td><input type=text name=d_no></td></tr>
- <tr><td>Enter Department name :</td><td><input type=text name=d_nm></td></tr>
- <tr><td>Enter Location :</td><td><input type=text name=loc></td></tr>
- <tr><td></td><td><input type=submit value=OK></td></tr>
- </table>
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $e_no = $_GET['e_no'];
- $e_name = $_GET['e_nm'];
- $add = $_GET['add'];
- $ph = $_GET['ph'];
- $sal = $_GET['sal'];
- $d_no = $_GET['d_no'];
- $d_nm = $_GET['d_nm'];
- $loc = $_GET['loc'];
- $con = mysql_connect("localhost","root","");
- $d = mysql_select_db("bca_programs",$con);
- $q = mysql_query("insert into emp values($e_no,'$e_name','$add',$ph,$sal)");
- $q1 = mysql_query("insert into dept values($d_no,'$d_nm','$loc',$e_no)");
- $q2 = mysql_query("select MIN(salary),MAX(salary),SUM(salary) from emp,dept where emp.emp_no=dept.emp_no");
- echo "<tr><td>Minimum salary----</td><td>Maximum salary----</td><td>Sum of Salary</td></tr>";
- while($row = mysql_fetch_array($q2))
- {
- echo "<tr><td>".MIN(salary)."</td><td>".MAX(salary)."</td><td>".SUM(salary)."</td></tr>";
- }
- mysql_close();
- ?>
- _--------------------------------------------------------------------------------------------
- SLIP_21
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP21: Write a JDBC Program in java to display the names of Employees starting with ‘S’
- character
- import java.sql.*;
- class Slip21_1
- {
- public static void main(String args[])
- { Connection con;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:dsn");
- if(con==null)
- {
- System.out.println("Connection Failed....");
- System.exit(1);
- }
- System.out.println("Connection Established...");
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * from employee where name like 'S%'");
- System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
- while(rs.next())
- {
- System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));
- }
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- HTMLXXXXXXXXXXXXXXX
- <html>
- <body>
- <form method="GET" action="http://localhost:8080/choice">
- select your hobbie:<br>
- <input type="radio" name="ch" value="painting">PAINTING<br>
- <input type="radio" name="ch" value="drawing">DRAWING<br>
- <input type="radio" name="ch" value="swiming">SWIMING<br>
- <input type="radio" name="ch" value="singing">SINGING<br>
- <br><input type="submit" value="select">
- <br><input type="reset">
- </form>
- </body>
- </html>
- JAVA XXXXXXXXXX
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class Setb21 extends HttpServlet
- {
- public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- PrintWriter out = null;
- try
- {
- out=res.getWriter();
- String hb=req.getParameter("ch");
- Cookie c1=new Cookie("hobby",hb);
- out.println("hobby are:"+hb);
- //res.addCookie(c1);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Q22 XXX
- setb2n.java
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class setb2n extends HttpServlet
- {
- public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- PrintWriter out = null;
- try
- {
- out=res.getWriter();
- Cookie c[]=req.getCookies();
- for(int i=0;i<c.length;i++)
- {
- String s1=c[i].getName();
- out.println("selected hobby are :"+s1);
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <form acion="<?php echo $_SERVER['PHP_SELF']?>" method="post">
- string1: <input type="text" name=txt1 value="<?php if(isset($_POST['txt1'])) echo $_POST['txt1'];?>">
- string2: <input type="text" name=txt2> value="<?php if(isset($_POST['txt2'])) echo $_POST['txt2'];?>">
- <input type=submit value="submit">
- </form>
- <?php
- $s1=$_POST['txt1'];
- $s2=$_POST['txt2'];
- if(strcomp($s1,$s2)==0)
- echo "Strings are mathcing";
- else
- echo "Strings are not matching";
- ?>
- </body>
- </html>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 21. Consider the following entities and their relationships
- Doctor (doc_no, doc_name, address, city, area)
- Hospital (hosp_no, hosp_name, hosp_city)
- Doctor and Hospital are related with many-many relationship
- Create a RDB in 3 NF for the above and solve following
- Using above database, write a PHP script which accepts hospital name and print information about doctors visiting / working in that hospital in tabular format.
- Html file :
- <html>
- <body>
- <form action="slip_21.php" method="get">
- Enter the Name Of Hospital : <input type=text name=hosp><br>
- <input type=submit value=SUBMIT>
- </form>
- </body>
- <html>
- Phpfile :
- <?php
- $hosp=$_GET['hosp'];
- $con=mysql_connect("localhost","root","");
- $d=mysql_select_db("bca_programs",$con);
- $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");
- echo "<tr><td>Doctor no--</td><td>Doctor Name--</td><td>Address--</td><td>city--</td><td>Area</td></tr>";
- while($row=mysql_fetch_array($q))
- {
- echo "<br><tr><td>".$row[0]." | </td><td>".$row[1]." | </td><td>".$row[2]." | </td><td>".$row[3]." |</td><td>".$row[4]." |</td></tr>";
- }
- mysql_close();
- ?>
- ---------------------------------------------------------------------------------
- SLIP_22
- CLIENT
- //client.java
- import java.net.*;
- import java.io.*;
- public class client
- {
- public static void main(String args[])
- {
- try
- {
- Socket s = new Socket("localhost",2222);
- InputStream is=s.getInputStream();
- InputStreamReader isr= new InputStreamReader(is);
- BufferedReader br=new BufferedReader(isr);
- OutputStream os=s.getOutputStream();
- PrintWriter pw= new PrintWriter(os,true);
- String msg="5";
- pw.println(msg);
- msg=br.readLine();
- int gh=Integer.parseInt(msg) ;
- System.out.println("factorial="+gh);
- s.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- SERVER XXXXXXXXX
- //server.java
- import java.net.*;
- import java.io.*;
- public class server
- {
- public static void main(String args[])
- {
- try
- {
- ServerSocket ss =new ServerSocket(2222);
- System.out.println("Server is started");
- while(true)
- {
- Socket s=ss.accept();
- System.out.print("Connection request Received");
- InputStream is=s.getInputStream();
- InputStreamReader isr= new InputStreamReader(is);
- BufferedReader br=new BufferedReader(isr);
- OutputStream os=s.getOutputStream();
- PrintWriter pw= new PrintWriter(os,true);
- String no= br.readLine();
- //System.out.print("no:"+ " " + (char)no);
- int no1=Integer.parseInt(no);
- int fact=1,i=0;
- while(no1>i)
- {
- fact=fact*no1;
- no1--;
- //System.out.println("fact="+fact+"no="+no1);
- }
- pw.println(fact);
- s.close();
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.sql.*;
- import java.io.*;
- import javax.sql.*;
- class slip6
- {
- public static void main(String args[])
- {
- Connection con;
- Statement state;
- ResultSet rs;
- int ch;
- boolean flag=true;
- String decision;
- int no;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection("jdbc:odbc:lab.dsn");
- System.out.println("Statement object created");
- do
- {
- System.out.println("\n");
- System.out.println("Menu:");
- System.out.println("1.create Table");
- System.out.println("2.Insert Record into the Table");
- System.out.println("3.Display all the Records from the Table");
- System.out.println("4.Exit");
- System.out.println("Enter your choice: ");
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- ch=Integer.parseInt(br.readLine());
- switch(ch)
- {
- case 1:
- state=con.createStatement();
- String query="create table student"+"(rno int ,"+" sname varchar(20),"+" per int,"+" address varchar(20))";
- state.executeUpdate(query);
- System.out.println("Table created");
- case 2:
- System.out.println("Enter student Number: ");
- int rno=Integer.parseInt(br.readLine());
- System.out.println("Enter student Name: ");
- String sname=br.readLine();
- System.out.println("Enter per: ");
- int per=Integer.parseInt(br.readLine());
- System.out.println("Enter address: ");
- String address=br.readLine();
- String sql="insert into student values(?,?,?,?)";
- PreparedStatement p=con.prepareStatement(sql);
- p.setInt(1,rno);
- p.setString(2,sname);
- p.setInt(3,per);
- p.setString(4,address);
- p.executeUpdate();
- System.out.println("Record Added");
- break;
- case 3:
- state=con.createStatement();
- sql="select * from student";
- rs=state.executeQuery(sql);
- while(rs.next())
- {
- System.out.println("\n");
- System.out.print("\t" +rs.getInt(1));
- System.out.print("\t" +rs.getString(2));
- System.out.print("\t" +rs.getInt(3));
- System.out.print("\t" +rs.getString(4));
- }
- break;
- case 4:
- System.exit(0);
- default:
- System.out.println("Invalid Choice");
- break;
- }
- }while(ch!=4);
- }catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 22.Write a script to keep track of number of times the web page has been accessed.(Use $_SESSION[])
- Html file :
- <html>
- <head>
- <title> Number of times the web page has been viited.</title>
- </head>
- <body>
- <?php
- session_start();
- if(isset($_SESSION['count']))
- $_SESSION['count']=$_SESSION['count']+1;
- else
- $_SESSION['count']=1;
- echo "<h3>This page is accessed</h3>".$_SESSION['count'];
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 22. Consider the following entities and their relationships
- Movie (movie_no, movie_name, release_year)
- Actor (actor_no, name)
- Relationship 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
- following: (Hint: Create HTML form having two radio buttons)
- a) Accept actor name and display the names of the movies in which he has acted.
- b) Insert new movie information
- html file :
- <html>
- <body>
- <form action="slip_22.php" method="get">
- <h3>Enter Actor Name : <input type=text name=nm></h3>
- <input type=radio name=a value=1>Display Movie Name<br><br>
- <h3>Enter movie no :<input type=text name=m_no></h3>
- <h3>Enter movie name :<input type=text name=m_nm></h3>
- <h3>Enter release year :<input type=text name=r_yr></h3>
- <h3>Enter actor no :<input type=text name=a_no></h3>
- <h3>Enter actor name :<input type=text name=a_nm></h3>
- <input type=radio name=a value=2>Insert New movie info<br><br>
- <input type=submit value=OK>
- </form>
- <div id="place"></div>
- </body>
- </html>
- php file :
- <?php
- $r = $_GET['a'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- if($r == 1)
- {
- $actor_name = $_GET['nm'];
- $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'");
- echo "<br>Movie Name </br>";
- while($row=mysql_fetch_array($q))
- {
- echo $row[0]."<br>";
- }
- }
- else if($r == 2)
- {
- $m_no = $_GET['m_no'];
- $m_name = $_GET['m_nm'];
- $r_yr = $_GET['r_yr'];
- $a_no = $_GET['a_no'];
- $a_name = $_GET['a_nm'];
- $q =mysql_query("insert into movie values($m_no,'$m_name',$r_yr)");
- $q1 =mysql_query("insert into actor values($a_no,'$a_name')");
- echo "Value Inserted";
- }
- mysql_close();
- ?>
- ------------------------------------------------------------------------------------------------------------
- SLIP_23
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <%
- int rno = Integer.parseInt(request.getParameter("rno"));
- String s_name = request.getParameter("name");
- String s_gender = request.getParameter("gender");
- String s_know = request.getParameter("know");
- String s_class = request.getParameter("Class");
- out.println("\nRoll No :"+rno);
- out.println("\nName :"+s_name);
- out.println("\nGender :"+s_gender);
- out.println("\nComp_Know :"+s_know);
- out.println("\nClass :"+s_class);
- %>
- HTMLZXXXXXXXXXXXXXXXXXXXXXXXXX
- SLIP23 : 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.
- HTML FILE:
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <h1>Enter Information</h1>
- <form action="Slip23.jsp" method="post">
- Roll No : <input type="text" name="rno"><br><br>
- Name : <input type="text" name="name"><br><br>
- Gender : <input type="radio" name="gender" value="Male" checked>Male
- <input type="radio" name="gender" value="Female">Female
- <br><br>
- Comp_Know : <input type="radio" name="know" value="Yes" checked>Yes
- <input type="radio" name="know" value="No">No
- <br><br>
- Class :
- <select name="Class">
- <option value="11">11Th</option>
- <option value="12">12Th</option>
- <option value="FY">FY</option>
- <option value="SY">SY</option>
- <option value="TY">TY</option>
- </select>
- <br><br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.sql.*;
- import java.io.*;
- import javax.sql.*;
- class Elements{
- public static void main(String args[]){
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
- Statement s=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- char ch = args[0].charAt(0);
- String name="",symbol="";
- int weight=0;
- switch(ch)
- {
- case 'R':
- s = con.createStatement();
- rs = s.executeQuery("select * from elements");
- while(rs.next()){
- System.out.println(rs.getInt(1)+"\t"+
- rs.getString(2)+"\t"+
- rs.getString(3));
- }
- break;
- case 'D':
- name = args[1];
- ps = con.prepareStatement("delete from elements where name=?");
- ps.setString(1,name);
- if(ps.executeUpdate()==1)
- System.out.println("Element "+name+" deleted successfully.");
- else
- System.out.println("Element "+name+" not found.");
- break;
- case 'U':
- weight = Integer.parseInt(args[1]);
- name = args[2];
- symbol = args[3];
- ps = con.prepareStatement("update elements set atomic_weight=?,chemical_symbol=? where name=?");
- ps.setInt(1,weight);
- ps.setString(2,symbol);
- ps.setString(3,name);
- if(ps.executeUpdate()==1)
- System.out.println("Element "+name+" updated successfully.");
- else
- System.out.println("Element "+name+" not found.");
- }
- con.close();
- }
- catch(Exception e){
- System.out.println(e);
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 23. Write a PHP script to generate an XML in the following format
- HTML file
- <html>
- <head>
- <title>Create XML</title>
- </head>
- <form action=slip23.php method=get>
- Enter Book Title<input type=text name=txtTitle></br>
- Enter Publication<input type=text name=publ></br>
- <input type=submit value="submit">
- </form>
- </html>
- PHP File
- <?php
- echo "Links data posted";
- $ele=$_GET['txtTitle'];
- $att=$_GET['publ'];
- $xmltags="<?xml version=1.0?>";
- $xmltags=$xmltags."<Bookstore>";
- $xmltags=$xmltags."<Books>";
- $xmltags=$xmltags."<PHP>";
- $xmltags=$xmltags."<title>";
- $xmltags=$xmltags.$ele;
- $xmltags=$xmltags."</title>";
- $xmltags=$xmltags."<publication>";
- $xmltags=$xmltags.$att;
- $xmltags=$xmltags."</attrib>";
- $xmltags=$xmltags."</PHP>";
- $xmltags=$xmltags."</Books>";
- $xmltags=$xmltags."</Bookstore>";
- if($fp=fopen("books.xml","w"))
- {
- if($wt=fwrite($fp,$xmltags))
- {
- echo "File created";
- }
- else
- echo "Not write";
- }
- else
- echo "Not opened";
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 23. Consider the following entities and their relationships
- BillMaster(billno, custname, billdate )
- BillDetails(itemname, qty, rate, discount)
- BillMaster and BillDetails are related with one-to-many relationship.
- Create a RDB in 3 NF for the above and solve following
- Write PHP script to print the bill in following format Accept the Bill number from user.
- Html file :
- <html>
- <body>
- <form action="slip_23.php" method="get">
- <center><h3>Enter the Bill Number : <input type=text name=bno><br></h3>
- <input type=submit value=SUBMIT></center>
- </form>
- </body>
- <html>
- Phpfile :
- <?php
- $bno = $_GET['bno'];
- $con =mysql_connect("localhost","root","");
- $d =mysql_select_db("bca_programs",$con);
- $q =mysql_query("select * from bill_master where bill_no=$bno");
- echo "<center>";
- while($row = mysql_fetch_array($q))
- {
- echo "<h3><br>Bill No : ".$row[0]." Bill Date : ".$row[2]."</h3>";
- echo "<h3>Customer Name : ".$row[1]."</h3>";
- }
- $i=1;
- $gt=0;
- $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");
- echo "<table border=1 width=30% height=10%>";
- echo "<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>";
- while($row1=mysql_fetch_array($q1))
- {
- $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>";
- $gt+=$t;
- }
- echo "</table>";
- echo "<br><b> Gross Ammount is :: ".$gt."</b>";
- echo "<center>";
- mysql_close();
- ?>
- ------------------------------------------------------------------------------
- SLIP_24
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <%@ page language="java" %>
- <%
- String email=request.getParameter("t1");
- if(email.contains("@") && email.contains("."))
- {
- out.println("Given Email Id is Valid");
- }
- else
- {
- out.println("Given Email id is not Valid");
- }
- %>
- </body>
- </html>
- XXXXXXXXXXXXXXXXXX HTML
- <html>
- <body>
- <form name=f1 action="EmailCheck.jsp">
- <fieldset>
- <legend>Enter Email Id...!!!</legend>
- Enter Email Id:<input type="text" name="t1" >
- </fieldset>
- <div align=center>
- <input type="submit" name="Submit" value="Submit">
- </div>
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class College extends JFrame
- {
- private JLabel lblID,lblName,lblAddr,lblYear;
- private JTextField txtID,txtName,txtAddr,txtYear;
- private JButton btnSave,btnClose;
- private JPanel panCenter,panSouth;
- private Connection con;
- private PreparedStatement ps;
- public College()
- {
- lblID = new JLabel("College ID:");
- lblName = new JLabel("College Name:");
- lblAddr = new JLabel("Address:");
- lblYear = new JLabel("Year:");
- txtID = new JTextField();
- txtName = new JTextField();
- txtAddr = new JTextField();
- txtYear = new JTextField();
- panCenter = new JPanel();
- panCenter.setLayout(new GridLayout(4,2));
- panCenter.add(lblID);
- panCenter.add(txtID);
- panCenter.add(lblName);
- panCenter.add(txtName);
- panCenter.add(lblAddr);
- panCenter.add(txtAddr);
- panCenter.add(lblYear);
- panCenter.add(txtYear);
- btnSave = new JButton("Save");
- btnClose = new JButton("Close");
- panSouth = new JPanel();
- panSouth.add(btnSave);
- panSouth.add(btnClose);
- setTitle("College Information");
- setSize(400,200);
- setLocation(100,100);
- add(panCenter,"Center");
- add(panSouth,"South");
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null,e);
- dispose();
- }
- btnSave.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- try{
- int cid = Integer.parseInt(txtID.getText());
- String cname = txtName.getText();
- String addr = txtAddr.getText();
- int yr = Integer.parseInt(txtYear.getText());
- ps = con.prepareStatement("insert into college values(?,?,?,?)");
- ps.setInt(1,cid);
- ps.setString(2,cname);
- ps.setString(3,addr);
- ps.setInt(4,yr);
- ps.executeUpdate();
- txtID.setText("");
- txtName.setText("");
- txtAddr.setText("");
- txtYear.setText("");
- txtID.requestFocus();
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,e);
- }
- }
- });
- btnClose.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- dispose();
- }
- });
- }
- public static void main(String args[]){
- new College();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 24. Write a simple PHP program which implements Ajax for addition of two numbers
- Html file :
- <html>
- <head>
- <script type="text/javascript">
- function Addition()
- {
- var ob=false;
- ob=new XMLHttpRequest();
- var no1=document.getElementById("no1").value;
- var no2=document.getElementById("no2").value;
- ob.open("GET","Que25.php?num1="+no1+"&num2="+no2);
- ob.send();
- ob.onreadystatechange=function()
- {
- if(ob.readyState==4 &&ob.status==200)
- document.getElementById("add").innerHTML=ob.responseText; }
- }
- </script>
- </head>
- <body>
- Enter first no :<input type=text name=no1 id="no1"><br>
- Enter second no :<input type=text name=no2 id="no2"><br>
- <input type=button name=submit value=add onClick="Addition()"><br>
- <span id="add"></span>
- <body>
- </html>
- PhpFile :
- <?php
- $n1=$_GET['num1'];
- $n2=$_GET['num2'];
- if((!empty($n1)) && (!empty($n2)))
- {
- $add=$n1+$n2;
- echo "Addition = ".$add;
- }
- else "enter both nos";
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 24. Create an application that reads “Book.xml” file into simple XML object. Display attributes
- and elements(Hint: use simple_xml_load_file() function)
- XML file :
- <?xml version='1.0' encoding ='UTF-8' ?>
- <bookstore>
- <books category="technical">
- <book_no>1</book_no>
- <book_name>def</book_name>
- <author_name>xxx</author_name>
- <price>100</price>
- <year>1990</year>
- </books>
- <books category="Cooking">
- <book_no>2</book_no>
- <book_name>ccc</book_name>
- <author_name>aaa</author_name>
- <price>200</price>
- <year>1950</year>
- </books>
- <books category="YOGA">
- <book_no>3</book_no>
- <book_name>ddd</book_name>
- <author_name>zzz</author_name>
- <price>150</price>
- <year>2016</year>
- </books>
- </bookstore>
- Phpfile :
- <?php
- $xml=simplexml_load_file("slip_24.xml") or die("eror:cannot create object");
- var_dump($xml);
- ?>
- ----------------------------------------------------------------------------------------------------
- SLIP_25
- Q1XXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <%!
- int cnt=0;
- String uname,nname;
- %>
- <%
- uname=request.getParameter("uname");
- nname=request.getParameter("nname");
- cnt++;
- if(cnt%2==0)
- out.println("Hello "+nname+"......... Visit Count "+cnt);
- else
- out.println("Hello "+uname+"......... Visit Count "+cnt);
- %>
- <br><br>
- <a href="visitpage.html">VISIT</a>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXXXX HTML
- <html>
- <body>
- <form method=get action="visitpage.jsp">
- Enter User Name : <input type=text name=uname><br><br>
- Enter Nick Name : <input type=text name=nname><br><br>
- <input type=submit value="visit">
- </form>
- <body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.io.*;
- import java.sql.*;
- public class slip6
- {
- public static void main(String args[])
- {
- try
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- Connection con=null;
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection("jdbc:odbc:lab");
- Statement sta=con.createStatement();
- sta=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
- ResultSet rs=sta.executeQuery("select * from employee");
- for(;;)
- {
- System.out.println("---------MAIN MENU---------");
- System.out.println("1:Next");
- System.out.println("2:First");
- System.out.println("3:Previous");
- System.out.println("4:Last");
- System.out.println("5:Exit");
- System.out.println("ENTER your choice :");
- int choice=Integer.parseInt(br.readLine());
- switch(choice)
- {
- case 1:
- System.out.println("Display next record");
- rs.next();
- System.out.println(" eNo:"+rs.getInt(1));
- System.out.println("eName:"+rs.getString(2));
- System.out.println("sal:"+rs.getFloat(3));
- break;
- case 2:
- System.out.println("Display first record");
- rs.first();
- System.out.println("eNo:"+rs.getInt(1));
- System.out.println("eName:"+rs.getString(2));
- System.out.println("sal:"+rs.getFloat(3));
- break;
- case 3:
- System.out.println("Display previous record");
- rs.previous();
- System.out.println("eNo:"+rs.getInt(1));
- System.out.println("eName:"+rs.getString(2));
- System.out.println("sal:"+rs.getFloat(3));
- break;
- case 4:
- System.out.println("Display last record");
- rs.last();
- System.out.println("eNo:"+rs.getInt(1));
- System.out.println("eName:"+rs.getString(2));
- System.out.println("sal:"+rs.getFloat(3));
- break;
- case 5:
- System.exit(0);
- break;
- }
- }
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 25. Write PHP script to demonstrate the concept of introspection for examining object.
- <?php
- class intro
- {
- var $i;
- function f1() {}
- function f2() {}
- }
- class intro_1 extends intro
- {
- var $j,$k;
- function f3() {}
- function f4() {}
- }
- $ob=new intro_1();
- if(is_object($ob)) //returns boolean value true if an object ob is created
- {
- echoget_class($ob); //returns class name of given object
- }
- if(method_exists($ob,'f4')) //returns tru if the method f4 exists for the object ob
- {
- echo "method f4 exists";
- }
- var_dump(get_object_vars($ob)); //retuns an array of parameter / variables for given object
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 25. Create a XML file which gives details of books available in “ABC Bookstore” from
- following categories.
- 1) Technical 2) Cooking 3) Yoga
- and elements in each category are in the following format
- --------------
- --------------
- ---------------
- Save 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)
- XML file :
- <?xml version='1.0' encoding ='UTF-8' ?>
- <bookstore>
- <books category="technical">
- <book_no>1</book_no>
- <book_name>def</book_name>
- <author_name>xxx</author_name>
- <price>100</price>
- <year>1990</year>
- </books>
- <books category="Cooking">
- <book_no>2</book_no>
- <book_name>ccc</book_name>
- <author_name>aaa</author_name>
- <price>200</price>
- <year>1950</year>
- </books>
- <books category="YOGA">
- <book_no>3</book_no>
- <book_name>ddd</book_name>
- <author_name>zzz</author_name>
- <price>150</price>
- <year>2016</year>
- </books>
- </bookstore>
- Phpfile :
- <?php
- $xml=simplexml_load_file("slip_24.xml") or die("eror:cannot create object");
- var_dump($xml);
- ?>
- --------------------------------------------------------------------------------------
- SLIP_26
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.io.*;
- import java.util.*;
- class slip26 implements Runnable
- {
- Thread t;
- public slip26()
- {
- t=new Thread(this);
- t.start();
- }
- public void run()
- {
- char ch;
- for (ch='a';ch<='z';ch++)
- {
- System.out.println(ch);
- try
- {
- Thread.sleep(300);
- }
- catch(Exception e)
- {
- }
- }
- }
- public static void main(String args[])
- {
- slip26 s=new slip26();
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import java.sql.*;
- import java.util.*;
- import java.text.*;
- class SalesReport extends JFrame{
- private JLabel lblStart,lblEnd;
- private JComboBox cmbStart,cmbEnd;
- private JPanel panNorth;
- private JButton btnShow;
- private JTable tabReport;
- private DefaultTableModel dtm;
- public SalesReport(){
- lblStart = new JLabel("Start Date:");
- lblEnd = new JLabel("End Date:");
- cmbStart = new JComboBox();
- cmbEnd = new JComboBox();
- Calendar calendar = new GregorianCalendar();
- java.util.Date d = new java.util.Date();
- System.out.println(d.getDate());
- calendar.set(Calendar.YEAR, d.getYear()+1900);
- calendar.set(Calendar.MONTH, d.getMonth());
- calendar.set(Calendar.DAY_OF_MONTH, d.getDate());
- for(int i=1000;i>=1;i--){
- String str = calendar.get(Calendar.YEAR)+"-"+
- (calendar.get(Calendar.MONTH)+1)+"-"+
- calendar.get(Calendar.DAY_OF_MONTH);
- cmbStart.addItem(str);
- cmbEnd.addItem(str);
- calendar.add(Calendar.DAY_OF_MONTH, -1);
- }
- btnShow = new JButton("Show");
- panNorth = new JPanel(new GridLayout(1,4));
- panNorth.add(lblStart);
- panNorth.add(cmbStart);
- panNorth.add(lblEnd);
- panNorth.add(cmbEnd);
- panNorth.add(btnShow);
- dtm = new DefaultTableModel();
- dtm.addColumn("PID");
- dtm.addColumn("PName");
- dtm.addColumn("Amount");
- dtm.addColumn("Date");
- tabReport = new JTable(dtm);
- setTitle("Sales Report");
- setSize(400,400);
- add(panNorth,"North");
- add(new JScrollPane(tabReport),"Center");
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- btnShow.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- try{
- for(int i=0;i<dtm.getRowCount();i++)
- dtm.removeRow(0);
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
- String sdate = cmbStart.getSelectedItem().toString();
- String edate = cmbEnd.getSelectedItem().toString();
- java.util.Date d = sdf.parse(sdate);
- java.sql.Date newsdate = new java.sql.Date(d.getTime());
- d = sdf.parse(edate);
- java.sql.Date newedate = new java.sql.Date(d.getTime());
- PreparedStatement ps = con.prepareStatement("select * from prod_sales where sale_date between ? and ?");
- ps.setDate(1,newsdate);
- ps.setDate(2,newedate);
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- Vector v = new Vector();
- v.add(rs.getString(1));
- v.add(rs.getString(2));
- v.add(rs.getString(3));
- v.add(rs.getString(4));
- dtm.addRow(v);
- }
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,e);
- }
- }
- });
- }
- public static void main(String args[]){
- new SalesReport();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 26. 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
- html file :
- <html>
- <body>
- <form action=Que26.php method=GET>
- enter student roll no :<input type=text name=rno><br>
- enter student name : <input type=text name=s_name><br>
- enter class : <input type=text name=cls><br>
- <input type=submit name=submit value=submit >
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- <?php
- $rno=$_GET['rno'];
- $s_name=$_GET['s_name'];
- $cls=$_GET['cls'];
- $con=mysql_connect("localhost","root","");
- $d=mysql_select_db("bca_programs",$con);
- $q=mysql_query("insert into stud values($rno,'$s_name','$cls')");
- $q1=mysql_query("select * from stud order by sname");
- echo "<table>";
- echo "<tr><td>Roll no.</td><td>Name</td><td>Class</td></tr>";
- while($row=mysql_fetch_array($q1))
- {
- echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
- }
- echo "</table>";
- mysql_close();
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 26. Write a script to solve following questions (Use “Book.xml” file)
- a) Create a DOM Document object and load this XML file.
- b) Get the output of this Document to the browser
- c) Save this [. XML] document in another format i.e. in [.doc]
- d) Write a XML program to print the names of the books available in “Book.xml” file.
- XML file :
- Same as Q.24
- Phpfile :
- <?php
- $doc=new DOMDocument();
- $doc->load("slip_18.xml");
- $name=$doc->getElementsByTagName("book_name");
- echo "Books Names";
- foreach($name as $val)
- {
- echo "<br>".$val->textContent;
- }
- ?>
- ------------------------------------------------------------------------------------------------
- SLIP_27
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.io.*;
- import java.sql.*;
- class Empdisplay
- {
- static Connection cn;
- static Statement st;
- static ResultSet rs;
- static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- public static void main(String args[])
- {
- int e,k,ch,sal;
- String en;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- cn=DriverManager.getConnection("jdbc:odbc:Emp","","");
- st=cn.createStatement();
- System.out.println("1. Display ");
- System.out.println("Enter Your Choice");
- ch=Integer.parseInt(br.readLine());
- rs=st.executeQuery ("select * from emp where Ename like 'S%'");
- while(rs.next())
- {
- System.out.println(rs.getInt("eno") + "\t" +rs.getString("ename")+"\t"+rs.getInt("sal"));
- }
- }
- catch(Exception et)
- {
- System.out.println(et);
- }
- }
- }
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- Slip27_2.java
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.*;
- class MyThread extends Thread
- {
- JTextField tf;
- MyThread(JTextField tf)
- {
- this.tf = tf;
- }
- public void run()
- {
- while(true)
- {
- Date d = new Date();
- int h = d.getHours();
- int m = d.getMinutes();
- int s = d.getSeconds();
- tf.setText(h+":"+m+":"+s);
- try
- {
- Thread.sleep(300);
- }
- NR CLASSES, PUNE (8796064387/90)
- catch(Exception e){}
- }
- }
- }
- class Slip27_2 extends JFrame implements ActionListener
- {
- JTextField txtTime;
- JButton btnStart,btnStop;
- MyThread t;
- Slip27_2()
- {
- txtTime = new JTextField(20);
- btnStart = new JButton("Start");
- btnStop = new JButton("Stop");
- setTitle("Stop Watch");
- setLayout(new FlowLayout());
- setSize(300,100);
- add(txtTime);
- add(btnStart);
- add(btnStop);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- btnStart.addActionListener(this);
- btnStop.addActionListener(this);
- t = new MyThread(txtTime);
- }
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==btnStart)
- {
- if(!t.isAlive()) t.start();
- else t.resume();
- }
- if(ae.getSource()==btnStop)
- {
- t.suspend();
- }
- }
- public static void main(String a[])
- {
- new Slip27_2();
- }
- }
- Q2XXXXXXXXXXXXXXX
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- public class slip27 extends Frame implements ActionListener,Runnable
- {
- Button start,stop;
- TextField tf;
- int x=0,y=0;
- String msg="";
- Thread t1=new Thread(this);
- public slip27()
- {
- setLayout(new FlowLayout());
- tf=new TextField();
- start=new Button("start");
- stop=new Button("stop");
- add(tf);
- add(start);
- add(stop);
- start.addActionListener(this);
- stop.addActionListener(this);
- /** addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- });*/
- setSize(200,200);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent ae)
- {
- Button btn=(Button)ae.getSource();
- if(btn==start)
- {
- t1.start();
- }
- if(btn==stop)
- {
- t1.stop();
- }
- }
- public void run()
- {
- try
- {
- while(true)
- {
- repaint();
- Thread.sleep(350);
- }
- }
- catch(Exception e){ }
- }
- public void paint(Graphics g)
- {
- int sec,min,hr;
- GregorianCalendar date = new GregorianCalendar();
- sec = date.get(Calendar.SECOND);
- min = date.get(Calendar.MINUTE);
- hr = date.get(Calendar.HOUR);
- msg = hr+":"+min+":"+sec;
- tf.setText(msg);
- }
- public static void main(String args[])
- {
- new slip27();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 27. Write an Ajax program to display list of games stored in an array on clicking OK button.
- Html file :
- <html>
- <head>
- <script>
- function dis()
- {
- varob=false;
- ob=new XMLHttpRequest();
- vargm=document.getElementById("gm").value;
- ob.open("GET","slip27.php?game="+gm);
- ob.send();
- ob.onreadystatechange=function()
- { if(ob.readyState==4 &&ob.status==200)
- {
- document.getElementById("game").innerHTML=ob.responseText;
- }
- }
- Phpfile :
- }
- </script>
- </head>
- <body>
- <h2>Display the list of Games<input type=button name=submit value=OK id="gm" onClick="dis()"></h2>
- <span id="game"></span>
- </body>
- </html>
- Phpfile :
- <?php
- $gm=$_GET['game'];
- $a=array("Hockey","Football","Cricket","Basket Ball","Kho-Kho","Tennis","Dough Ball");
- echo "<h3>List of Games<br></h3>";
- for($i=0;$i<count($a);$i++)
- {
- echo $a[$i]."<br>";
- }
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 27 .Write a script to create “cricket.xml” file with multiple elements as shown below:
- <CricketTeam>
- <Team country=”India”>
- <player>____</player>
- <runs>______</runs>
- <wicket>____</wicket>
- </Team>
- </CricketTeam>
- Write a script to add multiple elements in “cricket.xml” file of category, country=”Australia”.
- XML file :
- <?xml version='1.0' encoding='UTF-8' ?>
- <CricketTeam>
- <Team country='India'>
- <player>Mahi</player>
- <runs>100</runs>
- <wicket>4</wicket>
- </Team>
- <Team country='Austrelia'>
- <player>smith</player>
- <runs>10</runs>
- <wicket>1</wicket>
- </Team>
- </CricketTeam>
- --------------------------------------------------------------------------------
- SLIP_28
- Q1XXXXXXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <%! int n,m,sum=0,rem; %>
- <% n=Integer.parseInt(request.getParameter("t1"));
- m=n;
- while(n>0)
- {
- rem=n%10;
- sum=sum+(rem*rem*rem);
- n=n/10;
- }
- if(sum==m)
- out.print("the no. is armstrong "+sum);
- else
- out.print("the no. is not armstrong "+sum);
- %>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXXXX HTML
- <html>
- <body>
- <form method=post action="Armstrong.jsp">
- Enter Number : <input type=text name=t1><br>
- <input type=submit>
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import java.util.*;
- import java.sql.*;
- class slip28 extends JFrame
- {
- private JTable tabRecord;
- private JLabel lblEmp;
- private JComboBox cmbEmp;
- private JPanel panNorth;
- private DefaultTableModel dtm;
- private Connection con;
- private PreparedStatement ps;
- private Statement s;
- private ResultSet rs;
- public slip28()
- {
- lblEmp = new JLabel("Employee:");
- cmbEmp = new JComboBox();
- panNorth = new JPanel();
- panNorth.add(lblEmp);
- panNorth.add(cmbEmp);
- dtm = new DefaultTableModel();
- dtm.addColumn("EmpNo");
- dtm.addColumn("Name");
- dtm.addColumn("Salary");
- //dtm.addColumn("Designation");
- tabRecord = new JTable(dtm);
- setTitle("View Employee");
- setSize(500,150);
- add(panNorth,"North");
- add(new JScrollPane(tabRecord),"Center");
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
- s = con.createStatement();
- rs = s.executeQuery("select * from emp");
- cmbEmp.addItem("---");
- while(rs.next()){
- cmbEmp.addItem(rs.getString(2));
- }
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null,e);
- }
- cmbEmp.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent ie)
- {
- try
- {
- String name = cmbEmp.getSelectedItem().toString();
- ps = con.prepareStatement("select * from emp where name=?");
- ps.setString(1,);
- rs = ps.executeQuery();
- if(rs.next())
- {
- Vector rec = new Vector();
- rec.add(rs.getString(1));
- rec.add(rs.getString(2));
- rec.add(rs.getString(3));
- // rec.add(rs.getString(4));
- if(dtm.getRowCount()>0)
- dtm.removeRow(0);
- dtm.addRow(rec);
- }
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null,e);
- }
- }
- });
- }
- public static void main(String args[])
- {
- new slip28();
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 28. 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.
- Html file :
- <html>
- <body>
- <form action="slip_28_Q3-1.php" method="get">
- <center>
- <b>Select font style :</b><input type=text name=s1><br>
- <b>Enter font size : </b><input type=text name=s><br>
- <b>Enter font color : </b><input type=text name=c><br>
- <b>Enter background color :</b><input type=text name=b><br>
- <input type=submit value="Next">
- </center>
- </form>
- </body>
- </html>
- Phpfile :
- slip_28_1.php
- <?php
- echo "style is ".$_GET['s1']."<br>color is ".$_GET['c']."<br>Background color is ".$_GET['b']."<br>size is ".$_GET['s'];
- setcookie("set1",$_GET['s1'],time()+3600);
- setcookie("set2",$_GET['c'],time()+3600);
- setcookie("set3",$_GET['b'],time()+3600);
- setcookie("set4",$_GET['s'],time()+3600);
- ?>
- <html>
- <body>
- <form action="slip28_2.php">
- <input type=submit value=OK>
- </form>
- </body>
- </html>
- php file :
- slip28_2.php
- <?php
- $style=$_COOKIE['set1'];
- $color=$_COOKIE['set2'];
- $size=$_COOKIE['set4'];
- $b_color=$_COOKIE['set3'];
- $msg="NR Classes";
- echo "<body bgcolor=$b_color>";
- echo "<font color=$color size=$size>$msg";
- echo "</font></body>";
- ?>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 28. Write a PHP script to accept an .XML file which should comprise the following:
- <cricket>
- <player>abc</player>
- <runs>1000</runs>
- <wickets>50</wickets>
- <noofnotout>10</noofnotout>
- </cricket>
- For at least 5 players.
- Display the details of players who have scored more than 1000 runs and at least 50 wickets.
- XML file :
- <?xml version='1.0' encoding='UTF-8'?>
- <cricketinfo>
- <cricket>
- <player>abc</player>
- <runs>1000</runs>
- <wickets>50</wickets>
- <noofnotout>10</noofnotout>
- </cricket>
- <cricket>
- <player>def</player>
- <runs>100</runs>
- <wickets>40</wickets>
- <noofnotout>10</noofnotout>
- </cricket>
- <cricket>
- <player>pqr</player>
- <runs>1020</runs>
- <wickets>60</wickets>
- <noofnotout>10</noofnotout>
- </cricket>
- <cricket>
- <player>xyz</player>
- <runs>9000</runs>
- <wickets>90</wickets>
- <noofnotout>40</noofnotout>
- </cricket>
- <cricket>
- <player>lmn</player>
- <runs>170</runs>
- <wickets>80</wickets>
- <noofnotout>8</noofnotout>
- </cricket>
- </cricketinfo>
- Phpfile :
- <?php
- $d=new DOMDocument();
- $d->load("slip_29.xml");
- $run=$d->getElementsByTagName('runs');
- $wic=$d->getElementsByTagName('wickets');
- $name=$d->getElementsByTagName('player');
- foreach($name as $n)
- {
- if($run=='1000' && $wic>='50')
- echo "<br>".$n->textContent;
- else "not";
- }
- ?>
- ---------------------------------------------------------------------------------------------------
- SLIP_29
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <%! int n; %>
- <% n=Integer.parseInt(request.getParameter("t1"));
- if(n>=18)
- out.print("You are eligible for voting....!");
- else
- out.print("You are not eligible for voting....!");
- %>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXX HTML
- <html>
- <body>
- <form method=post action="Voter.jsp">
- Enter Your Age : <input type=text name=t1><br>
- <br>
- <input type=submit>
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.sql.*;
- import java.io.*;
- class slip29
- {
- public static void main(String args[])
- {
- Connection con;
- Statement state;
- ResultSet rs;
- int ch,k;
- boolean flag=true;
- String decision;
- int rno;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection("jdbc:odbc:dsn");
- System.out.println("Statement object created");
- do
- {
- System.out.println("\n");
- System.out.println("Menu:");
- System.out.println("1.Insert Record into the Table");
- System.out.println("2.Update The Existing Record.");
- System.out.println("3.Display all the Records from the Table");
- System.out.println("4.Delete Record into the Table");
- System.out.println("5.Search The Existing Record.");
- System.out.println("6.Exit");
- System.out.println("Enter your choice: ");
- DataInputStream br=new DataInputStream(System.in);
- // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- ch=Integer.parseInt(br.readLine());
- switch(ch)
- {
- case 1:
- System.out.println("Enter Student Number: ");
- rno=Integer.parseInt(br.readLine());
- System.out.println("Enter Student Name: ");
- String name=br.readLine();
- System.out.println("Enter Percentage: ");
- int per=Integer.parseInt(br.readLine());
- String sql="insert into Student values(?,?,?)";
- PreparedStatement p=con.prepareStatement(sql);
- p.setInt(1,rno);
- p.setString(2,name);
- p.setInt(3,per);
- p.executeUpdate();
- System.out.println("Record Added");
- break;
- case 2:
- state=con.createStatement();
- System.out.println("Enter the rno");
- rno=Integer.parseInt(br.readLine());
- System.out.println("Enter the per");
- per=Integer.parseInt(br.readLine());
- String ss="update Student set Student.per="+per+" where(((Student.[rno])="+rno+"))";
- k=state.executeUpdate(ss);
- System.out.println(ss);
- if(k>0)
- {
- System.out.println("Record Is Updated");
- }
- break;
- case 3:
- state=con.createStatement();
- sql="select * from Student";
- rs=state.executeQuery(sql);
- while(rs.next())
- {
- System.out.println("\n");
- System.out.print("\t" +rs.getInt(1));
- System.out.print("\t" +rs.getString(2));
- System.out.print("\t" +rs.getInt(3));
- }
- break;
- case 4:
- state =con.createStatement();
- while(flag)
- {
- System.out.println("Enter Student Number for the record you wish to Delete: ");
- rno=Integer.parseInt(br.readLine());
- sql="delete from Student where rno="+rno;
- System.out.println(sql);
- int rows=state.executeUpdate(sql);
- System.out.println(rows+"rows sucessfully Deleted");
- System.out.println("Do u want to Delete more data:y/n:");
- decision=br.readLine().toLowerCase();
- if(decision.charAt(0)=='n')
- flag=false;
- }
- break;
- case 5:
- state=con.createStatement();
- System.out.println("enter roll no u want to search");
- rno=Integer.parseInt(br.readLine());
- sql="select * from Student where rno="+rno;
- rs=state.executeQuery(sql);
- System.out.println("success");
- while(rs.next())
- {
- System.out.println("RollNo="+rs.getInt(1)+""+"name="+rs.getString(2)+" "+"per="+rs.getInt(3));
- }
- break;
- case 6:
- System.exit(0);
- default:
- System.out.println("Invalid Choice");
- break;
- }//switch
- }while(ch!=6);
- }catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Q3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 29.Write a script to create XML file named “Course.xml” ....... ...... ..... Store the details of 5 students who are in TYBCA.
- <?xml version='1.0' encoding='UTF-8' ?>
- <Course>
- <ComputerScience>
- <Studentname>resh</Studentname>
- <Classname>ty</Classname>
- <percentage>60</percentage>
- </ComputerScience>
- <ComputerScience>
- <Studentname>tej</Studentname>
- <Classname>ty</Classname>
- <percentage>55</percentage>
- </ComputerScience>
- <ComputerScience>
- <Studentname>praj</Studentname>
- <Classname>sy</Classname>
- <percentage>55</percentage>
- </ComputerScience>
- <ComputerScience>
- <Studentname>pooja</Studentname>
- <Classname>fy</Classname>
- <percentage>78</percentage>
- </ComputerScience>
- <ComputerScience>
- <Studentname>sweety</Studentname>
- <Classname>LKG</Classname>
- <percentage>50</percentage>
- </ComputerScience>
- <ComputerScience>
- <Studentname>akshada</Studentname>
- <Classname>fy</Classname>
- <percentage>79</percentage>
- </ComputerScience>
- </Course>
- Q4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- 29. Write a PHP script using AJAX concept, to check user name and password are valid or
- Invalid (use database to store user name and password).
- Html file :
- <html>
- <head>
- <script type="text/javascript">
- function validate()
- {
- uname=document.getElementById('uname').value;
- pwd=document.getElementById('pwd').value;
- }
- </script>
- </head>
- <body>
- <form action="slip_29-1.php" method=get>
- Enter UserName<input type=text name=uname id=uname><span id=a></span><br>
- Enter Password<input type=password name=pwd id=pwd><br>
- <input type=SUBMIT value=SUBMIT onClick=validate()>
- </form>
- </body>
- </html>
- Phpfile :
- <?php
- $uname=$_GET['uname'];
- $password=$_GET['pwd'];
- $con=mysql_connect("localhost","root","") or die("I cannot connect");
- $d=mysql_select_db("bca_programs",$con);
- $q=mysql_query("select * from login");
- $n=0;
- while($row=mysql_fetch_array($q))
- {
- if($row[0]==$uname&& $row[1]==$password)
- $n=1;
- }
- if($n==0)
- echo "invalid username or password";
- ?>
- ------------------------------------------------------------------------------------
- SLIP_30
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- <html>
- <body>
- <%! int n,cnt,i,j; %>
- <% n=Integer.parseInt(request.getParameter("t1"));
- for(i=1;i<=n;i++)
- {
- cnt=0;
- for(j=2;j<i;j++)
- {
- if(i%j==0)
- {
- cnt++;
- }
- }
- if(cnt==0)
- {
- %><br><font color=blue size=5>
- <%
- out.println(" "+i);
- }
- }
- %>
- </body>
- </html>
- Q1XXXXXXXXXXXXXXXXXXXXXXXXXXXX HTML
- <html>
- <body>
- <form method=post action="prime.jsp">
- Enter Limit : <input type=text name=t1><br>
- <input type=submit>
- </form>
- </body>
- </html>
- Q2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.sql.*;
- public class slip30 extends HttpServlet
- {
- private Connection con;
- private Statement s;
- private ResultSet rs;
- public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
- {
- res.setContentType("text/html");
- PrintWriter out = res.getWriter();
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection("jdbc:odbc:dsn");
- s = con.createStatement();
- rs = s.executeQuery("select * from product");
- out.print("<table border=1 bgcolor='yellow'>"+"<tr bgcolor='red'>"+"<th>Code</th><th>Name</th><th>Price</th></tr>");
- while(rs.next())
- {
- out.print("<tr>"+"<td>"+rs.getInt(1)+"</td>"+"<td>"+rs.getString(2)+"</td>"+"<td>"+rs.getFloat(3)+"</td>"+"</tr>");
- }
- out.print("</table>");
- }
- catch(Exception e){out.print(e);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement