Wednesday, 24 January 2018

Advancedjava-Slip25



Slip25
Q1. Write a JSP script to accept UserName and his NickName through html page and then displays username when visit count to page is odd and displays nickname when the visit count to the page is even.  


nickname.html

<html>
<body>
<form action="nickname.jsp" method="get">
username: <input type="text" name="uname" />
<br>
Nickname: <input type="text" name="nname" />
<br>
<input type="submit" />
</form>
</body>
<html>


nickname.jsp
<%@ page language="java" %>
<html>
<body>
<%!int a=1;%>
<%String uname=request.getParameter("uname"); %>
<%String nname=request.getParameter("nname"); %>
<%if(a%2==0){%>
<%="Welcome "+nname %>
<%}else{%>
<%="Welcome "+uname %>
<%}
out.println("The Visit is "+a);
a++;
%>
</body>
</html>

 
                                                                                                           
Q2. Write a JDBC program for implementation of scrollable ResultSet. Consider Emp table (eno ename, sal)
-          moveFirst
-          moveNext
-          movePrevious
moveLast      



 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.dsn");

                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);
                       }
              }
             }