Thursday, August 28, 2014

JobDetails Management

Data

DBConnManager.java

package data1;

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DBConnManager {
 
 
     String sourceURL;
 
    public DBConnManager() {

try {
// Load JDBC driver
Class.forName("com.mysql.jdbc.Driver");
// Connection URL.
sourceURL = new String("");
} catch (ClassNotFoundException classNotFoundException) {
System.out.println(classNotFoundException + "-----------Unable to load database driver classes");
}
}



public Connection connect() throws SQLException{
Connection dbConn = null;
try {
dbConn =    (Connection) DriverManager.getConnection(sourceURL, "username", "password");
} catch (SQLException sQLException) {
System.out.println(sQLException + "-----------DB connection failure");
}
return dbConn;
}


public void con_close(Connection dbConn) {
try {
dbConn.close();
} catch (SQLException sQLException) {
System.out.println(sQLException + "-----------DB connection closing failure");
}
}


}
------------------------------------------------------------------------------------------------------------
JobDetailsDAO

package data1;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;


public class JobDetailsDAO {

    private DBConnManager dbConnManager = null;

    public JobDetailsDAO() {
        dbConnManager = new DBConnManager();

    }





public ArrayList getJobCategories() throws SQLException{

        ArrayList jobCatList = null;
Connection dbConn = null;

        try{
            //Connect to th DB
            dbConn = dbConnManager.connect();

            Statement stmt = (Statement) dbConn.createStatement();

            //Select the JobCatNames
            String query = "SELECT DISTINCT jobCatName FROM JobCategory";

            System.out.println(query);
            ResultSet rs = stmt.executeQuery(query);

            jobCatList = new ArrayList();

            while (rs.next()) {
                String catName = rs.getString(1);
                System.out.println(catName);
                jobCatList.add(catName);
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query failed at JobCatNames");
        }finally{
            //Close the db connection
            dbConnManager.con_close(dbConn);
        }
        return jobCatList;
    }



//sub_catogary
public int getJobCatId(String jobCatName){

        int catId = 0;
Connection dbConn = null;

        try {
            dbConn = dbConnManager.connect();

            Statement stmt = (Statement) dbConn.createStatement();

            String query = "SELECT jobCatId FROM JobCategory WHERE jobCatName = '"+jobCatName+"'";

            System.out.println(query);
            ResultSet rs = stmt.executeQuery(query);

            if(rs.next()){
                catId = Integer.parseInt(rs.getString(1));
                System.out.println(catId);
            }
        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query Failed for JobCatId");

        }finally{
            dbConnManager.con_close(dbConn);
        }
        return catId;
    }

public ArrayList getSubCategories(String jobCat){

        ArrayList jobSubCatList = null;
Connection dbConn = null;

        try{
            //Connect to th DB
            dbConn = dbConnManager.connect();

            Statement stmt = (Statement) dbConn.createStatement();

            int jobCatId = getJobCatId(jobCat);

            //Select the JobCatNames
            String query = "SELECT DISTINCT subCategoryName FROM JobSubCategory WHERE jobCatId = "+jobCatId;

            System.out.println(query);
            ResultSet rs = stmt.executeQuery(query);

            jobSubCatList = new ArrayList();

            while (rs.next()) {
                String subCatName = rs.getString(1);
                System.out.println(subCatName);
                jobSubCatList.add(subCatName);
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query failed at JobSubCatNames");
        }finally{
            //Close the db connection
            dbConnManager.con_close(dbConn);
        }
        return jobSubCatList;

    }

public int getSubCatId(String subCatName){

        int subCatId = 0;
Connection dbConn = null;

        try {
            dbConn = dbConnManager.connect();

            Statement stmt = (Statement) dbConn.createStatement();

            String query = "SELECT jobSubCatId FROM JobSubCategory WHERE subCategoryName = '"+subCatName+"'";

            System.out.println(query);
            ResultSet rs = stmt.executeQuery(query);

            if(rs.next()){
                subCatId = Integer.parseInt(rs.getString(1));
                System.out.println(subCatId);
            }
        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query Failed for JobCatId");

        }finally{
            dbConnManager.con_close(dbConn);
        }

        return subCatId;
}
public boolean addJob(jobDetails d) {

        boolean result = false;
Connection dbConn = null;

        try {
            dbConn = dbConnManager.connect();

            Statement stmt = (Statement) dbConn.createStatement();

            int catId = getJobCatId(d.getJobCategoryName());

            int subCatId = getSubCatId(d.getSubCategoryName());

            String query = "INSERT INTO Jobs(jobName,postedDate,expirationDate,jobCategory,jobSubCategory)  " +
                    "VALUES( '" + d.getJobName() + "','" + d.getPostedDate() + "','" + d.getExpirationDate() + "',"+catId+","+subCatId+")";

            System.out.println(query);

            int val = stmt.executeUpdate(query);

            if (val == 1) {
                result = true;
            }
            else {
                result = false;
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Insert query failed");

            result = false;
        }finally{
            dbConnManager.con_close(dbConn);
        }
        return result;
    }


public Vector getJobDetails() {

        Vector<Vector<String>> jobDetailsVector = null;
Connection dbConn = null;

        try {
            dbConn = dbConnManager.connect();
            Statement stmt = (Statement) dbConn.createStatement();

            String query = "SELECT jobID, jobName, postedDate, expirationDate, jobCatName, subCategoryName "+
                    "FROM Jobs J, JobCategory C, JobSubCategory S " +
                    "WHERE J.jobCategory=C.jobCatId AND J.jobSubCategory=S.jobSubCatid ORDER BY jobID DESC";

            ResultSet rs = stmt.executeQuery(query);
            jobDetailsVector = new Vector<Vector<String>>();

            while (rs.next()) {
                Vector<String> jobDetails = new Vector<String>();
                jobDetails.add(rs.getString(1)); //jobID
                jobDetails.add(rs.getString(2)); //jobName
                jobDetails.add(rs.getString(3)); //postedDate
                jobDetails.add(rs.getString(4)); //expirationDate
                jobDetails.add(rs.getString(5)); //jobCatName
                jobDetails.add(rs.getString(6)); //subCategoryName
                jobDetailsVector.add(jobDetails);
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query failed");
        } finally {
            dbConnManager.con_close(dbConn);
        }
        return jobDetailsVector;
    }


public boolean updateJob(jobDetails d) {
        boolean result = false;
Connection dbConn = null;

        try {
            dbConn = dbConnManager.connect();
            Statement stmt = (Statement) dbConn.createStatement();

            //Select the JobCatId and the JobSubCatId
            int catId = getJobCatId(d.getJobCategoryName());
            int subCatId = getSubCatId(d.getSubCategoryName());

            String query = "UPDATE Jobs SET jobName = '"
                           + d.getJobName() + "' ,expirationDate = '" + d.getExpirationDate()
                           + "' ,jobCategory = " + catId + " ,jobSubCategory = " + subCatId +
                             " WHERE jobId = " +d.getJobId();

            System.out.println(query);

            int val = stmt.executeUpdate(query);

            if (val == 1) {
                result = true;
            } else {
                result = false;
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Update query failed");
            result = false;
        } finally {
            dbConnManager.con_close(dbConn);
        }
        return result;
    }

public jobDetails getJobDetails(int jobId) {

jobDetails jobDetails = null;
Connection dbConn = null;

        try {

            //Connect to th DB
            dbConn = dbConnManager.connect();
            Statement stmt = (Statement) dbConn.createStatement();

            String query = "SELECT  j.jobId,j.jobName,j.postedDate, j.expirationDate, jc.jobCatName, js.subCategoryName " +
                    "FROM Jobs j,JobCategory jc,JobSubCategory js " +
                    "WHERE j.jobId = "+jobId+" AND jc.jobCatId = j.jobCategory AND js.jobSubCatId = j.jobSubCategory;";

            System.out.println(query);

           ResultSet rs = stmt.executeQuery(query);
           jobDetails = new jobDetails();

            if (rs.next()) {
                jobDetails.setJobId(Integer.parseInt(rs.getString(1))); //jobID
                jobDetails.setJobName(rs.getString(2)); //jobName
                jobDetails.setPostedDate(rs.getString(3)); //postedDate
                jobDetails.setExpirationDate(rs.getString(4)); //expirationDate
                jobDetails.setJobCategoryName(rs.getString(5)); //jobCatName
                jobDetails.setSubCategoryName(rs.getString(6)); //subCategoryName
            }

        } catch (SQLException sQLException) {
            System.out.println(sQLException + "-----------Select query failed for JobID");
        } finally {
            //Close the db connection
            dbConnManager.con_close(dbConn);
        }
        return jobDetails;

       }

}
------------------------------------------------------------------------------------------------------------

Sunday, July 6, 2014

What is JDBC Driver


JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.
For example, using JDBC drivers enable you to open database connections and to interact with it by sending SQL or database commands then receiving results with Java.
The Java.sql package that ships with JDK contains various classes with their behaviours defined and their actual implementaions are done in third-party drivers. Third party vendors implements thejava.sql.Driver interface in their database driver.

JDBC Drivers Types:

JDBC driver implementations vary because of the wide variety of operating systems and hardware platforms in which Java operates. Sun has divided the implementation types into four categories, Types 1, 2, 3, and 4, which is explained below:

Type 1: JDBC-ODBC Bridge Driver:

In a Type 1 driver, a JDBC bridge is used to access ODBC drivers installed on each client machine. Using ODBC requires configuring on your system a Data Source Name (DSN) that represents the target database.
When Java first came out, this was a useful driver because most databases only supported ODBC access but now this type of driver is recommended only for experimental use or when no other alternative is available.
DBMS Driver type 1
The JDBC-ODBC bridge that comes with JDK 1.2 is a good example of this kind of driver.

Type 2: JDBC-Native API:

In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls which are unique to the database. These drivers typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge, the vendor-specific driver must be installed on each client machine.
If we change the Database we have to change the native API as it is specific to a database and they are mostly obsolete now but you may realize some speed increase with a Type 2 driver, because it eliminates ODBC's overhead.
DBMS Driver type 2
The Oracle Call Interface (OCI) driver is an example of a Type 2 driver.

Type 3: JDBC-Net pure Java:

In a Type 3 driver, a three-tier approach is used to accessing databases. The JDBC clients use standard network sockets to communicate with an middleware application server. The socket information is then translated by the middleware application server into the call format required by the DBMS, and forwarded to the database server.
This kind of driver is extremely flexible, since it requires no code installed on the client and a single driver can actually provide access to multiple databases.
DBMS Driver type 3
You can think of the application server as a JDBC "proxy," meaning that it makes calls for the client application. As a result, you need some knowledge of the application server's configuration in order to effectively use this driver type.
Your application server might use a Type 1, 2, or 4 driver to communicate with the database, understanding the nuances will prove helpful.

Type 4: 100% pure Java:

In a Type 4 driver, a pure Java-based driver that communicates directly with vendor's database through socket connection. This is the highest performance driver available for the database and is usually provided by the vendor itself.
This kind of driver is extremely flexible, you don't need to install special software on the client or server. Further, these drivers can be downloaded dynamically.
DBMS Driver type 4
MySQL's Connector/J driver is a Type 4 driver. Because of the proprietary nature of their network protocols, database vendors usually supply type 4 drivers.

Which Driver should be used?

If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.
If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.
Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.
The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only.

Monday, June 30, 2014

Cisco Packet Tracer

Cisco Packet Tracer is a powerful network simulation program that allows students to experiment with network behavior and ask “what if” questions. As an integral part of the Networking Academy comprehensive learning experience, Packet Tracer provides simulation, visualization, authoring, assessment, and collaboration capabilities and facilitates the teaching and learning of complex technology concepts.






Packet Tracer supplements physical equipment in the classroom by allowing students to create a network with an almost unlimited number of devices, encouraging practice, discovery, and troubleshooting. The simulation-based learning environment helps students develop 21st century skills such as decision making, creative and critical thinking, and problem solving. Packet Tracer complements the Networking Academy curricula, allowing instructors to easily teach and demonstrate complex technical concepts and networking systems design.
The Packet Tracer software is available free of charge to Networking Academy instructors, students, alumni, and administrators who are registered NetSpace users.





Cisco Packet Tracer 6.0.1 for Windows (with tutorials).exe
https://docs.google.com/uc?export=download&confirm=wXlt&id=0B4CjGsNlfXWyRXUwSnNCT2pUT2M


packet-tracer through pwd Commands - Cisco





Saturday, June 7, 2014

SQL.Pocket.Reference



ITP_Initial Guidelines



OAuth authorization server