Sunday, December 7, 2014

sliitexamz.blogspot.com is worth $ 84 - Worth Of Web Calculator

sliitexamz.blogspot.com is worth $ 84 - Worth Of Web Calculator


1. ඔබ පාරෙ ගමන් කරන විට, තනි පොලිස් නිලධාරියෙක්ට ඔබව නැවැත්වීමට තහනම්. එසේ නැවැත්වීමට උත්සාහ ගතහොත්, නොනවත්වා යාමට ඔබට හැකිය. 

2. තනි පොලිස් නිලධාරියෙකුහට ඔබේ රියදුරු බලපත්‍රය රඳවා ගැනීමට නොහැකිය. 

3. ඔබ වාහනයක ගමන් කරන විටකදී, ඔබේ ජාතික හැඳුනුම් පත හැර වෙනත් ලියකියවිලි ඉල්ලා සිටීමට අයිතිය ඇත්තේ රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) පමණි.

4. තනි රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) ඔබට දඩ ගැසීමට හෝ චෝදනා කිරීමට නොහැකිය. ඔහුට අනිවාර්යෙන්ම සාක්ෂිකරුවෙකු අවශ්‍ය වේ. සාක්ෂිකරු පොලිස් නිලධාරියෙකුම විය යුතුයි. (එබැවින් සැමවිටම පාරේ රථ වාහන පාලක පොලිස් නිලධාරින් දෙන්නෙක් එකට සිටියි)

5. පොලිස් නිලධාරියෙකු ඔබට බීමතින් රිය පැදවූ බවට චෝදනා කලහොත්, බැලූන් පරීක්ෂාව (Balloon Test) කිරීමට ඉල්ලා සිටිය හැක. ඒ අවස්ථාවේදී ඔවුන් සතුව බැලූන් නොමැති නම්, ඔබට යාමට අවසර ඇත.

6. මහ මග ගමන් ගන්නා වාහනයක් නැවැත්වීමට අවසර ඇත්තේ රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) පමණයි.(ඒ බැවින් හමුදා මුරපොල (check point) වල එක පොලිස් නිලධාරියෙක් හෝ සිටිය යුතුය.)

7. පොලිස් නිලධාරියෙකුට ලිඛිත උසාවි නියෝගයක් නොමැතිව ඔබේ නිවසට හෝ රැකියා ස්ථානයට ඇතුළු විය නොහැක. ලිඛිත නියෝගය ඉල්ලා සිටීමට ඔබට සියලු අයිතිය ඇත. ඔවුන් බලෙන් ඇතුලු වීමට සැරසෙයිනම් එයට විරුද්ධ වීමට ඔබට අයිතිය ඇත.

8. ඔබ සිදුකල වැරැද්දේ ස්වභාවයත්, දණ්ඩ නීති සංග්‍රහය අනුව අදාල නීති උල්ලංගනය කිරීමත් පිලිබඳව කියන තුරු රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) ට ඔබේ රියදුරු බලපත්‍රය ලබාගත නොහැකිය. එසේ සඳහන් කිරීමට අපොහොසත් වන්නේ නම් ඔබට යාමට අවසර ඇත.

9.රථ වාහන පාලක පොලිස් නිලධාරියෙකු (Traffic Police) ඔබේ බලපත්‍රය බලෙන් ලබාගෙන, එය නැවත ලබා ගැනීමට පොලිස් ස්ථානයට එන ලෙස පැවසූ විටක, එලෙස නොගොස් පොලිස් අධිකාරියතුමන්ට හෝ ප්ප්‍රදේශිකයට අදාල නියෝජ්‍ය පොලිස්පතිතුමන්ට පැමිණිලි කිරීමට ඔබට අයිතිය පවතී. එවිට අදාල නිලධාරියාව, දුරාචාරය සහ නොහික්මුණු හැසිරීම යන වරද මත පදනම්ව සේවයෙන් පහ කරවීමට වුවද හැකියාව පවතී.

10. කාන්තාවකගෙන්,පොලිස් නිලධාරියෙකු නම, ලිපිනය, හැඳුනුම් පත, දුරකථන අංකය ඉල්ලා සිටී නම් ඒ ඉල්ලීම ඉටු නොකිරීමට අයිතිය ඇත (ඔහු ඔබට හිරිහැර කිරීමේ අරමුණින් සිටින බව ඔබට හැඟේ නම් පමණක්). ඔහුට ඔබව (කාන්තාව) අත් අඩංගුවට ගැනීමට නොහැක. ඔබට පොලිස් නිලධාරිනියකගේ සහය ඉල්ලා සිටීමට අයිතිය ඇත.

