Posts

Showing posts from March, 2019

Login page in jsp in only one jsp page

Prerequisite ------------------------------------ 1)) Import the ojdbc6.jar /ojdbc14.jar filr to the project by using build path-library-add external jar for database connectivity. 2))Optional--May be some external jar like jsp.api be required index.jsp ============================================================= <%@ page language="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1" import="java.sql.*;"%> <!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=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String n=request.getParameter("name"); String p=request.getParameter("pass"); if(n==null || p==null) { %> <form action="inde...

Go back to previous page in jsp/servlet

Try the following  ways ----------------------------------------------------------------------------------------------------------------->>>>> <button type="button" name="back" onclick="history.back()">back</button> <a href="index.jsp">Back</a> <button type="button"      name="back"      onclick='window.location='<your_path>/index.jsp'>back</button> -------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>> previous.jsp ............................ <form method="post" action="Student"> <input type="hidden" name="back" value="previous.jsp" /> <input type="text" name="studentname"/> <input type="submit" value="search"/> </f...

Session tracking in J2EE

In java we can do session tracking in the following way. ..................................................................... 1)Cookies 2)Hidden Form Field 3)URL Rewriting 4)HttpSession Cookies ================================== There are 2 types of cookies in java servlets. 1) Non-persistent cookie 2) Persistent cookie Non-persistent cookie -------------------------------- It is valid for single session only. It is removed each time when user closes the browser. Persistent cookie --------------------------------- It is valid for multiple session . It is not removed each time when user closes the  browser. It is removed only if user logout or signout. Cookies ---------------------------------------- creating the cookies .................................... Cookie ck=new Cookie("user","sandeep_mishra");   //creating cookie  object response.addCookie(ck);    //adding cookie in the response delet...

Sorry username or password error (#Database record is not saved

---------------------------------------------------------------------------- index.html ---------------------------------------------------------------------------- <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> <form action="FirstServlet" method="post">   Name:<input type="text" name="username"/><br/><br/>   Password:<input type="password" name="userpass"/><br/><br/>   <input type="submit" value="login"/>   </form>  </head> </html> ------------------------------------------------ FirstServlet.java ------------------------------------------------ import java.io.*; import javax.servlet.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public c...

Tomcat Errors in J2EE

Image
Error -------------------------------- java.net.BindException: Address already in use: JVM_Bind solution ======================= i had the above error in tomcat .So i changed the port address and its resolved for now. By default the 3 ports in tomcat is 1.Tomcat admin port    8080 2.HTTP/1.1                  9090 3.AJP/1.3                    8080 Now I have changed the ports as follows 8013 9091 8011 now its working fine. Steps to change the ports------------------- 1)Go to server and then double click on                                                        apache tomcat 2)Then the tomcat page will open and you can change your port 1.Go to server....double click on apache tomcat (Follow the below picture) ...

Array Of Object In Java Script

<html> <body> <script> var n=prompt("Enter the number of employees"); var sample = new Array(); //Input the objects into the array for(var i=0;i<n;i++) { var name=prompt("Enter the name of "+(i+1)+" Employee"); var designation=prompt("Enter the Designation of "+(i+1)+" Employee"); var salary=prompt("Enter the Salary of "+(i+1)+" Employee"); //Enter values into each object var employee={name:name,designation:designation,salary:salary}; //insert each object into the array sample.push(employee); } //Print the element of object array for(var j=0;j<n;j++) { document.write(sample[j].name+" "); document.write(sample[j].designation+" "); document.write(sample[j].salary+" "); document.write("<br>"); } </script> </body> </html> #javascript #arrayofobject

Passing array to function java script

<html> <body> <script> //Input the size and values of array var a=[]; var size=prompt("Enter the size of the array"); for(var i=0;i<size;i++) { a[i]=prompt("Enter the "+(i+1)+" th element of array"); } //function call var s=sumNumber(a); document.write(s); //called function body function sumNumber(a){ //var a=[]; var sum=0; for(var i=0;i<a.length;i++) { sum=Number(sum)+Number(a[i]); } return sum; } </script> </body> </html>

PL/SQL Trigger

create table employee (id number,name varchar2(20),designation varchar2(20),salary number); create table employee_history (id number,name varchar2(20),designation varchar2(20),salary number); creating trigger ====================================================================  create or replace trigger employee_history         before insert or update or delete on employee         for each row         begin         if inserting then        dbms_output.put_line('record inserting');         end if;       if deleting then         insert into employee_history values(:old.id,:old.name,:old.designation,:old.salary);       end if;       if updating then       dbms_output.put_line('updating');       end if;     end;    / by above code ...

PL/SQL userdefined Exception

    declare     cid number;     cname varchar2(20);     cdes varchar2(20);     csal number;     notZero exception;     begin     cid:=&number;     if(cid<=0)       then    raise notZero;    end if;    cname:='&cname';    cdes:='&cdes';    csal:=&csal;    insert into employee values(cid,cname,cdes,csal);    exception    when notZero then    dbms_output.put_line('id cant be zero');    when others then    dbms_output.put_line('Check the code again');    end;    /

PL/SQL function

