Saturday, 1 September 2012

Discuss the significances of JDBC.


The significances are given below:

• JDBC is the acronym stands for Java Database Connectivity.

• Java Database Connectivity (JDBC) is a standard Java API .

• It's purpose is to interact with the relational databases in Java. 

• JDBC is having a set of classes & interfaces which can be used from any Java application. 

• By using the Database Specific JDBC drivers, it interacts with a database without the applications of RDBMS.

How to send data one jsp page to another jsp page


Index.jsp


<%--
    Document   : index
    Created on : 21 Aug, 2012, 11:53:21 PM
    Author     : Himanshu
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
           <form action="sucess.jsp" method="get">
              Name :  <input type="text" name="name"><br>
            Age :  <input type="text" name="age"><br>
             Dob :   <input type="text" name="dob"><br>
                <input type="submit">

            </form>

        </table>
    </body>
</html>

sucess.jsp
<%--
    Document   : sucess
    Created on : 22 Aug, 2012, 12:35:55 AM
    Author     : Himanshu
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% String name=request.getParameter("name");%>
        <h1>Name : <%=name%></h1>
         <% String age=request.getParameter("age");%>
        <h1>Name : <%=age%></h1>
         <% String dob=request.getParameter("dob");%>
        <h1>Name : <%=dob%></h1>

    </body>
</html>

for loop in jsp



<%--
    Document   : index
    Created on : 21 Aug, 2012, 11:53:21 PM
    Author     : himanshu
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%for(int i=0;i<10;i++){%>
        <h4><%=i+"->"%>Hello World!</h4>
        <%}%>
       
    </body>
</html>

Prime Numbers java program


Prime Numbers
Output
prime numbers are:
2
3
5
7
11

 Source code
Prime.java

package com.swain.cell;

public class Prime {
      
        public static void main(String args[])
          {
             int n, status = 1, num = 3;
               n=5;
             if ( n >= 1 )
             {
                System.out.println("prime numbers are: ");
                System.out.println(2);
             }
        
             for ( int count = 2 ; count <=n ;  )
             {
                for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
                {
                   if ( num%j == 0 )
                   {
                      status = 0;
                      break;
                   }
                }
                if ( status != 0 )
                {
                   System.out.println(num);
                   count++;
                }
                status = 1;
                num++;
             }        
          }

}



Factorial java program


Factorial
Output
Factorial of 5 is = 120
Source code
Factorial.java

package com.swain.cell;

public class Factorial {
      
       public static void main(String args[])
          {
             int n, c, fact = 1;
        
             n=5;
             if ( n < 0 )
                System.out.println("Number should be non-negative.");
             else
             {
                for ( c = 1 ; c <= n ; c++ )
                   fact = fact*c;
        
                System.out.println("Factorial of "+n+" is = "+fact);
             }
          }

}

String Palindrome java program


Output
Himanshu is not a palindrome.
Source code
StringPalindrome.java

package com.swain.cell;

public class StringPalindrome {
       public static void main(String args[])
          {
             String original="Himanshu";
             String rev="";
                      
             int length = original.length();
        
             for ( int i = length - 1 ; i >= 0 ; i-- )
                rev = rev + original.charAt(i);
        
             if (original.equals(rev))
                System.out.println(original+" is a palindrome.");
             else
                System.out.println(original+" is not a palindrome.");
        
          }
}


Palindrome java program


Palindrome
Output
Number is palindrome!

Source code
Palindrome.java

package com.swain.cell;

public class Palindrome {

       public static void main(String [] args){
                try{
               
                int num= 161;
                int n = num;
                int rev=0;
                for (int i=0; i<=num; i++){
                int r=num%10;
                num=num/10;
                rev=rev*10+r;
                i=0;
                }
                 if(n == rev){
                System.out.print("Number is palindrome!");
                }
                else{
                System.out.println("Number is not palindrome!");
                }
                }
                catch(Exception e){
                System.out.println("Error");
                }
                }
}