11.පොලිස් නිලධාරියෙකු කාන්තාවක් පරීක්ෂා කිරීමට බව පැවසූ විටක, එය පොලිස් නිලධාරිණියක ලවා කරවා ගැනීමට ඔබට (කාන්තාව) අයිතිය ඇත. පොලිස් කාන්තාවක් නොමැති නම්, ඔබට එය ප්‍රතික්ෂේප කිරීමට අයිතිය ඇත.

12. ඔබට අධික වේගයෙන් වාහනය පැදවීමේ වරදට දඩ ගැසීමට හෝ නඩු දැමීමට සැරසෙයි නම් ඊට ප්‍රථම වාහනයේ වේගය මනින ලද මීටරයේ වේගය සටහන් වී ඇති අයුරු තමාට පෙන්වන ලෙස ඉල්ලා සිටීමට අයිතිය ඇත. (බොහොමයක් පොලිසිවල පවතින වේග මීටර අක්‍රිය අතර ඔවුන් හුදෙක් මීටරය දිගුකර අනුමානයෙන් වරදකරුවන් අසුකරගනී)

13. ඔබ කිසියම් කරුණක් මත අත් අඩංගුවට පත්ව සිටිනම් පොලිසියට ප්‍රකාශ ඉදිරිපත් කිරීමට ප්‍රථම නීතිඥයෙකුගේ උපදෙස් ලබාගැනීමට ඔබට අයිතියක් පවතී. එනිසා එවැනි අවස්ථාවල ඔබට නීතිඥයෙකු ඉල්ලා සිටීය හැකිය.

ඔබට නීතිමය කරුණක් ගැන තවදුරටත් තොරතුරු ලබාගැනීමට අවශ්‍ය නම් නීති ආධාර කොමිෂන් සභාව ,අංක 1295,මහාධිකරණ සංකීර්ණය,අළුත්කඩේ,කොළඔ 12. යන ලිපිනයට ලිවීමෙන් හෝ 0094-11-2433618, 0094-11-5335329, 0094-11-5335281, 0094-011-2395894 යන අංක වලට ඇමතීමෙන් තොරතුරු ලබාගත හැකිය.

--share කිරීම වැදගත්--

උපුටාගැනීමකි..

Monday, November 24, 2014




 ..ඔයාලගේ computer වල සමහර වෙලාවට,සමහර game ,software open කරද්දී පල්ලෙහා පින්තුරේ තියෙනවා වගේ eror message එකක් එනවා නේද බලන්නකෝ ටිකක් රූපේ දිහා  . .



ඉතින් මන් දැන් කියන්න හදන්නේ මේක හදාගන්න විදිහ ගැන  .. මුලින්ම මේ path එකට යන්නකෝ  ..
My Computer > Write click > Advanced System Setting > 





දැන් ඔකේ මුලින්ම තියෙන්නේ Perfomance කියලා  .. එකේ තියන setting කියන එක click කරන්න  ..




දැන් පල්ලෙහා විදිහේ dailog එකක් ආවනේ  . . ඔකේ තුන්වන එකට යන්න  . .(Data Execution prevention)




ඊළගට පල්ලෙහා රූපේ විදිහට කරන්න  . .




Add click කරට පස්සේ පල්ලෙහා තියන විදිහේ එකක් එනවනේ  . .එකෙන් ඔයාලගේ වැඩ කරන්නේ නැති install කරපු software එක හොයාගෙන එක select කරලා ok කරන්න. . .


දැන් අනිත් application එකත් ok කරලා සේරගෙන්ම අයින් වෙලා ඔයාල ඔතනට දුන්න  open කරන්න බැරි software එක open කරලා බලන්නකෝ  .

Sunday, October 12, 2014

ARP and RARP-- The Address Resolution Protocols

ARP and RARP-- The Address Resolution Protocols

ARP  --Address Resolution Protocol

What is it for:  Arp translates IP numbers into hardware addresses.
How ARP works:  Send a packet from the querrying host with an Ethernet  broadcast address asking the target host with the given IP address to respond.  All hosts on the physical network receive this packet, and the one with the given IP number responds.  Then the original querring host knows the physical address of the target host.   Does not use IP; uses's physical frames.
Common ARP improvements:  Keep a cache of recently received translations.  Remember that these addresses are quite small, and the space needed to store them is also small. Store both the physical and IP addresses of all ARP broadcasting hosts.  Then every host who receives a broadcast ARP request can know the address translation of the sender.  This is especially imporant for the receiver of the broadcast.
How to Write ARP Software:    There are two parts.  The first part uses the cache to map IP -> physical addresses.  The second part fills the cache with mapping upon request from the first part.
Security:  Can you fool ARP software.  Yes, by poluting the network with your own answers.
Interesting question:  To send machine A some data, you broadcast seeking machine A.  Would it not be easier just to broadcast the data.  That would for sure reduce the total number of packets sent, at the cost of changing many unicasts to broadcasts.  What if someone answers an ARP request for you, and lies about who they are?  Who answers an ARP for a machine

