Sunday, 8 February 2015

CREATE and INSERT Queries

=> Create Table
 create table employee(no integer,name varchar2(15));

=>Crete Table with Primary key
 create table employee(no int primary key,name varchar2(15));

=>Crete Table with different Data types

 create table student(a int,b integer,c long,d float,e numeric(7,2),f number(7,2),g dec(7,2),h decimal(7,2),i varchar2(15),j date);

* desc student

 Name                                      Null?    Type
 ----------------------------------------- --------

 A                                                  NUMBER(38)
 B                                                  NUMBER(38)
 C                                                  LONG
 D                                                  FLOAT(126)
 E                                                  NUMBER(7,2)
 F                                                  NUMBER(7,2)
 G                                                  NUMBER(7,2)
 H                                                  NUMBER(7,2)
 I                                                  VARCHAR2(15)
 J                                                  DATE


* insert row into student table

insert into student values(100000000000,20000000,300000000,111.5,15000.00,15000.00,15000.00,15000.00,'ram',TO_DATE('1988/10/28','yyyy/mm/dd'));




Login Application

Sample View

Login Page

 If Login Fail

If Login Success


 Development

1) index.html

 

<form action="/LoginApplication/login">
Name:<input type="text" name="user" value="Ram"/>
Password:<input type="password" name="pwd" value="Ram"/>
<input type="submit" value="Login">
</form>
 

 

2)success.html

 

Login Success<br>
<a href="./index.html">Login</a>

 

3)fail.html

Login Failure<br>
<a href="./index.html">Login</a>

 

4)LoginServlet.java

 

package com.ram;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
   
    RequestDispatcher rd = null;
    boolean status;
      
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       
        String user = request.getParameter("user");
        String pwd = request.getParameter("pwd");
        UserDTO userDTO = new UserDTO();
        userDTO.setName(user);
        userDTO.setPwd(pwd);
       
        UserDAO userDAO = new UserDAO();
        status = userDAO.checkLogin(userDTO);
        if(status) {
            rd = request.getRequestDispatcher("success.html");
            rd.forward(request, response);
        } else {
            rd = request.getRequestDispatcher("fail.html");
            rd.forward(request, response);
        }
       
       
    }

}
 

 

5)UserDAO.java

 

package com.ram;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UserDAO {
   
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    boolean status;
    String name = null;
    String pwd = null;
   
    public boolean checkLogin(UserDTO userDTO) {
       
        name = userDTO.getName();
        pwd = userDTO.getPwd();
       
        try {
           
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","ram","ram");
            stmt=con.createStatement();
            rs=stmt.executeQuery("select * from users where NAME='"+name+"' and PWD='"+pwd+"'");
           
            if(rs.next()) {
                status = true;
            }
           
           
        } catch (SQLException e) {
            e.printStackTrace();
        }
       
        return status;
       
        }
    }

 

 

6)UserDTO.java

 

package com.ram;

public class UserDTO {
   
    String name;
    String pwd;
   
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
   
   

}
 

7)web.xml


<web-app>
  <display-name>LoginApplication</display-name>


  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>


  <servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>com.ram.LoginServlet</servlet-class>
  </servlet>


  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>


</web-app>

  8)Use ojdbc14.jar

9)Deployment