How does this example work even if no oracle to be used and only access is available?

How does this example work even if no oracle to be used and only access is available?


package ExamplePackage;

import java.sql.*; import java.util.*;

public class ConnectionManager {

  static Connection con;
  static String url;

  public static Connection getConnection()


        System.out.println(" Defing the URL");

         String url= "jdbc:oracle:thin:@";
        // assuming "DataSource" is your DataSource name

       // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


            System.out.println(" Defing the username");
            String username= ""; 
            System.out.println(" Defing the password");
            String password= "";
            System.out.println(" Defing the connection");
            con = DriverManager.getConnection(url,username,password); 
            System.out.println(" connection done" +con);


        catch (SQLException ex)

     catch(ClassNotFoundException e)

  return con;

} }


package ExamplePackage;

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

/** * Servlet implementation class LoginServlet */ public class LoginServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, {

try {

 UserBean user = new UserBean();

 user = UserDAO.login(user);

 if (user.isValid())

      HttpSession session = request.getSession(true);       
      response.sendRedirect("userLogged.jsp"); //logged-in page             

      response.sendRedirect("invalidLogin.jsp"); //error page


catch (Throwable theException)
{ System.out.println(theException); } } }


package ExamplePackage;

public class UserBean {

  private String username;
  private String password;
  private String firstName;
  private String lastName;
  public boolean valid;

  public String getFirstName() {
     return firstName;

  public void setFirstName(String newFirstName) {
     firstName = newFirstName;

  public String getLastName() {
     return lastName;

  public void setLastName(String newLastName) {
     lastName = newLastName;

  public String getPassword() {
     return password;

  public void setPassword(String newPassword) {
     password = newPassword;

  public String getUsername() {
     return username;

  public void setUserName(String newUsername) {
     username = newUsername;

  public boolean isValid() {
     return valid;

  public void setValid(boolean newValid) {
     valid = newValid;


USERDAO package ExamplePackage;

import java.text.*; import java.util.*; import java.sql.*;

public class UserDAO
{ static Connection currentCon = null; static ResultSet rs = null;

  public static UserBean login(UserBean bean) {

     //preparing some objects for connection 
     Statement stmt = null;    

     String username = bean.getUsername();    
     String password = bean.getPassword();   

     String searchQuery =
           "select * from users where username='"
                    + username
                    + "' AND password='"
                    + password
                    + "'";

  // "System.out.println" prints in the console; Normally used to trace the process
  System.out.println("Your user name is " + username);          
  System.out.println("Your password is " + password);
  System.out.println("Query: "+searchQuery);

     //connect to DB 
     currentCon = ConnectionManager.getConnection();
     rs = stmt.executeQuery(searchQuery);           
     boolean more =;

     // if user does not exist set the isValid variable to false
     if (!more) 
        System.out.println("Sorry, you are not a registered user! Please sign up first");

     //if user exists set the isValid variable to true
     else if (more) 
        String firstName = rs.getString("firstname");
        String lastName = rs.getString("lastname");

        System.out.println("Welcome " + firstName);

  catch (Exception ex) 
     System.out.println("Log In failed: An Exception has occurred! " + ex);

  //some exception handling
     if (rs != null)    {
        try {
        } catch (Exception e) {}
           rs = null;

     if (stmt != null) {
        try {
        } catch (Exception e) {}
           stmt = null;

     if (currentCon != null) {
        try {
        } catch (Exception e) {

        currentCon = null;

return bean;



View Answers


Related Tutorials/Questions & Answers:
How does this example work even if no oracle to be used and only access is available?
ModuleNotFoundError: No module named 'does-this-even-work-anymore'
How does the Java for each loop work?
What is data analysis, and how does it work?
How many hours does a data scientist work?
How does Hadoop distributed file system work?
How does Social Media Marketing Work
How many hours a week does a data scientist work?
import package.subpackage.* does not work
Jquery form validation does not work
Jquery form validation does not work
How Does the Display Work for the iPad?
How to access Enterprise Beans
How to work with Ajax in spring
How to access Subclass?
in my project, i have to add only vertical scrollbar to a panel,but not horizontal scrollbar. i need some example on it,how to doit.
how to download oracle 9i
How to list even numbers between 1 and 100?
How to Access MS Access in jar.
What does a data scientist Do example?
How does it take to learn Java
How does it take to learn Java
How does it take to learn Java
How java work on Unicode machanish
how to get only checked data
How does Java handle integer overflows and underflows?
How to install Oracle JDK 8 on Ubuntu?
i need a school appication using struts frame work with oracle 10g using myeclipse6.0
How are this() and super() used with constructors?
How the AOP used in Spring?
What is jQuery and how it is used?