RARP -- Reverse Address Resolution Protocol

What is it for:  Diskless clients don't have a place to store there IP number.  Rarp translates machines addresses into IP numbers.
How RARP works:  The client broadcasts a RARP packet with an ethernet broadcast address, and it's own physical address in the data portion.  The server responds by telling the client it's IP address.  Note there is no name sent.  Also note there is no security.  Does not use IP; uses's physical frames.
Common RARP improvements:  Don't let an RARP client retry indefinitlly.  That just causes wasted broadcasts.  Have a backup RARP server or two, on random time delays.
Interesting Question:  When should the server broadcast the answer instead of target it?  What gets put in the rest of the packet (since there is a large minimum packet length?

BOOTP -- The Bootstrapping Protocol

What is it for:  Diskless clients don't have a place to store there IP number.  Bootp translates machines addresses into IP numbers.  Because it uses IP packets, application level programmers can write bootp servers.
How BOOTP works:  The client broadcasts a BOOTP packet with source and destination IP broadcast addresses (all 1's), and it's own physical address in the data portion.  The server responds by telling the client it's actual IP address, and some other info (see page 368).  Note that the server must also send to a broadcast address, since there is no IP-> physical address mapping in the server's ARP cache yet, and the client won't yet respond to ARP requests (since it does not yet recognize it's IP address).
The Boot file:  BOOTP sends a suggested file server and file name to the client.  The client can then use anbother protocol (TFTP?) to retrieve that file, and boot using the resulting image.
Vendor Specific Area:  Can contain anything, but often time of day, dns server name, printer IP address,  and such.
Advantages over RARP:   Carries more info in the reply.

DHCP -- The Dynamic Host Configuration Protocol

What is it for:  Allows hosts to dynamically get a unique  IP number on each bootup.  Allows more hosts than IP numbers, as long as the total number of hosts up at any one time does not exceed the number of IP addresses available.  Further, DHCP provides more info (like netmask) than bootp.  Finally, it can take the IP addres back when no longer needed. 

Saturday, August 30, 2014

Difference between TCP vs UDP Protocol

TCP and UDP are two transport layer protocols, which are extensively used in internet for transmitting data between one host to another. Good knowledge of how TCP and UDP works is essential for any programmer. That's why difference between TCP and UDP is one of the most popular programming interview question. I have seen this question many times on various Java interviews , especially for server side Java developer positions. Since FIX (Financial Information Exchange) protocol is also a TCP based protocol, several investment banks, hedge funds, and exchange solution provider looks for Java developer with good knowledge of TCP and UDP. Writing fix engines and server side components for high speed electronic trading platforms needs capable developers with solid understanding of fundamentals including data structure, algorithms and networking. By the way, use of TCP and UDP is not limited to one area, its at the heart of internet. The protocol which is core of internet, HTTP is based on TCP. One more reason, why Java developer should understand these two protocol in detail is that Java is extensively used to write multi-threaded, concurrent and scalable servers. Java also provides rich Socket programming API for both TCP and UDP based communication. In this article, we will learn key differences between TCP and UDP protocol, which is useful to every Java programmers. To start with, TCP stands for Transmission Control Protocol and UDP stands for User Datagram Protocol, and both are used extensively to build Internet applications.




Difference between TCP vs UDP Protocol

I love to compare two things on different points, this not only makes them easy to compare but also makes it easy to remember differences. When we compare TCP to UDP, we learn difference in how both TCP and UDP works, we learn which provides reliable and guaranteed delivery and which doesn't. Which protocol is fast and why, and most importantly when to choose TCP over UDP while building your own distributed application. In this article we will see difference between UDP and TCP in 9 points, e.g. connection set-up, reliability, ordering, speed, overhead, header size, congestion control, application, different protocols based upon TCP and UDP and how they transfer data. By learning these differences, you not only able to answer this interview question better but also understand some important details about two of the most important protocols of internet.


1) Connection oriented vs Connection less
TCP handshake process SYN, SYN-ACK and ACK
First and foremost difference between them is TCP is a connection oriented protocol, and UDP is connection less protocol. This means  a connection is established between client and server, before they can send data. Connection establishment process is also known as TCP hand shaking where control messages are interchanged between client and server. Attached image describe the process of TCP handshake, for example which control messages are exchanged between client and server. Client, which is initiator of TCP connection, sends SYN message to server, which is listening on a TCP port. Server receives and sends a SYN-ACK message, which is received by client again and responded using ACK. Once server receive this ACK message,  TCP connection is established and ready for data transmission. On the other hand, UDP is a connection less protocol, and point to point connection is not established before sending messages. That's the reason, UDP is more suitable for multicast distribution of message, one to many distribution of data in single transmission.