Find the second max salary from employee ======================================================== create function second_max1 return number is b number(10); begin select max(salary) into b from employee where salary!=(select max(salary) from employee); return b; end; / declare b number(10); begin b:=second_max1; dbms_output.put_line(b); end; / Find the number of words in a Sentence =============================================== --the function body create or replace function wordcount(n in varchar2) return number as l number; i number; begin l:=1; for i in 1..length(n) loop if(substr(n,i,1)=' ') then l:=l+1; end if; end loop; return l; end; / --calling the function declare n varchar2(20); c number; begin n:='&n'; c:=wordcount(n); dbms_output.put_line(c); end; /

query writing using PL/SQL procedure

Employee table ===================================================== create table employee(id number(10),name varchar2(20),designation varchar2(20),salary number(10)); 1))) Selecting second max salary from employee -------------------------------------------------------------------- proc e dure:- ----------------------------------------------------------- create procedure second_highest1(b out varchar2)    is    begin    select max(salary) into b from employee where salary!=(Select               max(salary) from employee);    end;    / P rogram To C all The P rocedure:- -------------------------------------------- declare b varchar2(20); begin second_highest1(b); dbms_output.put_line(b); end; / set serveroutput on;

Cursors in PL/SQL

Cursors in PL/SQL ---------------------------------------------------------- Normally when we use functions and procedures in PL/SQL we return a single value. Normally when we use pl/SQL program, functions, procedures we deal with single row output. When we required multiple records cursor comes into the picture. Cursor return records one by one to the user. #-------------------------------------------------------------------------- 4 parts are there of the cursor. 1)declare cursor 2)open cursor 3)fetch records 4)close cursor #cursor in plsql

Number programs using plsql procedure and function

1)Print the prime number upto certain number in plsql ============================================= procedure --------------------------- create procedure reverNum(a in number) is i number; j number; k number; flag number:=0; begin for i in 2..a loop k:=i-1; for j in 2..k loop if(mod(i,j)=0) then flag:=1;             end if; end loop; if(flag=0) then dbms_output.put_line(i||' '); end if; flag:=0; end loop; end; / calling the procedure --------------------------------------------------- declare a number; begin a:='&a'; reverNum(a); end; / 2))Print the fibonacci series upto certain number using pl/sql procedure ==================================================================== procedure-------------------- create procedure fibonaci(a in number) is x number:=0; y number:=1; test number:=0; begin dbms_output.put_line(x||' '); dbms_output.p...

create a new user in oracle

Create a new user in oracle ============================================== 1.Login to the oracle with password using command sql> conn username/password; After login type the following command  =============================================== sql> create user new_user_name identified by  password; sql>create user sandeep identified by mishra; here sandeep is my new user and mishra is the password after creation of user the message will be displayed "User created". Grant DBA permission to newly created user =================================================== if you want the new user to grant the DBA then type the below command sql> grant dba to user_name; ex> sql>grant dba to sandeep; #create new user in oracle #grant dba to user in oracle

PL/SQL Procedure

1-->create a table ------------------------------------------------------------------------------------------------ create table employee(name varchar2(20),sal number(10),exp number(5)); 2-->create a procedure to insert element into the employee table ------------------------------------------------------------------------------------------------- create or replace procedure insert_value(a in varchar2,b in number,e in number) is begin insert into employee values(a,b,e); end; / 3-->call the procedure to insert the records into your table ------------------------------------------------------------------------------------------------------- declare  a varchar2(10); b number(10); e number(10); begin a:='&a'; b:='&b'; e:='&e'; insert_value(a,b,e); end; / Now after insertion, check once records are inserted or not -------------------------------------------------------------------------- select * from employee; ...

PL/SQL sum of 2 numbers

Image
program --------------------------------------------------------------------------------------------- declare a number:=10; b number:=20; c number; begin c:=a+b; dbms_output.put_line('Sum is' ||c); end; / Run in sql developer::----------------                                                (Click on the photo to zoom in) if  it is showing procedure is created but not showing any output,run the following commands -------------------------------------------------------------------------- set serveroutput on; Then again run ----------------------------------------------------------------------- declare a number:=10; b number:=20; c number; begin c:=a+b; dbms_output.put_line('Sum is' ||c); end; /

Create connection in sql developer oracle

Image
-: Observe the following figure :-                                                         (Click on the picture to zoom in) In sql developer Click on the + button which is the top left corner in green color according to above figure. create connection as connection name : system as sysdba username : password : then connect. Enjoy the go!! if you have sufficient previlage then go for---------------------------------------------------------

ORA-12543: TNS:destination host unreachable

SQL> conn Enter user-name: system Enter password ERROR: ORA-12543: TNS:destination host unreachable ------------------------------------------------------------------------------------------------------------------ One of the reasons why this type of error occurs is that if our password contain @  symbol. The way how to solve it is 1. Change the password (password should not contain @).       2. Without changing password, While entering the password, use double quotes  " at the beginning and at the end of the password.  ---> Lets my password is   abc@123 SQL> conn Enter user-name: system Enter password: "abc@123"

ArrayList of object

Understand the following program-------------------------------------- Main.java ------------------------------------ import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); List<Team> l=new ArrayList<Team>(); int n=sc.nextInt(); for(int i=0;i<n;i++) { System.out.println("Enter the team name"); String name=sc.next(); System.out.println("Enter the team id"); int id=sc.nextInt(); l.add(new Team(name,id)); } PrintTheList p=new PrintTheList(); p.Print(l); } } Team.java ------------------------------------------ public class Team { String name; int id; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public Team(String name, int id) { ...