2) Reliability
TCP provides delivery guarantee, which means a message sent using TCP protocol is guaranteed to be delivered to client. If message is lost in transits then its recovered using resending, which is handled by TCP protocol itself. On the other hand, UDP is unreliable, it doesn't provide any delivery guarantee. A datagram package may be lost in transits. That's why UDP is not suitable for programs which requires guaranteed delivery.


3) Ordering
Apart from delivery guarantee, TCP also guarantees order of message. Message will be delivered to client in the same order, server has sent, though its possible they may reach out of order to the other end of the network. TCP protocol will do all sequencing and ordering for you. UDP doesn't provide any ordering or sequencing guarantee. Datagram packets may arrive in any order. That's why TCP is suitable for application which need delivery in sequenced manner, though there are UDP based protocol as well which provides ordering and reliability by using sequence number and redelivery e.g. TIBCO Rendezvous, which is actually a UDP based application.


4) Data Boundary
TCP does not preserve data boundary, UDP does. In Transmission control protocol, data is sent as a byte stream, and no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually and are checked for integrity only if they arrived. Packets have definite boundaries which are honoured upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent. Though TCP will also deliver complete message after assembling all bytes. Messages are stored on TCP buffers before sending to make optimum use of network bandwidth.


5) Speed
In one word, TCP is slow and UDP is fast. Since TCP does has to create connection, ensure guaranteed and ordered delivery, it does lot more than UDP. This cost TCP in terms of speed, that's why UDP is more suitable where speed is a concern, for example online video streaming, telecast or online multi player games.


6) Heavy weight vs Light weight
Because of the overhead mentioned above, Transmission control protocol is considered as heavy weight as compared to light weight UDP protocol. Simple mantra of UDP to deliver message without bearing any overhead of creating connection and guaranteeing delivery or order guarantee keeps it light weight. This is also reflected in their header sizes, which is used to carry meta data.


7) Header size
TCP has bigger header than UDP. Usual header size of a TCP packet is 20 bytes which is more than double of 8 bytes, header size of UDP datagram packet. TCP header contains Sequence Number, Ack number, Data offset, Reserved, Control bit, Window, Urgent Pointer, Options, Padding, Check Sum, Source port, and Destination port. While UDP header only contains Length, Source port, Destination port, and Check Sum. Here is how TCP and UDP header looks like :

TCP Header Format


UDP Header Format 



8) Congestion or Flow control
TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. On the other hand, UDP does not have an option for flow control.


9) Usage and application
Where does TCP and UDP are used in internet? After knowing key differences between TCP and UDP, we can easily conclude, which situation suits them. Since TCP provides delivery and sequencing guaranty, it is best suited for applications that require high reliability, and transmission time is relatively less critical. While UDP is more suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients. In practice, TCP is used in finance domain e.g. FIX protocol is a TCP based protocol, UDP is used heavily in gaming and entertainment sites.


10) TCP and UDP based Protocols
One of the best example of TCP based higher end protocol is HTTP and HTTPS, which is every where on internet. In fact most of the common protocol you are familiar of e.g. Telnet, FTP and SMTP all are based over Transmission Control Protocol. UDP don't have any thing as popular as HTTP but UDP is used in protocol like DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System). Some of the other protocol, which is based over User Datagram protocol is Simple Network Management Protocol (SNMP), TFTPBOOTP and NFS (early versions).


That's all about difference between TCP and UDP protocol. Always remember to mention that TCP is connection oriented, reliable, slow, provides guaranteed delivery and preservers order of messages, while UDP is connection less, unreliable, no ordering guarantee, but fast protocol. TCP overhead is also much higher than UDP, as it transmits more meta data per packet than UDP. It's worth mentioning that header size of Transmission control protocol is 20 bytes, compared to 8 bytes header of User Datagram protocol. Use TCP, if you can't afford to lose any message, while UDP is better for high speed data transmission, where loss of single packet is acceptable e.g. video streaming or online multi player games. While working in TCP/UDP based application on Linux, it's also good to remember basic networking commands e.g. telnet and netstat, they help tremendously to debug or troubleshoot any connection issue.

Read more: Click Here

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.

OAuth authorization server