<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-513216235819956207</id><updated>2012-02-16T16:46:52.294-08:00</updated><category term='SCJP 6.0'/><category term='EJB'/><category term='SCWCD'/><category term='SCWCD 5.0'/><category term='Servlets'/><category term='Struts'/><category term='SCWCD Mock Exams'/><category term='SCBCD 5.0'/><category term='SCJP 5.0'/><category term='Hibernate'/><category term='JSF'/><category term='SCJP 1.6'/><category term='Basics'/><category term='SCBCD Mock Exams'/><category term='Interview Questions'/><category term='Java'/><category term='OpenSource'/><category term='Tutorials'/><category term='JDBC'/><category term='SCJP 1.5'/><category term='SCBCD'/><title type='text'>JavaBeat Weblog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>79</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-4253815752010432024</id><published>2008-04-02T06:15:00.000-07:00</published><updated>2008-04-02T06:18:09.641-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCBCD 5.0'/><title type='text'>Sample SCBCD 5.0 Questions</title><content type='html'>&lt;span style="font-weight: bold;"&gt;To get all 300 &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.javabeat.net/products/cert/scbcd-5-0.php"&gt;SCBCD 5.0&lt;/a&gt;&lt;span style="font-weight: bold;"&gt; Questions, click &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.javabeat.net/products/cert/scbcd-5-0.php"&gt;here.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;1) Consider the following Stateless Session Bean,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Stateless&lt;br /&gt;public class MyTestBean implements MyTestLocal&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;  public void cleanResources( )&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;You want to annotate the method cleanResources() with @PreDestroy Annotation using XML Deployment Descriptor. Which of the following will correctly do that? 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;session&gt;&lt;br /&gt;      &lt;ejb-name&gt;MyTestBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;pre-destroy-method&gt;&lt;br /&gt;       &lt;lifecycle-callback-method&gt;cleanResources&lt;/lifecycle-callback-method&gt;&lt;br /&gt;      &lt;/pre-destroy-method&gt;&lt;br /&gt;     &lt;/session&gt;&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;session&gt;&lt;br /&gt;      &lt;ejb-name&gt;MyTestBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;pre-destroy&gt;&lt;br /&gt;       &lt;lifecycle-callback-method&gt;cleanResources&lt;/lifecycle-callback-method&gt;&lt;br /&gt;      &lt;/pre-destroy&gt;&lt;br /&gt;     &lt;/session&gt;&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;session&gt;&lt;br /&gt;      &lt;ejb-name&gt;MyTestBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;pre-destroy-method&gt;cleanResources&lt;/pre-destroy-method&gt;&lt;br /&gt;     &lt;/session&gt;&lt;br /&gt;&lt;br /&gt;4. None of the above.&lt;br /&gt;&lt;br /&gt;2) A Stateful Session Bean by name 'ResourceAllocatorBean' has a business method by name 'allocate' along with a number of methods. You have developed an interceptor class 'net.javabeat.ejb3.LoggingInterceptor' which you want to apply to the method 'allocate' of the 'ResourceAllocatorBean'. Which of the following is the correct way to achieve that?&lt;br /&gt;1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;assembly-descriptor&gt;&lt;br /&gt;      &lt;interceptor-binding&gt;&lt;br /&gt;       &lt;ejb-name&gt;ResourceAllocatorBean&lt;/ejb-name&gt;&lt;br /&gt;       &lt;interceptor-class&gt; net.javabeat.ejb3.LoggingInterceptor&lt;/interceptor-class&gt;&lt;br /&gt;       &lt;method-name&gt;allocate&lt;/method-name&gt; &lt;br /&gt;      &lt;/interceptor-binding&gt;&lt;br /&gt;     &lt;/assembly-descriptor&gt;&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;assembly-descriptor&gt;&lt;br /&gt;      &lt;interceptor-binding&gt;&lt;br /&gt;       &lt;ejb-name&gt;ResourceAllocatorBean&lt;/ejb-name&gt;&lt;br /&gt;       &lt;interceptor&gt; net.javabeat.ejb3.LoggingInterceptor&lt;/interceptor&gt;&lt;br /&gt;       &lt;method-name&gt;allocate&lt;/method-name&gt; &lt;br /&gt;      &lt;/interceptor-binding&gt;&lt;br /&gt;     &lt;/assembly-descriptor&gt;&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;assembly-descriptor&gt;&lt;br /&gt;      &lt;interceptor-binding&gt;&lt;br /&gt;       &lt;ejb-name&gt;ResourceAllocatorBean&lt;/ejb-name&gt;&lt;br /&gt;       &lt;interceptor-class&gt; net.javabeat.ejb3.LoggingInterceptor&lt;/interceptor-class&gt;&lt;br /&gt;      &lt;/interceptor-binding&gt;&lt;br /&gt;     &lt;/assembly-descriptor&gt;&lt;br /&gt;&lt;br /&gt;4. None of the above.&lt;br /&gt;&lt;br /&gt;3) Given the following session bean,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Stateful&lt;br /&gt;public class CounterBean implements CounterRemote&lt;br /&gt;{&lt;br /&gt; // Line 'A'&lt;br /&gt; public int count()&lt;br /&gt; {&lt;br /&gt;  // Line 'B'.&lt;br /&gt;  userTransaction.begin();&lt;br /&gt;  // Do something here&lt;br /&gt;  userTransaction.commit();   &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Which of the following code snippets can be inserted into the lines marked by identifiers A and B so that the above bean code will compile without any compilation errors? 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Resource&lt;br /&gt;     private SessionContext sessionContext; // Line 'A'&lt;br /&gt;     Transaction userTransaction = sessionContext.getTransaction(); // Line 'B'&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Resource&lt;br /&gt;     private SessionContext sessionContext; // Line 'A'&lt;br /&gt;     UserTransaction userTransaction = sessionContext.getUserTransaction(); // Line 'B'&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Resource&lt;br /&gt;     private ApplicationTransaction transaction; // Line 'A'&lt;br /&gt;     UserTransaction userTransaction = transaction.getUserTransaction(); // Line 'B'&lt;br /&gt;&lt;br /&gt;4. None of the above.&lt;br /&gt;&lt;br /&gt;4) Which of the following is not a life-cycle method for a Stateful Session Bean?&lt;br /&gt;1. Post Construction&lt;br /&gt;2. Pre Destruction&lt;br /&gt;3. Post Activation&lt;br /&gt;4. Pre Construction&lt;br /&gt;5. Pre Passivation&lt;br /&gt;6. All the Above&lt;br /&gt;&lt;br /&gt;5) Imagine that you have a business interface by name 'Template'. Which of the following ways can be used by the Client Application to acquire a reference to the business interface (assuming that this interface is bound in the JNDI Context)?&lt;br /&gt;1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Resource&lt;br /&gt;     SessionContext context;&lt;br /&gt;     â€¦&lt;br /&gt;     Template template = (Template)context.lookup("template");&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @EJB&lt;br /&gt;     Template template;&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     Template template = null;&lt;br /&gt;     InitialContext context = new InitialContext();&lt;br /&gt;     template = (Template)Context.lookup("java:comp/ejb/template");&lt;br /&gt;&lt;br /&gt;4. All the above.&lt;br /&gt;&lt;br /&gt;6) Which of the following code snippets correctly declares a Message-Driven Bean by name 'TestMessageDrivenBean'?&lt;br /&gt;1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     public class TestMessageDrivenBean implements javax.jms.MessageListener&lt;br /&gt;     {&lt;br /&gt;         public void onMessage(Message message)&lt;br /&gt;         {&lt;br /&gt;             // Business logic here.&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     public class TestMessageDrivenBean implements javax.ejb.MessageListener&lt;br /&gt;     {&lt;br /&gt;         public void onMessage(Message message)&lt;br /&gt;         {&lt;br /&gt;             // Business logic here.&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     public class TestMessageDrivenBean implements javax.ejb.MessageListener&lt;br /&gt;     {&lt;br /&gt;         public void ejbRemove()&lt;br /&gt;         {&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;         public void setMessageDrivenContext(MessageDrivenContext context)&lt;br /&gt;         {&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;4. All the above.&lt;br /&gt;&lt;br /&gt;7) Imagine that the Application you develop periodically sends some events to some other parts of the Application at some defined intervals. Which of the following enterprise bean(s) can be used in this scenario?&lt;br /&gt;1. Entity Bean&lt;br /&gt;2. Stateful Session Bean&lt;br /&gt;3. Stateless Session Bean&lt;br /&gt;4. Message Driven Bean&lt;br /&gt;5. Timer Bean&lt;br /&gt;6. None of the above.&lt;br /&gt;&lt;br /&gt;8) Assume that your Application has created as instance of EntityManager with the following piece of code,&lt;br /&gt;EntityManagerFactory factory = Persistence.createEntityManagerFactory("...");&lt;br /&gt;EntityManager manager = factory.createEntityManager();&lt;br /&gt;Which of the following methods can be used to check whether the handle of the EntityManager instance is valid?&lt;br /&gt;1. EntityManager.isValid()&lt;br /&gt;2. EntityManager.isHandleValid()&lt;br /&gt;3. EntityManager.isOpen()&lt;br /&gt;4. None of the above.&lt;br /&gt;&lt;br /&gt;9) Which of the following way is used for creating an extended persistence context?&lt;br /&gt;1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     EntityManager entityManager = ...;&lt;br /&gt;     PersistenceContext context = entityManager.createExtendedPersistenceContext();&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     EntityManagerFactory factoy = Persistence.createEntityManagerFactory();&lt;br /&gt;     EntityManager entityManager = factory.createEntityManager();&lt;br /&gt;     PersistenceContext context =&lt;br /&gt;     entityManager.createPersistenceContext(PersistenceContextType.EXTENDED);&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @PersistenceContext(unitName = "...", type=PersistenceContextType.EXTENDED)&lt;br /&gt;     private EntityManager entityManager;&lt;br /&gt;&lt;br /&gt;4. None of the above.&lt;br /&gt;&lt;br /&gt;10) Which of the following criteria is needed to make a plain java class by name 'Employer' as an entity and that can also be transferred and accessible by a remote application?&lt;br /&gt;1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Entity&lt;br /&gt;     public class Employer&lt;br /&gt;     {&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     public class Employer extends javax.persistence.Entity&lt;br /&gt;     {&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     @Entity&lt;br /&gt;     public class Employer implements Serializable&lt;br /&gt;     {&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;4. All the above.&lt;br /&gt;Answers&lt;br /&gt;&lt;br /&gt;1) b.&lt;br /&gt;Option b is correct. The element 'lifecycle-callback-method' must be used specifying the name of the method and this element should be included within the element 'pre-destroy'.&lt;br /&gt;&lt;br /&gt;2)4) a.&lt;br /&gt;Option a is correct. This option correctly defines the elements for associating an enterprise bean and the interceptor class along with the method that should be intercepted.&lt;br /&gt;&lt;br /&gt;3) b.&lt;br /&gt;Option b is correct. The business method 'count' is trying to explicitly start a transaction, then do some business logic and finally commit the transaction. Here, since the transaction is controlled at the Application level, this transaction should be of type 'UserTransaction'. A UserTransaction object can be obtained a reference by calling the method getUserTransaction() on the Session Context object which is already initialized by the Container by applying the Annotation '@Resource'.&lt;br /&gt;&lt;br /&gt;4) d.&lt;br /&gt;Option d is correct. The life-cycle method Pre Construction is not valid for a Stateful Session Bean (as well as for any Enterprise Bean).&lt;br /&gt;&lt;br /&gt;5) d.&lt;br /&gt;All the options are correct. Options a and b using the dependency injection mechanism for initializing the business interface (from EJB 3.0). Option c uses the older style (EJB 2.1) for acquiring the reference to the business interface.&lt;br /&gt;&lt;br /&gt;6) a.&lt;br /&gt;Option a is correct. It is mandatory for a Message-Driven Bean to implement the MessageListener interface thereby overriding the onMessage() method.&lt;br /&gt;&lt;br /&gt;7) c and d.&lt;br /&gt;Options c and d are correct. It should be noted that only Stateless Session Beans and Message Driven Beans can make use of the Timer Service provided by the Container.&lt;br /&gt;&lt;br /&gt;8) c.&lt;br /&gt;Option c is correct. The method isOpen() will return true if the handle of the EntityManager is valid and it is not closed.&lt;br /&gt;&lt;br /&gt;9) c.&lt;br /&gt;Option c is correct. There is no such interface called PersistenceContext defined by the JPA Specification. A Persistence context is a virtual object that comes into existence whenever an EntityManager instance is created.&lt;br /&gt;&lt;br /&gt;10) c.&lt;br /&gt;Option c is correct. The class must be annotated with @Entity and must implement the Serializable interface (or the Externalizable interface).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To get all 300 &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.javabeat.net/products/cert/scbcd-5-0.php"&gt;SCBCD 5.0&lt;/a&gt;&lt;span style="font-weight: bold;"&gt; Questions, click &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.javabeat.net/products/cert/scbcd-5-0.php"&gt;here.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-4253815752010432024?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/4253815752010432024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=4253815752010432024' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4253815752010432024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4253815752010432024'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2008/04/sample-scbcd-50-questions.html' title='Sample SCBCD 5.0 Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-7151119867058699884</id><published>2008-04-02T06:06:00.000-07:00</published><updated>2008-04-02T06:09:07.218-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 1.5'/><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 6.0'/><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 1.6'/><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 5.0'/><category scheme='http://www.blogger.com/atom/ns#' term='SCWCD 5.0'/><category scheme='http://www.blogger.com/atom/ns#' term='SCBCD 5.0'/><title type='text'>List of Certification Exams Released by Javabeat</title><content type='html'>&lt;a href="http://www.javabeat.net/products/cert/scjp-1-5.php"&gt;350 SCJP 1.5 Mock Exam Questions&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/products/cert/scjp-1-6.php"&gt;400 SCJP 1.6 Mock Exam Questions&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/products/cert/scwcd-5-0.php"&gt;300 SCWCD 5.0 Mock Exam Questions&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/products/cert/scwcd-1-4.php"&gt;300 SCWCD 1.4 Mock Exam Questions&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/products/cert/scbcd-5-0.php"&gt;300 SCBCD 5.0 Mock Exam Questions&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-7151119867058699884?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/7151119867058699884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=7151119867058699884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7151119867058699884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7151119867058699884'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2008/04/list-of-certification-exams-released-by.html' title='List of Certification Exams Released by Javabeat'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-9070442978586503321</id><published>2008-04-02T06:02:00.000-07:00</published><updated>2008-04-02T06:04:35.098-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCBCD 5.0'/><title type='text'>SCBCD 5.0 Mock Exam Questions</title><content type='html'>&lt;span style="font-family:Verdana, Arial;font-size:85%;"&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/" target="_blank" rel="nofollow"&gt;JavaBeat&lt;/a&gt; has released 300 mock exam questions for &lt;a href="http://www.javabeat.net/products/cert/scbcd-5-0.php" target="_blank" rel="nofollow"&gt;SCBCD 5.0&lt;/a&gt; exam. The cost of this kit is JUST $12 or 300 INR. You can buy these mock exams &lt;a href="http://www.javabeat.net/products/cert/scbcd-5-0.php" target="_blank" rel="nofollow"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-9070442978586503321?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/9070442978586503321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=9070442978586503321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/9070442978586503321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/9070442978586503321'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2008/04/scbcd-50-mock-exam-questions.html' title='SCBCD 5.0 Mock Exam Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-1993445450387364223</id><published>2007-03-01T18:29:00.001-08:00</published><updated>2007-03-01T18:29:09.517-08:00</updated><title type='text'>Sun Updates Mobile Java Platform</title><content type='html'>&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;Sun  Microsystems announced the availability of the Mobile Services  Architecture (MSA), the next generation Java platform for mobile phones  and other handheld devices. MSA is available now for mobile devices and  Sun's NetBeans development platform.&lt;br&gt;&lt;br&gt; &lt;/font&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;Sun  developed the MSA along with 13 other companies, including operators,  OEMs and software vendors. The MSA is the next step in the evolution of  Sun's mobile API set, Java Technology for the Wireless Industry (JTWI).  &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;"What  we did with JTWI was make a compilation of a number of specs together  to create a standard platform developer could count on being in  handsets. MSA is the next generation. It supersedes JTWI with much more  features and functionality than what we had," John Muhlner, group  manager for Java ME product marketing at Sun (&lt;a href="http://www.internetnews.com/stocks/quotes/quote.php/SUNW"&gt;Quote&lt;/a&gt;&lt;!--, &lt;A HREF="http://www.internetnews.com/stocks/quotes/chart.php/SUNW/chart"&gt;Chart&lt;/A&gt;--&gt;), told &lt;i&gt;internetnews.com&lt;/i&gt; at an event to announce the new platform.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;&lt;br&gt;     &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;The new APIs (&lt;a href="http://inews.webopedia.com/SHARED/search_action.asp?Term=API&amp;amp;Template_Name=inews.webopedia.com"&gt;define&lt;/a&gt;)&amp;nbsp;in  MSA allow for the creation of mobile applications and services that use  3D graphics, personal information management, Bluetooth, animation, Web  services, location services and payment services. &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;MSA  also adds a Wireless Client optimized to support multiple, concurrent  wireless applications, the Device Test Suite 2.0 for testing the  quality and compliance of APIs to the specs, and the NetBeans Mobility  Pack 5.5 for building applications in the NetBeans environment.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;&lt;br&gt; &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;Finally,  there is the Java Wireless Toolkit 2.5 for Connected Limited Device  Configuration (CLDC), a collection of tools for building applications  and a wireless platform emulator for testing the applications. &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;Java  ME was severely fragmented for the longest time, and MSA will bring it  some unity, said Muhlner. "These platform specs take the specific  technologies and clarify or define certain options within the spec. It  reduces fragmentation and makes for a more consistent application  environment."&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;&lt;br&gt; &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Verdana, Arial, Helvetica, sans-serif" size="-1"&gt;Jeff  Griffin, MSA Expert Group representative for cell phone maker Sony  Ericsson, agreed. "MSA is critical for us in the next phase of making  Java more usable in mobile phones. The technology continues to grow,  new JSRs are added to the mix. This means imp fragmentation. What  umbrella JSRs like this are good is setting a baseline and saying  everyone needs to start here," he said.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-1993445450387364223?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/1993445450387364223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=1993445450387364223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1993445450387364223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1993445450387364223'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/03/sun-updates-mobile-java-platform.html' title='Sun Updates Mobile Java Platform'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-1673071672536194661</id><published>2007-01-18T19:35:00.000-08:00</published><updated>2007-01-18T19:35:46.944-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 5.0'/><title type='text'>SCJP 5.0 Mock Exams - Generics</title><content type='html'>&lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;a title="SCJP 5.0 Mock Exams - Generics" href="http://www.javabeat.net/javabeat/scjp5/mocks/"&gt;SCJP 5.0 Mock Exams - Generics&lt;/a&gt; &lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;what  is the result compiling and running the following piece of code?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Test {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;Set vals = new TreeSet&amp;lt;String&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;vals.add("one");&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;vals.add(1);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;vals.add("two");&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;                        &lt;font style="font-size: 9pt;" size="4"&gt;System.out.println(vals);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Does  not Compile&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  with warning and prints output [one, 1, two]&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  without warning and prints output [one, 1, two]&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  with warning and throws exception at runtime&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  without warning and throws exception at runtime&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;           &lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;font style="font-size: 9pt;" size="4"&gt;D are correct Answers.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt;Compiles with warning due to un-safe assignment List vals = new ArrayList&amp;lt;String&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt;Since TreeSet&amp;lt;String&amp;gt; is used, it will try to sort by natural order. Due to the presence of   Integer (vals.add(1);) in the collection, it will throw ClassCastException at runtime(While try to cast Integer in to String). &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="2"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;which  of the following piece of code can be inserted to make the following  code to compile?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class PickThePiece {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                        &lt;font style="font-size: 9pt;" size="4"&gt;//insert the first line here&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;    &lt;font style="font-size: 9pt;" size="4"&gt;             datas.add("delhi")    &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                            &lt;font style="font-size: 9pt;" size="4"&gt;datas.add(new Object());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                       &lt;font style="font-size: 9pt;" size="4"&gt;//insert the second line here&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;} &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;  &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;           &lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;Object&amp;gt;  datas = new LinkedList&amp;lt;Object&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.75in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;String data = datas.get(0);&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;" start="2"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;Object&amp;gt;  datas = new LinkedList&amp;lt;Object&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.75in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;String data = (String)datas.get(0);&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;" start="3"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;String&amp;gt;  datas = new LinkedList&amp;lt;String&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.75in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;String data = (String)datas.get(0);&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;" start="4"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;String&amp;gt;  datas = new LinkedList&amp;lt;String&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.75in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;String data = datas.get(0);&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;" start="5"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;all  the above&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;B,C, and D are the correct answers. &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;A is wrong because datas.get(0) will return a Object which cannot be directly assigned to a String without casting.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="3"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;What  is the result of compiling and running the following code?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;       &lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class SampleTest {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;    &lt;font style="font-size: 9pt;" size="4"&gt; List samples = new ArrayList();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;samples.add("100");&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;samples.add(200);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;samples.add("300");&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;printData(samples); &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;    &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;    &lt;font style="font-size: 9pt;" size="4"&gt;static void printData(List&amp;lt;String&amp;gt; samples) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;for(String sample : samples) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;            &lt;font style="font-size: 9pt;" size="4"&gt;System.out.print(sample + “ “);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;    &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;       &lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Prints  100 200 300&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compile  time error&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  without warning&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  with warning&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Runtime  Exception&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;D, E are correct answers. &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;D) It produces warning since un-safe List samples is passed to a type safe  collections(as a method argument).&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;E) Since samples.add(200), adds a Integer in to collection. While iterating through enhanced for loop, Integer is tried to cast to String causes ClassCastException.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="4"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Consider  the following code, select the valid options given below.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Fruit {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Apple extends Fruit {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Orange extends Fruit {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  extends Fruit&amp;gt; stmt = new ArrayList&amp;lt;Fruit&amp;gt;();&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  super Apple&amp;gt; stmt = new ArrayList&amp;lt;Fruit&amp;gt;();&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  extends Fruit&amp;gt; stmt = new ArrayList&amp;lt;Apple&amp;gt;();&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  super Orange&amp;gt; stmt = new ArrayList&amp;lt;Orange&amp;gt;();&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;All  the above&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;None  of these&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;E is the correct answer. All these options are valid.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;Keyword “super “ – allows the type followed by keyword and its super type(parent ).&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;Keyword “extends” – allows the type followed by keyword and its sub type(child).&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="5"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;What  is the output of the following code?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Color {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Blue extends Color {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Red extends Color {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class TestColor {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;1)         List&amp;lt;Color&amp;gt; colors = new ArrayList&amp;lt;Color&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;2)        colors.add(new Color());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;3)         colors.add(new Blue());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;4)         colors.add(new Red());  &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;5)        List&amp;lt;Color&amp;gt; newClr = alterColor(colors);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;6)         System.out.println(newClr);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;static void alterColor(List clrs) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;7) clrs.add(new Object());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}   &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compile  time error due to lines 3 and 4.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compile  time error due to line 5.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compile  time error due to line 7.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  with warning and produces some output.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  without warning and produces some output.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  fine and Exception is thrown at runtime.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answers :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;D is the correct answer. &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Warning is due to non-type safe method call. Within the alterColor() method adding a new Object is not a issue because the collection becomes non-type safe.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="6"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;what  is the result of the following code ?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Bird {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Duck extends Bird {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Hen extends Bird {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class FuzzyTest {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt; Map&amp;lt;String, Bird&amp;gt; birds = new HashMap&amp;lt;String, Bird&amp;gt;();  &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;birds.put("bird", new Bird());  &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;birds.put("hen", new Hen());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;birds.put("duck", new Duck());&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;Map bs = addBirds(birds);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;for(String b : bs.keySet())&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;             &lt;font style="font-size: 9pt;" size="4"&gt;System.out.print(b + " ");&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;     &lt;font style="font-size: 9pt;" size="4"&gt;} &lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;     &lt;font style="font-size: 9pt;" size="4"&gt;static Map addBirds(Map brds) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;     &lt;font style="font-size: 9pt;" size="4"&gt; brds.put("bird", new Object());     &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;        &lt;font style="font-size: 9pt;" size="4"&gt;return brds;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;     &lt;font style="font-size: 9pt;" size="4"&gt;}  &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  and prints output “bird hen duck”.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  and prints output “bird duck hen”.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  and prints some output order cannot be determined.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Run  time Exception.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compilation  fails.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;E is the correct answer.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Since bs is non-typesafe collection, bs.keySet() returns Object. But in enhanced for loop string is used to catch the returned values, that leads to compilation error.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="7"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;what  are the valid statements can be filled in the blank, to make the  code to compile and run?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;interface Eat{}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Animal implements Eat{}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Dog extends Animal {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Cat extends Animal  {}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class AnimalTest {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String[] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt; List&amp;lt;Animal&amp;gt; a = new ArrayList&amp;lt;Animal&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt; List&amp;lt;Dog&amp;gt; d = new ArrayList&amp;lt;Dog&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                &lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;Cat&amp;gt; c = new ArrayList&amp;lt;Cat&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                &lt;font style="font-size: 9pt;" size="4"&gt;checkAnimal(a);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;font style="font-size: 9pt;" size="4"&gt; checkAnimal(d);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt; checkAnimal(c);             &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;}       &lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt; &lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;static void checkAnimal( ________________ pets) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt; System.out.print(“animals checked here”);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;      &lt;font style="font-size: 9pt;" size="4"&gt;} &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  extends Animal&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  super Animal&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  extends Eat&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?  super Eat&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;List&amp;lt;?&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;All  of the above&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;A , C and E are the correct answers.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;               &lt;font style="font-size: 9pt;" size="4"&gt;Keyword “super “ – allows the type followed by keyword and its super type(parent ).&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;               &lt;font style="font-size: 9pt;" size="4"&gt;Keyword “extends” – allows the type followed by keyword and its sub type(child).&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;               &lt;font style="font-size: 9pt;" size="4"&gt;Wild card ? – allows everything.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="8"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;what  is the output of the following code?&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;import java.util.*;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Example {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;         &lt;font style="font-size: 9pt;" size="4"&gt;public static void main(String [] args) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;          &lt;font style="font-size: 9pt;" size="4"&gt; Set&amp;lt;String&amp;gt; values = new TreeSet&amp;lt;String&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt; values.add(“yet”);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt; values.add(“get”);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; text-indent: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt;values.add(“bet”);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; text-indent: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt;displayValues(values);&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;          &lt;font style="font-size: 9pt;" size="4"&gt;}   &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;         &lt;font style="font-size: 9pt;" size="4"&gt;static void displayValues(Set&amp;lt;?&amp;gt; values) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt; values.add(“wet”)&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;                &lt;font style="font-size: 9pt;" size="4"&gt;for(Object v : values) ;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;      System.out.print(v + “ “); &lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;         &lt;font style="font-size: 9pt;" size="4"&gt;}  &lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  and gives output “yet get bet wet”.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  and gives output “bet get wet yet”.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compilation  fails&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compiles  with warning and Exception thrown at runtime.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt; &lt;font style="font-size: 9pt;" size="4"&gt;Compiles  without warning and Exception thrown at runtime.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;C is the correct answer.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;When we use wildcard(?) to catch the collection , then modifications are not allowed in that collection. Here values.add(“wet”) will throw error at compilation time.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="9"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Choose  the valid ways to create an object for the following class.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class GenTest&amp;lt;T super Number&amp;gt; {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;font style="font-size: 9pt;" size="4"&gt;T num;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;font style="font-size: 9pt;" size="4"&gt;public T checkNumber(T n) {&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;font style="font-size: 9pt;" size="4"&gt;return n;&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;font style="font-size: 9pt;" size="4"&gt;}   &lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Compilation  fails.&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;GenTest&amp;lt;Number&amp;gt;  gt = new GenTest&amp;lt;Number&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="3"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;GenTest&amp;lt;Integer&amp;gt;  gt = new GenTest&amp;lt;Integer&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="4"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;GenTest&amp;lt;Object&amp;gt;  gt = new GenTest&amp;lt;Object&amp;gt;();&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="5"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;None  of the above.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;A is the correct answer.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Since &amp;lt;T super Number&amp;gt; is an invalid syntax. If super keyword is replaced by extends, then B and C will be the valid answers.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;ol style="font-family: Arial;" start="10"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Choose  the valid constructors for the following class.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;class Generics&amp;lt;T&amp;gt;{}&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Options :&lt;/font&gt;&lt;/p&gt; &lt;ol style="font-family: Arial;"&gt;  &lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;public  Generics(){}&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;public  Generics&amp;lt;T&amp;gt;(){}&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;public  &amp;lt;T&amp;gt; Generics(T t){}&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;public  &amp;lt;T&amp;gt; Generics(){}&lt;/font&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p class="western" style="margin-bottom: 0in;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;All  the above.&lt;/font&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;Answer :&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;A,C and D are correct answers.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font style="font-size: 9pt;" size="4"&gt;B is incorrect because of improper syntax.&lt;/font&gt;&lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;   &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.25in; margin-bottom: 0in; font-family: Arial;"&gt;  &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-left: 0.5in; margin-bottom: 0in; font-family: Arial;"&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;/font&gt; &lt;/p&gt; &lt;p class="western" style="margin-bottom: 0in; font-family: Arial;"&gt;  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-1673071672536194661?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/1673071672536194661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=1673071672536194661' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1673071672536194661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1673071672536194661'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/scjp-5_18.html' title='SCJP 5.0 Mock Exams - Generics'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-1628828086419166594</id><published>2007-01-18T17:47:00.004-08:00</published><updated>2007-01-18T17:49:18.369-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlets'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Servlets Interview Questions</title><content type='html'>&lt;a title="Servlet Interview Questions" href="http://faqs.javabeat.net/index.php?page=Servlets"&gt;Servlet Interview Questions&lt;/a&gt;   &lt;table style="text-align: left; margin-left: 0px; margin-right: auto; width: 981px; height: 2389px;" cellspacing="1"&gt;   &lt;tbody&gt;   &lt;tr style="color: rgb(255, 0, 0);" align="left"&gt;     &lt;td class="heading"&gt;       &lt;span style="font-weight: bold;"&gt;1. What is the servlet?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; Servlet is a script, which resides and executes on       server side, to create dynamic HTML. In servlet programming we will use       java language. A servlet can handle multiple requests concurrently &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;2. What is the architechture       of servlet package?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;       &lt;pre&gt;Servlet Interface is the central abstraction. All servlets implements this Servlet &lt;br&gt;Interface either direclty or indirectly &lt;br&gt;( may implement or extend Servlet Interfaces sub classes or sub interfaces)&lt;br&gt;&lt;br&gt;&lt;br&gt;  Servlet&lt;br&gt;    |&lt;br&gt;Generic Servlet&lt;br&gt;    |&lt;br&gt;HttpServlet   ( Class )  -- we will extend this class to handle GET / PUT HTTP requests&lt;br&gt;    |&lt;br&gt; MyServlet&lt;/pre&gt;       &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;3. What is the difference       between HttpServlet and GenericServlet?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; A GenericServlet has a service() method to handle       requests.&lt;br&gt;       HttpServlet extends GenericServlet added new methods&lt;br&gt;       doGet()&lt;br&gt;       doPost()&lt;br&gt;       doHead()&lt;br&gt;       doPut()&lt;br&gt;       doOptions()&lt;br&gt;       doDelete()&lt;br&gt;       doTrace() methods&lt;br&gt;       Both these classes are abstract. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; 4. What's the difference       between servlets and applets?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; Servlets executes on Servers. Applets executes on       browser. Unlike applets, however, servlets have no graphical user       interface. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr style="color: rgb(255, 0, 0);"&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold;"&gt; 5. What are the uses of Servlets?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; A servlet can handle multiple requests concurrently,       and can synchronize requests. Servlets can forward requests to other       servers and servlets. Thus servlets can be used to balance load among       several servers. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; 6. When doGET() method will       going to execute?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; When we specified method='GET' in HTML&lt;br&gt;       Example : &amp;lt; form name='SSS' method='GET'&amp;gt; &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; 7. When doPOST() method       will going to execute?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; When we specified method='POST' in HTML&lt;br&gt;       &amp;lt; form name='SSS' method='POST' &amp;gt; &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;   &lt;/tr&gt;   &lt;tr style="font-weight: bold;"&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt;8. What is the difference between Difference       between doGet() and doPost()?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; GET Method : Using get method we can able to pass 2K       data from HTML&lt;br&gt;       All data we are passing to Server will be displayed in URL (request       string).&lt;br&gt;       &lt;br&gt;       POST Method : In this method we does not have any size limitation.&lt;br&gt;       All data passed to server will be hidden, User cannot able to see this       info&lt;br&gt;       on the browser. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;9. What is the servlet life       cycle?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;When first request came in for the servlet , Server       will invoke init() method of the servlet. There after if any user request       the servlet program, Server will directly executes the service() method.       When Server want to remove the servlet from pool, then it will execute the       destroy() method &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       Which code line must be set before any of the lines that use the       PrintWriter?     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;setContentType() method must be set. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;10. Which protocol will be       used by browser and servlet to communicate ?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;HTTP&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;            &lt;br&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;          Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;br&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;/tbody&gt; &lt;/table&gt; &lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-1628828086419166594?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/1628828086419166594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=1628828086419166594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1628828086419166594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1628828086419166594'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/servlet-interview-questions-1.html' title='Servlets Interview Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-2209519744657587141</id><published>2007-01-18T17:47:00.003-08:00</published><updated>2007-01-18T17:49:22.147-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlets'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Servlets Interview Questions</title><content type='html'>&lt;a title="Servlet Interview Questions" href="http://faqs.javabeat.net/index.php?page=Servlets"&gt;Servlet Interview Questions&lt;/a&gt;&lt;table style="text-align: left; margin-left: 0px; margin-right: auto; width: 981px; height: 2389px;" cellspacing="1"&gt;   &lt;tbody&gt;                                             &lt;tr&gt;   &lt;/tr&gt;                           &lt;tr&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;11. In how many ways we can track the sessions?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; Method 1) By URL rewriting&lt;br&gt;       &lt;br&gt;       Method 2) Using Session object&lt;br&gt;       &lt;br&gt;       Getting Session form HttpServletRequest object&lt;br&gt;       &lt;font color="#a3aaaf"&gt;HttpSession session = request.getSession(true);&lt;/font&gt;&lt;br&gt;       &lt;br&gt;       Get a Value from the session&lt;br&gt;       &lt;font color="#a3aaaf"&gt; session.getValue(session.getId()); &lt;/font&gt;&lt;br&gt;       &lt;br&gt;       Adding values to session&lt;br&gt;       &lt;font color="#a3aaaf"&gt;cart = new Cart();&lt;br&gt;       session.putValue(session.getId(), cart); &lt;/font&gt;&lt;br&gt;       &lt;br&gt;       At the end of the session, we can inactivate the session by using the following command&lt;br&gt;       &lt;font color="#a3aaaf"&gt;session.invalidate();&lt;/font&gt;&lt;br&gt;       &lt;br&gt;       Method 3) Using cookies&lt;br&gt;       &lt;br&gt;       Method 4) Using hidden fields&lt;br&gt;       &lt;br&gt;       &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;12. How Can You invoke other web resources (or other servelt / jsp ) ?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; Servelt can invoke other Web resources in two ways: indirect and direct.&lt;br&gt;       &lt;br&gt;       Indirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource)&lt;br&gt;       &lt;br&gt; Direct Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.&lt;br&gt;       &lt;br&gt; You can get this object using getRequestDispatcher("URL") method. You can get this object from either a request or a Context.&lt;br&gt;       &lt;br&gt;       Example :&lt;br&gt;       &lt;font color="#6e6e6e"&gt; RequestDispatcher dispatcher = request.getRequestDispatcher("/jspsample.jsp");&lt;br&gt;       if (dispatcher != null)&lt;br&gt;       dispatcher.forward(request, response);&lt;br&gt;       } &lt;/font&gt; &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;13. How Can you include other Resources in the Response?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; Using include method of a RequestDispatcher object.&lt;br&gt;       &lt;br&gt; Included WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response.&lt;br&gt;       &lt;br&gt;       Example : &lt;font color="#a3aaaf"&gt;RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/banner");&lt;br&gt;                  &amp;amp;nbspif (dispatcher != null)&lt;br&gt;                  &amp;amp;nbspdispatcher.include(request, response);&lt;br&gt;       } &lt;/font&gt; &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;14. What is the difference between the getRequestDispatcher(String path) ServletRequest interface and ServletContext interface?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt; The getRequestDispatcher(String path) method of ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.&lt;br&gt;       &lt;br&gt;The getRequestDispatcher(String path) method of ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root. If the resource is not available, or if the server has not implemented a RequestDispatcher object for that type of resource, getRequestDispatcher will return null. Your servlet should be prepared to deal with this condition. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;15. What is the use of ServletContext ?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;Using ServletContext, We can access data from its environment. Servlet context is common to all Servlets so all Servlets share the information through ServeltContext. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;16. Is there any way to generate PDF'S dynamically in servlets?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;We need to use iText. A open source library for java. Please refer sourceforge site for sample servlet examples. &lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="heading"&gt;       &lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;17. What is the difference between using getSession(true) and getSession(false) methods?&lt;/span&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td&gt;       &lt;font class="answer"&gt;getSession(true) - This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object.&lt;br&gt;       &lt;br&gt; getSession(false) - This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;/tbody&gt; &lt;/table&gt; &lt;br&gt;    Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-2209519744657587141?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/2209519744657587141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=2209519744657587141' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2209519744657587141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2209519744657587141'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/servlet-interview-questions-11.html' title='Servlets Interview Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-7886304864510504314</id><published>2007-01-18T17:47:00.002-08:00</published><updated>2007-01-18T17:49:43.051-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Struts'/><title type='text'>Struts Interview Questions</title><content type='html'>&lt;a title="Struts Interview Questions" href="http://struts.javabeat.net/faq/index.php"&gt;Struts Interview Questions&lt;/a&gt; &lt;br&gt;&lt;font color="#000080"&gt;&lt;b&gt;&lt;br&gt; &lt;/b&gt;&lt;/font&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question21:&lt;/b&gt; What are the disadvantages of &lt;/font&gt;Struts&lt;font color="#000080"&gt;?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; Struts is very robust framework and is being used extensively in the industry. But there are some disadvantages of the Struts:&lt;br&gt;   &lt;b&gt;a) High Learning Curve&lt;br&gt;   &lt;/b&gt;Struts requires lot of efforts to learn and master it. For any small project less experience developers could spend more time on learning the Struts.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;b) Harder to learn&lt;/b&gt;&lt;br&gt;   Struts are harder to learn, benchmark and optimize.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question22:&lt;/b&gt; What is Struts Flow?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; Struts Flow is a port of Cocoon's Control Flow to Struts to allow complex workflow, like multi-form wizards, to be easily implemented using continuations-capable JavaScript. It provides the ability to describe the order of Web pages that have to be sent to the client, at any given point in time in an application. The code is based on a proof-of-concept Dave Johnson put together to show how the Control Flow could be extracted from Cocoon. (Ref: &lt;a href="http://struts.sourceforge.net/struts-flow/index.html" target="_blank"&gt;http://struts.sourceforge.net/struts-flow/index.html&lt;/a&gt; )&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question23:&lt;/b&gt; What are the difference between &amp;lt;bean:message&amp;gt; and &amp;lt;bean:write&amp;gt;?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; &lt;b&gt;&amp;lt;bean:message&amp;gt;&lt;/b&gt;: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.&lt;br&gt;   &lt;br&gt;   &lt;b&gt;&amp;lt;bean:write&amp;gt;&lt;/b&gt;: This tag is used to output property values from a bean. &amp;lt;bean:write&amp;gt; is a commonly used tag which enables the programmers to easily present the data.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question24:&lt;/b&gt; What is LookupDispatchAction?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. (Ref. &lt;a href="http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html" target="_blank"&gt;http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html&lt;/a&gt;).&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question25:&lt;/b&gt; What are the components of Struts?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; Struts is based on the MVC design pattern. Struts components can be categories into &lt;b&gt;Model&lt;/b&gt;, &lt;b&gt;View&lt;/b&gt; and &lt;b&gt;Controller&lt;/b&gt;.&lt;br&gt;   &lt;b&gt;Model: &lt;/b&gt;Components like business logic / business processes and data are the part of Model.&lt;br&gt;   &lt;b&gt;View:&lt;/b&gt; JSP, HTML etc. are part of View&lt;br&gt;   &lt;b&gt;Controller:&lt;/b&gt; Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question26:&lt;/b&gt; What are Tag Libraries provided with Struts?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; Struts provides a number of tag libraries that helps to create view components easily. These tag libraries are:&lt;br&gt;   &lt;b&gt;a) Bean Tags:&lt;/b&gt; Bean Tags are used to access the beans and their properties.&lt;br&gt;   &lt;b&gt;b) HTML Tags:&lt;/b&gt; HTML Tags provides tags for creating the view components like forms, buttons, etc..&lt;br&gt;   &lt;b&gt;c) Logic Tags:&lt;/b&gt; Logic Tags provides presentation logics that eliminate the need for scriptlets.&lt;br&gt;   &lt;b&gt;d) Nested Tags:&lt;/b&gt; Nested Tags helps to work with the nested context.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question27:&lt;/b&gt; What are the core classes of the Struts Framework?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; &lt;/font&gt;&lt;font color="#000080"&gt;Core classes of Struts Framework are ActionForm, Action, ActionMapping, ActionForward, ActionServlet etc.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question28:&lt;/b&gt; What are difference between ActionErrors and ActionMessage?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; &lt;b&gt;ActionMessage:&lt;/b&gt; A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.&lt;br&gt;   Each individual message is described by an ActionMessage object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;ActionErrors:&lt;/b&gt; A class that encapsulates the error messages being reported by the validate() method of an ActionForm. Validation errors are either global to the entire ActionForm bean they are associated with, or they are specific to a particular bean property (and, therefore, a particular input field on the corresponding form).&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;Question29:&lt;/b&gt; How you will handle exceptions in Struts?&lt;br&gt;   &lt;b&gt;Answer:&lt;/b&gt; In Struts you can handle the exceptions in two ways:&lt;br&gt;   &lt;b&gt;a) Declarative Exception Handling: &lt;/b&gt;You can either define global exception handling tags in your struts-config.xml or define the exception handling tags within &amp;lt;action&amp;gt;..&amp;lt;/action&amp;gt; tag.&lt;br&gt;   &lt;b&gt;Example:&lt;/b&gt;&lt;/font&gt;&lt;br&gt;   &lt;font color="#000080"&gt;&amp;lt;exception &lt;p&gt; &lt;/p&gt; &lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;      key="database.error.duplicate"&lt;p&gt; &lt;/p&gt; &lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;      path="/UserExists.jsp"&lt;p&gt; &lt;/p&gt; &lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;      type="mybank.account.DuplicateUserException"/&amp;gt;&lt;/font&gt; &lt;/p&gt; &lt;font color="#000080"&gt;&lt;b&gt;b) Programmatic Exception Handling:&lt;/b&gt; Here you can use try{}catch{} block to handle the exception.&lt;/font&gt;&lt;br&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;br&gt;   &lt;/font&gt; &lt;/p&gt; &lt;font color="#000080"&gt;&lt;b&gt;Question30:&lt;/b&gt; What do you understand by JSP Actions?&lt;br&gt; &lt;b&gt;Answer:&lt;/b&gt; JSP actions are XML tags that direct the server to use existing components or control the behavior of the JSP engine. JSP Actions consist of a typical (XML-based) prefix of "jsp" followed by a colon, followed by the action name followed by one or more attribute parameters.&lt;br&gt; There are six JSP Actions:&lt;/font&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:include/&amp;gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:forward/&amp;gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:plugin/&amp;gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:usebean/&amp;gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:setProperty/&amp;gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;jsp:getProperty/&amp;gt; &lt;br&gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;   &lt;br&gt;   &lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;&lt;span style="font-weight: bold;"&gt;Source : www.javabeat.net&lt;/span&gt;&lt;br&gt;&lt;/font&gt;&lt;/code&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-7886304864510504314?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/7886304864510504314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=7886304864510504314' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7886304864510504314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7886304864510504314'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/struts-interview-questions-question21.html' title='Struts Interview Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-7985600244022851044</id><published>2007-01-18T17:47:00.001-08:00</published><updated>2007-01-18T17:49:49.290-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Struts'/><title type='text'>Struts Interview Questions</title><content type='html'>&lt;a title="Struts Interview Questions" href="http://struts.javabeat.net/faq/index.php"&gt;Struts Interview Questions&lt;/a&gt; &lt;br&gt;&lt;font color="#000080"&gt;&lt;b&gt;       &lt;/b&gt;&lt;/font&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question11: Why cant we overide create method in StatelessSessionBean?&lt;br&gt;     Answer:&lt;/b&gt;  &lt;/font&gt;&lt;font color="#000080"&gt;From the EJB Spec : - A Session bean's home interface defines one or morecreate(...) methods. Each create method must be named create and must match one of the ejbCreate methods defined in the enterprise Bean class. The return type of a create method must be the enterprise Bean's remote interface type. The home interface of a stateless session bean must have one create method that takes no arguments.&lt;br&gt;       &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question12: Is struts threadsafe?Give an example?&lt;br&gt;     Answer:&lt;/b&gt;  &lt;/font&gt;&lt;font color="#000080"&gt;Struts is not only thread-safe but thread-dependant. The response to a request is handled by a light-weight Action object, rather than an individual servlet. Struts instantiates each Action class once, and allows other requests to be threaded through the original object. This core strategy conserves resources and provides the best possible throughput. A properly-designed application will exploit this further by routing related operations through a single Action.&lt;br&gt;        &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question13: Can we Serialize static variable?&lt;br&gt;     Answer:  &lt;/b&gt;Serialization is the process of converting a set of object         instances that contain references to each other into a linear stream of         bytes, which can then be sent through a socket, stored to a file, or         simply manipulated as a stream of data. Serialization is the mechanism         used by RMI to pass objects between JVMs, either as arguments in a         method invocation from a client to a server or as return values from a         method invocation. In the first section of this book, There are         three exceptions in which serialization doesnot necessarily read and         write to the stream. These are&lt;br&gt;         1. Serialization ignores static fields, because they are not part of any         particular object's state.&lt;br&gt;         2. Base class fields are only handled if the base class itself is     serializable.&lt;br&gt;         3. Transient fields.         There are four basic things       you must do when you are making a class serializable. They are:&lt;/font&gt;      &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;font color="#000080"&gt;Implement the Serializable interface.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Make sure that instance-level, locally defined state is serialized         properly.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Make sure that superclass state is serialized properly.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Override equals( )and hashCode(         ).&lt;br&gt; it is possible to have control over serialization process. The class       should implement Externalizable interface. This interface contains two       methods namely readExternal and writeExternal. You should implement these       methods and write the logic for customizing the serialization process ....         (Source: &lt;a href="http://www.oreilly.com/catalog/javarmi/chapter/ch10.html"&gt;http://www.oreilly.com/catalog/javarmi/chapter/ch10.html&lt;/a&gt;) &lt;br&gt;           &lt;/font&gt;                 &lt;/li&gt;&lt;/ol&gt; &lt;font color="#000080"&gt;&lt;b&gt;Question14: What are the uses of tiles-def.xml file, resourcebundle.properties file, validation.xml file?&lt;br&gt;     Answer:  &lt;/b&gt;&lt;/font&gt;&lt;font color="#000080"&gt;tiles-def.xml is is an xml file used to configure tiles with the struts application. You can define the layout / header / footer / body content for your View. See more at &lt;a href="http://www.roseindia.net/struts/using-tiles-defs-xml.shtml"&gt;http://www.roseindia.net/struts/using-tiles-defs-xml.shtml&lt;/a&gt;. &lt;br&gt;     &lt;br&gt;     The &lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt; resourcebundle.properties &lt;/b&gt;file is     used to configure the message (error/ other messages) for the struts     applications. &lt;br&gt;     &lt;br&gt;     The file validation.xml is used to declare sets of validations that should be applied to Form Beans.     Fpr more information please visit &lt;a href="http://www.roseindia.net/struts/address_struts_validator.shtml"&gt;http://www.roseindia.net/struts/address_struts_validator.shtml&lt;/a&gt;. &lt;br&gt;        &lt;/font&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question15: What is the difference between     perform() and execute() methods?&lt;br&gt;     Answer:  &lt;/b&gt;Perform method is the method which was deprecated in the     Struts Version 1.1.  &lt;/font&gt;&lt;font color="#000080"&gt;In Struts 1.x, Action.perform() is the method called by the ActionServlet. This is typically where your business logic resides, or at least the flow control to your JavaBeans and EJBs that handle your business logic. As we already mentioned, to support declarative exception handling, the method signature changed in perform. Now execute just throws Exception. Action.perform() is now deprecated; however, the Struts v1.1 ActionServlet is smart enough to know whether or not it should call perform or execute in the Action, depending on which one is available.&lt;br&gt;        &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question16: What are the various Struts tag libraries?&lt;br&gt;     Answer:  &lt;/b&gt;Struts is very rich framework and it provides very good     and user friendly way to develop web application forms. Struts provide many     tag libraries to ease the development of web applications. These tag     libraries are:&lt;br&gt;  * Bean tag library - Tags for accessing JavaBeans and their properties.&lt;br&gt;     * HTML tag library - Tags to output standard HTML, including forms, text     boxes, checkboxes, radio buttons etc..&lt;br&gt;     * Logic tag library - Tags for generating conditional output, iteration capabilities and flow management&lt;br&gt;     * Tiles or Template tag library - For the application using tiles&lt;br&gt;     * Nested tag library - For using the nested beans in the application&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question17: What do you understand by     DispatchAction?&lt;br&gt;     Answer:  &lt;/b&gt;&lt;/font&gt;&lt;font color="#000080"&gt;DispatchAction is an action that comes with Struts 1.1     or later, that lets you combine Struts actions into one class, each with their own method.     The org.apache.struts.action.DispatchAction class allows multiple operation     to mapped to the different functions in the same Action class. &lt;br&gt;     &lt;b&gt;For example: &lt;/b&gt;&lt;br&gt;     A package might include separate RegCreate, RegSave, and RegDelete Actions,     which just perform different operations on the same RegBean object. Since     all of these operations are usually handled by the same JSP page, it would     be handy to also have them handled by the same Struts Action.&lt;/font&gt;     &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;A very simple way to do this is to have the submit     button modify a field in the form which indicates which operation to     perform.&lt;/font&gt;&lt;/p&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;html:hidden       property="dispatch" value="error"/&amp;gt; &lt;br&gt;       &amp;lt;SCRIPT&amp;gt;function set(target)       {document.forms[0].dispatch.value=target;}&amp;lt;/SCRIPT&amp;gt;&lt;br&gt;       &amp;lt;html:submit onclick="set('save');"&amp;gt;SAVE&amp;lt;/html:submit&amp;gt;&lt;br&gt;       &amp;lt;html:submit onclick="set('create');"&amp;gt;SAVE AS NEW&amp;lt;/html:submitl&amp;gt; &lt;br&gt;       &amp;lt;html:submit onclick="set('delete);"&amp;gt;DELETE&amp;lt;/html:submit&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;     &lt;/blockquote&gt;     &lt;p&gt;&lt;font color="#000080"&gt;Then, in the Action you can setup different methods     to handle the different operations, and branch to one or the other depending     on which value is passed in the dispatch field.&lt;/font&gt;&lt;/p&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;String dispatch = myForm.getDispatch();&lt;br&gt;       if ("create".equals(dispatch)) { ...&lt;br&gt;       if ("save".equals(dispatch)) { ...&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;     &lt;/blockquote&gt;     &lt;p&gt;&lt;font color="#000080"&gt;The Struts Dispatch Action [org.apache.struts.actions]     is designed to do exactly the same thing, but without messy branching logic.     The base perform method will check a dispatch field for you, and invoke the     indicated method. The only catch is that the dispatch methods must use the     same signature as perform. This is a very modest requirement, since in     practice you usually end up doing that anyway.&lt;/font&gt;&lt;/p&gt;     &lt;p&gt;&lt;font color="#000080"&gt;To convert an Action that was switching on a     dispatch field to a DispatchAction, you simply need to create methods like     this&lt;/font&gt;&lt;/p&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;public ActionForward create(&lt;br&gt;           ActionMapping mapping, &lt;br&gt;           ActionForm form, &lt;br&gt;           HttpServletRequest request, &lt;br&gt;           HttpServletResponse response) &lt;br&gt;         throws IOException, ServletException { ...&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;public ActionForward save(&lt;br&gt;           ActionMapping mapping, &lt;br&gt;           ActionForm form, &lt;br&gt;           HttpServletRequest request, &lt;br&gt;           HttpServletResponse response) &lt;br&gt;         throws IOException, ServletException { ...&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;     &lt;/blockquote&gt;     &lt;p&gt;&lt;font color="#000080"&gt;Cool. But do you have to use a property named     dispatch? No, you don't. The only other step is to specify the name of of     the dispatch property as the "parameter" property of the     action-mapping. So a mapping for our example might look like this:&lt;/font&gt;&lt;/p&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;action &lt;br&gt;         path="/reg/dispatch" &lt;br&gt;         type="app.reg.RegDispatch" &lt;br&gt;         name="regForm" &lt;br&gt;         scope="request" &lt;br&gt;         validate="true" &lt;br&gt;         parameter="dispatch"/&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;     &lt;/blockquote&gt;     &lt;p&gt;&lt;font color="#000080"&gt;If you wanted to use the property "o"     instead, as in o=create, you would change the mapping to&lt;/font&gt;&lt;/p&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;code&gt;&lt;font color="#000080"&gt;&amp;lt;action &lt;br&gt;         path="/reg/dispatch" &lt;br&gt;         type="app.reg.RegDispatch" &lt;br&gt;         name="regForm" &lt;br&gt;         scope="request" &lt;br&gt;         validate="true" &lt;br&gt;         parameter="o"/&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;     &lt;/blockquote&gt;     &lt;p&gt;&lt;font color="#000080"&gt;Again, very cool. But why use a JavaScript button     in the first place? Why not use several buttons named "dispatch"     and use a different value for each?&lt;/font&gt;&lt;/p&gt;     &lt;p&gt;&lt;font color="#000080"&gt;You can, but the value of the button is also its     label. This means if the page designers want to label the button something     different, they have to coordinate the Action programmer. Localization     becomes virtually impossible. (Source: &lt;a href="http://husted.com/struts/tips/002.html" target="_blank"&gt;http://husted.com/struts/tips/002.html&lt;/a&gt;). &lt;br&gt;         &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question18: How Struts relates to J2EE?&lt;br&gt;     Answer: &lt;/b&gt;Struts framework  is built on J2EE technologies (JSP,     Servlet, Taglibs), but it is itself not part of the J2EE standard.&lt;br&gt;        &lt;/font&gt; &lt;/p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question19: What is Struts actions and action mappings?&lt;br&gt;     Answer: &lt;/b&gt;A Struts action is an instance of a subclass of an Action class, which implements a portion of a Web application and whose perform or execute method returns a forward.&lt;br&gt;     &lt;br&gt;     An action can perform tasks such as validating a user name and password.&lt;br&gt;     &lt;br&gt; An action mapping is a configuration file entry that, in general, associates an action name with an action. An action mapping can contain a reference to a form bean that the action can use, and can additionally define a list of local forwards that is visible only to this action.&lt;br&gt;     &lt;br&gt; An action servlet is a servlet that is started by the servlet container of a Web server to process a request that invokes an action. The servlet receives a forward from the action and asks the servlet container to pass the request to the forward's URL. An action servlet must be an instance of an org.apache.struts.action.ActionServlet class or of a subclass of that class. An action servlet is the primary component of the controller.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question20:&lt;/b&gt; Can I setup Apache Struts to use multiple configuration files?&lt;br&gt; &lt;b&gt;Answer:&lt;/b&gt; Yes Struts can use multiple configuration files. Here is the configuration example:&lt;br&gt; &amp;lt;servlet&amp;gt;&lt;br&gt;         &amp;lt;servlet-name&amp;gt;banking&amp;lt;/servlet-name&amp;gt;&lt;br&gt;         &amp;lt;servlet-class&amp;gt;org.apache.struts.action.ActionServlet&lt;br&gt;         &amp;lt;/servlet-class&amp;gt;&lt;br&gt;         &amp;lt;init-param&amp;gt;&lt;br&gt;         &amp;lt;param-name&amp;gt;config&amp;lt;/param-name&amp;gt;&lt;br&gt; &lt;/font&gt;&lt;b&gt;&lt;font color="#0000ff"&gt;        &amp;lt;param-value&amp;gt;/WEB-INF/struts-config.xml,&lt;br&gt;                 /WEB-INF/struts-authentication.xml,&lt;br&gt;                 /WEB-INF/struts-help.xml&lt;br&gt;            &amp;lt;/param-value&amp;gt;&lt;br&gt; &lt;/font&gt;&lt;/b&gt;&lt;font color="#000080"&gt;    &amp;lt;/init-param&amp;gt;&lt;br&gt;     &amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;br&gt; &amp;lt;/servlet&amp;gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;code&gt;&lt;font color="#000080"&gt;&lt;span style="font-weight: bold;"&gt;Source : www.javabeat.net&lt;/span&gt;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-7985600244022851044?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/7985600244022851044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=7985600244022851044' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7985600244022851044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/7985600244022851044'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/struts-interview-questions-question11.html' title='Struts Interview Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-6399823428389973432</id><published>2007-01-18T17:47:00.000-08:00</published><updated>2007-01-18T17:49:52.946-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Struts'/><title type='text'>Struts Interview Questions</title><content type='html'>&lt;a title="Struts Interview Questions" href="http://struts.javabeat.net/faq/index.php"&gt;Struts Interview Questions&lt;/a&gt; &lt;br&gt;&lt;br&gt;Q1: What is ActionServlet?&lt;br&gt;A: The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.&lt;br&gt;&lt;br&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q2: How you will make available any Message     Resources Definitions file to the Struts Framework Environment?&lt;br&gt;     A: &lt;/b&gt;Message Resources Definitions file are simple .properties files and     these files contains the messages that can be used in the struts project. Message     Resources Definitions files can be added to the struts-config.xml file     through &lt;b&gt;&amp;lt;message-resources /&amp;gt;&lt;/b&gt;     tag.&lt;br&gt;     &lt;b&gt;Example:&lt;/b&gt;&lt;br&gt;     &amp;lt;message-resources parameter="MessageResources" /&amp;gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q3: What is Action Class?&lt;br&gt;     A: &lt;/b&gt;The Action is part of the controller. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to  Subclass and overwrite the execute()  method. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. There should be no database interactions in the action. The action should receive the request, call business objects (which then handle database, or interface with J2EE, etc) and then determine where to go next. Even better, the business objects could be handed to the action at runtime (IoC style) thus removing any dependencies on the model.   The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q4: Write code of any Action Class?&lt;br&gt;     A: &lt;/b&gt;Here is the code of Action Class that returns the &lt;i&gt;ActionForward&lt;/i&gt; object.&lt;br&gt;     &lt;b&gt;TestAction.java&lt;/b&gt;     &lt;/font&gt;                                                             &lt;code&gt; &lt;font color="#000080"&gt;&lt;b&gt;package &lt;/b&gt;roseindia.net;&lt;br&gt;  &lt;br&gt;  &lt;b&gt;import &lt;/b&gt;javax.servlet.http.HttpServletRequest;&lt;br&gt;  &lt;b&gt;import &lt;/b&gt;javax.servlet.http.HttpServletResponse;&lt;br&gt;  &lt;br&gt;  &lt;b&gt;import &lt;/b&gt;org.apache.struts.action.Action;&lt;br&gt;  &lt;b&gt;import &lt;/b&gt;org.apache.struts.action.ActionForm;&lt;br&gt;  &lt;b&gt;import &lt;/b&gt;org.apache.struts.action.ActionForward;&lt;br&gt;  &lt;b&gt;import &lt;/b&gt;org.apache.struts.action.ActionMapping;&lt;br&gt;  &lt;br&gt;  &lt;b&gt;public class &lt;/b&gt;TestAction &lt;b&gt;extends &lt;/b&gt;Action&lt;br&gt;  {&lt;br&gt;    &lt;b&gt;public &lt;/b&gt;ActionForward execute(&lt;br&gt;      ActionMapping mapping,&lt;br&gt;      ActionForm form,&lt;br&gt;      HttpServletRequest request,&lt;br&gt;      HttpServletResponse response) &lt;b&gt;throws &lt;/b&gt;Exception{&lt;br&gt;        &lt;b&gt;return &lt;/b&gt;mapping.findForward("testAction");&lt;br&gt;    }&lt;br&gt;  }&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/code&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q5: What is ActionForm?&lt;br&gt;     A: &lt;/b&gt;An ActionForm is a JavaBean that extends &lt;code&gt;org.apache.struts.action.ActionForm&lt;/code&gt;.     ActionForm maintains the session state for web application and the     ActionForm object is automatically populated on the server side with data     entered from a form on the client side.&lt;br&gt;        &lt;/font&gt;  &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q6: What is Struts Validator Framework?&lt;br&gt;     A: &lt;/b&gt;Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with &lt;b&gt;DynaValidatorForm&lt;/b&gt; class. &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.&lt;br&gt;    &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q7. Give the Details of XML files used in Validator Framework?&lt;br&gt; A: &lt;/b&gt;The Validator Framework uses two XML configuration files &lt;b&gt;validator-rules.xml&lt;/b&gt; and &lt;b&gt;validation.xml&lt;/b&gt;. The &lt;b&gt;validator-rules.xml&lt;/b&gt; defines the standard validation routines, these are reusable and used in &lt;b&gt;validation.xml&lt;/b&gt;. to define the form specific validations. The &lt;b&gt;validation.xml&lt;/b&gt; defines the validations applied to a form bean.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Q8. How you will display validation fail errors on jsp page?&lt;br&gt; A: &lt;/b&gt;Following tag displays all the errors:&lt;br&gt; &amp;lt;html:errors/&amp;gt;&lt;br&gt;   &lt;/font&gt;&lt;/p&gt; &lt;font color="#000080"&gt;&lt;b&gt;Q9. How you will enable front-end validation based on the xml in validation.xml?&lt;br&gt; A: &lt;/b&gt;The &amp;lt;html:javascript&amp;gt; tag to allow front-end validation based on the xml in validation.xml. For  example the code: &amp;lt;html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /&amp;gt; generates the client side java script for the form "logonForm" as defined in the validation.xml file. The &amp;lt;html:javascript&amp;gt; when added in the jsp file generates the client site validation script.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;Question10: What is RequestProcessor and RequestDispatcher?&lt;br&gt;     Answer:&lt;/b&gt;  The controller is responsible for intercepting and translating user input into actions to be performed by the model. The controller is responsible for selecting the next view based on user input and the outcome of model operations. The Controller receives the request from the browser, invoke a business operation and coordinating the view to return to the client.&lt;br&gt;     &lt;br&gt; The controller is implemented by a java servlet, this servlet is centralized point of control for the web application. In struts framework the controller responsibilities are implemented by several different components like&lt;br&gt;     &lt;b&gt;The ActionServlet Class&lt;br&gt;     The RequestProcessor Class&lt;br&gt;     The Action Class&lt;/b&gt;&lt;br&gt;     &lt;br&gt;     The ActionServlet extends the&lt;b&gt; javax.servlet.http.httpServlet&lt;/b&gt; class. The ActionServlet class is not abstract and therefore can be used as a concrete controller by your application.&lt;br&gt; The controller is implemented by the ActionServlet class. All incoming requests are mapped to the central controller in the deployment descriptor as follows.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;servlet&amp;gt;&lt;br&gt;                 &amp;lt;servlet-name&amp;gt;action&amp;lt;/servlet-name&amp;gt;&lt;br&gt;                 &amp;lt;servlet-class&amp;gt;org.apache.struts.action.ActionServlet&amp;lt;/servlet-class&amp;gt;&lt;br&gt;     &amp;lt;/servlet&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     &lt;br&gt;     &lt;br&gt;     All request URIs with the pattern *.do are mapped to this servlet in the deployment descriptor as follows.&lt;br&gt;     &lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br&gt;    &amp;lt;servlet-name&amp;gt;action&amp;lt;/servlet-name&amp;gt;&lt;br&gt;             &amp;lt;url-pattern&amp;gt;*.do&amp;lt;/url-pattern&amp;gt;&lt;br&gt;             &amp;lt;url-pattern&amp;gt;*.do&amp;lt;/url-pattern&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     A request URI that matches this pattern will have the following form.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;http://www.my_site_name.com/mycontext/actionName.do&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     &lt;br&gt; The preceding mapping is called extension mapping, however, you can also specify path mapping where a pattern ends with /* as shown below.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br&gt;         &amp;lt;servlet-name&amp;gt;action&amp;lt;/servlet-name&amp;gt;&lt;br&gt;         &amp;lt;url-pattern&amp;gt;/do/*&amp;lt;/url-pattern&amp;gt;&lt;br&gt;     &amp;lt;url-pattern&amp;gt;*.do&amp;lt;/url-pattern&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     A request URI that matches this pattern will have the following form.&lt;br&gt;     http://www.my_site_name.com/mycontext/do/action_Name&lt;br&gt;     The class &lt;b&gt; org.apache.struts.action.requestProcessor&lt;/b&gt; process the request from the controller. You can sublass the RequestProcessor with your own version and modify how the request is processed.&lt;br&gt;     &lt;br&gt; Once the controller receives a client request, it delegates the handling of the request to a helper class. This helper knows how to execute the business operation associated with the requested action. In the Struts framework this helper class is descended of org.apache.struts.action.Action class. It acts as a bridge between a client-side user action and business operation. The Action class decouples the client request from the business model. This decoupling allows for more than one-to-one mapping between the user request and an action. The Action class also can perform other functions such as authorization, logging before invoking business operation. the Struts Action class contains several methods, but most important method is the execute() method.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;public ActionForward execute(ActionMapping mapping,&lt;br&gt;                 ActionForm form, HttpServletRequest request, HttpServletResponse response)        throws Exception; &lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt; The execute() method is called by the controller when a request is received from a client. The controller creates an instance of the Action class if one doesn’t already exist. The strut framework will create only a single instance of each Action class in your application.&lt;br&gt;     &lt;br&gt; Action are mapped in the struts configuration file and this configuration is loaded into memory at startup and made available to the framework at runtime. Each Action element is represented in memory by an instance of the org.apache.struts.action.ActionMapping class . The ActionMapping object contains a path attribute that is matched against a portion of the URI of the incoming request.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;action&amp;gt;&lt;br&gt;             path= "/somerequest"&lt;br&gt;             type="com.somepackage.someAction"&lt;br&gt;             scope="request"&lt;br&gt;             name="someForm"&lt;br&gt;             validate="true"&lt;br&gt;             input="somejsp.jsp"&lt;br&gt;         &amp;lt;forward name="Success" path="/action/xys" redirect="true"/&amp;gt;&lt;br&gt;         &amp;lt;forward name="Failure" path="/somejsp.jsp" redirect="true"/&amp;gt;&lt;br&gt;     &amp;lt;/action&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt; Once this is done the controller should determine which view to return to the client. The execute method signature in Action class has a return type org.apache.struts.action.ActionForward class. The ActionForward class represents a destination to which the controller may send control once an action has completed. Instead of specifying an actual JSP page in the code, you can declaratively associate as action forward through out the application. The action forward are specified in the configuration file.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;action&amp;gt;&lt;br&gt;             path= "/somerequest"&lt;br&gt;             type="com.somepackage.someAction"&lt;br&gt;             scope="request"&lt;br&gt;             name="someForm"&lt;br&gt;             validate="true"&lt;br&gt;             input="somejsp.jsp"&lt;br&gt;         &amp;lt;forward name="Success" path="/action/xys" redirect="true"/&amp;gt;&lt;br&gt;         &amp;lt;forward name="Failure" path="/somejsp.jsp" redirect="true"/&amp;gt;&lt;br&gt;     &amp;lt;/action&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     The action forward mappings also can be specified in a global section, independent of any specific action mapping.&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;global-forwards&amp;gt;&lt;br&gt;         &amp;lt;forward name="Success" path="/action/somejsp.jsp" /&amp;gt;&lt;br&gt;         &amp;lt;forward name="Failure" path="/someotherjsp.jsp" /&amp;gt;&lt;br&gt;     &amp;lt;/global-forwards&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     &lt;br&gt;     &lt;b&gt;public interface RequestDispatcher&lt;/b&gt;&lt;br&gt;     &lt;br&gt; Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name.&lt;br&gt; This interface is intended to wrap servlets, but a servlet container can create RequestDispatcher objects to wrap any type of resource.&lt;br&gt;     &lt;br&gt;     &lt;b&gt;getRequestDispatcher&lt;/b&gt;&lt;br&gt;     &lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;public RequestDispatcher getRequestDispatcher(java.lang.String path)&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     &lt;br&gt; Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.&lt;br&gt; The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.&lt;br&gt;     &lt;br&gt;     &lt;b&gt;    Parameters:&lt;br&gt;         path - a String specifying the pathname to the resource &lt;br&gt;     Returns:&lt;br&gt;         a RequestDispatcher object that acts as a wrapper for the resource at the specified path &lt;br&gt;     See Also:&lt;br&gt;         RequestDispatcher, getContext(java.lang.String)&lt;/b&gt;&lt;br&gt;     &lt;br&gt;     getNamedDispatcher&lt;br&gt;     &lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;public RequestDispatcher getNamedDispatcher(java.lang.String name)&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;     &lt;br&gt;     Returns a RequestDispatcher object that acts as a wrapper for the named servlet.&lt;br&gt; Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet instance can determine its name using ServletConfig.getServletName().&lt;br&gt;     This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.&lt;br&gt;     &lt;br&gt;     &lt;b&gt;        Parameters:&lt;br&gt;         name - a String specifying the name of a servlet to wrap &lt;br&gt;         Returns:&lt;br&gt;         a RequestDispatcher object that acts as a wrapper for the named servlet &lt;br&gt;         See Also:&lt;br&gt;         RequestDispatcher, getContext(java.lang.String), ServletConfig.getServletName()&lt;br&gt;&lt;br&gt;&lt;/b&gt;&lt;/font&gt;&lt;code&gt;&lt;font color="#000080"&gt;&lt;span style="font-weight: bold;"&gt;Source : www.javabeat.net&lt;/span&gt;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-6399823428389973432?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/6399823428389973432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=6399823428389973432' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6399823428389973432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6399823428389973432'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/struts-interview-questions-q1-what-is.html' title='Struts Interview Questions'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-3903087605007073679</id><published>2007-01-18T17:39:00.005-08:00</published><updated>2007-01-18T17:41:41.422-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;br&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;1. &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);" class="boldbodycopy"&gt;&lt;a name="01_01"&gt;What is JDBC?&lt;/a&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span class="bodycopy"&gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span class="bodycopy"&gt;JDBC technology is an API that lets you access virtually any tabular data source from the Java programming language. It provides cross-DBMS connectivity to a wide range of SQL databases, and now, with the new JDBC API, it also provides access to other tabular data sources, such as spreadsheets or flat files.&lt;/span&gt;&lt;br&gt;&lt;span class="bodycopy"&gt;&lt;/span&gt;&lt;span class="bodycopy"&gt;&lt;br&gt;&lt;/span&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;a name="1"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;2. What's the JDBC 3.0 API?&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;/b&gt;&lt;/a&gt; &lt;p&gt;The JDBC 3.0 API is the latest update of the JDBC API. It contains many features, including scrollable result sets and the SQL:1999 data types.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;b&gt;&lt;a name="2"&gt;3. Does the JDBC-ODBC Bridge support the new features in the JDBC 3.0 API?&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;b&gt;&lt;a name="2"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt; &lt;p&gt;The JDBC-ODBC Bridge provides a limited subset of the JDBC 3.0 API.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="3"&gt;4. Can the JDBC-ODBC Bridge be used with applets?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="3"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Use of the JDBC-ODBC bridge from an untrusted applet running in a browser,  such as Netscape Navigator, isn't allowed. The JDBC-ODBC bridge doesn't allow untrusted code to call it for security reasons. This is good because it means that an untrusted  applet that is downloaded by the browser can't circumvent Java security by calling ODBC. Remember that ODBC is native code, so once ODBC is called the Java programming language can't guarantee that a security violation won't occur. On the other hand, Pure Java JDBC drivers work well with applets. They are fully downloadable and do not require any client-side configuration.&lt;/p&gt; &lt;p&gt;Finally, we would like to note that it is possible to use the JDBC-ODBC bridge with applets that will be run in appletviewer since appletviewer assumes that applets are trusted. In general, it is dangerous to turn applet security off, but it may be appropriate in certain controlled situations, such as for applets that will only be used in a secure intranet environment. Remember to exercise caution if you choose this option, and use an all-Java JDBC driver whenever possible to avoid security problems.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="4"&gt;5. How do I start debugging problems related to the JDBC API?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="4"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.&lt;/p&gt; &lt;p&gt;If you use the &lt;code&gt;DriverManager&lt;/code&gt; facility to establish your database connection, you use the &lt;code&gt;DriverManager.setLogWriter&lt;/code&gt; method to enable tracing of JDBC operations. If you use a &lt;code&gt;DataSource&lt;/code&gt; object to get a connection, you use the &lt;code&gt;DataSource.setLogWriter&lt;/code&gt; method to enable tracing. (For pooled connections, you use the &lt;code&gt;ConnectionPoolDataSource.setLogWriter&lt;/code&gt; method, and for connections that can participate in distributed transactions, you use the &lt;code&gt;XADataSource.setLogWriter&lt;/code&gt; method.)&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="5"&gt;6. How can I use the JDBC API to access a desktop database like Microsoft Access over the network?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="5"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Most desktop databases currently require a JDBC solution that uses  ODBC underneath. This is because the vendors of these database products haven't implemented all-Java JDBC drivers.&lt;/p&gt; &lt;p&gt;The best approach is to use a commercial JDBC driver that supports ODBC and the database you want to use. See the  &lt;a href="http://industry.java.sun.com/products/jdbc/drivers"&gt;JDBC drivers page&lt;/a&gt; for a list of  available JDBC drivers.&lt;/p&gt; &lt;p&gt;The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers for desktop databases like Access aren't networked. The JDBC-ODBC bridge can be used together with the  &lt;a href="http://www.objectweb.org/"&gt;RMI-JDBC bridge&lt;/a&gt;, however, to access a desktop database like Access over the net. This RMI-JDBC-ODBC solution is free.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="8"&gt;7. Are there any ODBC drivers that do not work with the JDBC-ODBC Bridge?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="8"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Most ODBC 2.0 drivers should work with the Bridge. Since there is some  variation in functionality between ODBC drivers, the functionality of the  bridge may be affected. The bridge works with popular PC databases, such as Microsoft Access and FoxPro.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="9"&gt;8. What causes the "No suitable driver" error?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="9"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;"No suitable driver" is an error that usually occurs during a call to the &lt;code&gt;DriverManager.getConnection&lt;/code&gt; method. The cause can be failing to load the appropriate JDBC drivers before calling the &lt;code&gt;getConnection&lt;/code&gt; method, or it can be specifying an invalid JDBC URL--one that isn't  recognized by your JDBC driver. Your best bet is to check the documentation for your JDBC driver or contact your JDBC driver vendor if you suspect that the URL you are specifying is not being recognized by your JDBC driver.&lt;/p&gt; &lt;p&gt;In addition, when you are using the JDBC-ODBC Bridge, this error can occur if one or more the the shared libraries needed by the Bridge cannot be loaded. If you think this is the cause, check your configuration to be sure that the  shared libraries are accessible to the Bridge.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="10"&gt;9. Why isn't the &lt;code&gt;java.sql.DriverManager&lt;/code&gt; class being found?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="10"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;This problem can be caused by running a JDBC applet in a browser that supports the JDK 1.0.2, such as Netscape Navigator 3.0. The JDK 1.0.2 does not contain the JDBC API, so the &lt;code&gt;DriverManager&lt;/code&gt; class typically isn't found by the Java virtual machine running in the browser.&lt;/p&gt; &lt;p&gt;Here's a solution that doesn't require any additional configuration of your web clients. Remember that classes in the &lt;code&gt;java.*&lt;/code&gt; packages cannot be downloaded by most browsers for security reasons. Because of this, many vendors of all-Java JDBC drivers supply versions of the &lt;code&gt;java.sql.*&lt;/code&gt; classes that have been renamed to &lt;code&gt;jdbc.sql.*&lt;/code&gt;, along with a version of their driver that uses these modified classes.  If you import &lt;code&gt;jdbc.sql.*&lt;/code&gt; in your applet code instead of &lt;code&gt;java.sql.*&lt;/code&gt;, and add the &lt;code&gt;jdbc.sql.*&lt;/code&gt; classes provided by your JDBC driver vendor to your applet's  codebase, then all of the JDBC classes needed by the applet can be downloaded by the browser at run time, including the &lt;code&gt;DriverManager&lt;/code&gt; class.&lt;/p&gt; &lt;p&gt;This solution will allow your applet to work in any client browser that supports the JDK 1.0.2. Your applet will also work in browsers that support the JDK 1.1, although you may want to switch to the JDK 1.1 classes for performance reasons.  Also, keep in mind that the solution outlined here is just an example and that other solutions are possible.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="11"&gt;10. How do I retrieve a whole row of data at once, instead of  calling an individual &lt;code&gt;ResultSet.getXXX&lt;/code&gt; method for each column?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="11"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;The &lt;code&gt;ResultSet.getXXX&lt;/code&gt; methods are the only way to retrieve data from a &lt;code&gt;ResultSet&lt;/code&gt; object, which means that you have to make a method call for each column of a row. It is unlikely that  this is the cause of a performance problem, however, because it is difficult to see how a column could be fetched without at least the cost of a function call in any scenario. We welcome input from developers on this issue.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="12"&gt;11. Why does the ODBC driver manager return 'Data source name not found and no default driver specified Vendor: 0'&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="12"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;This type of error occurs during an attempt to connect to a database with the bridge.   First, note that the error is coming from the ODBC driver manager. This indicates that the  bridge-which is a normal ODBC client-has successfully called ODBC, so the problem isn't due  to native libraries not being present. In this case, it appears that the error is due to the  fact that an ODBC DSN (data source name) needs to be configured on the client machine.   Developers often forget to do this, thinking that the bridge will magically find the DSN they  configured on their remote server machine.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="13"&gt;12. Are all the required JDBC drivers to establish connectivity to my database part of the JDK?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="13"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;No. There aren't any JDBC technology-enabled drivers bundled with the JDK 1.1.x or Java 2 Platform releases other than the JDBC-ODBC Bridge. So, developers need to get a driver and install it before they can  connect to a database. We are considering bundling JDBC technology- enabled drivers in the future.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="14"&gt;13. Is the JDBC-ODBC Bridge multi-threaded?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="14"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading. In addition, deadlocks can occur between locks held in the database and the semaphore used by the Bridge. We are thinking about removing the synchronized methods in the future. They were added originally to make things simple for folks writing Java programs that use a single-threaded ODBC driver.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="15"&gt;14. Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="15"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;No. You can open only one &lt;code&gt;Statement&lt;/code&gt; object per connection when you are using the JDBC-ODBC Bridge.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="16"&gt;15. Why can't I invoke the &lt;code&gt;ResultSet&lt;/code&gt; methods &lt;code&gt;afterLast&lt;/code&gt; and  &lt;code&gt;beforeFirst&lt;/code&gt; when the method &lt;code&gt;next&lt;/code&gt; works?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;You are probably using a driver implemented for the JDBC 1.0 API. You need to upgrade to a JDBC 2.0 driver that implements scrollable result sets. Also be sure that your code has created scrollable result sets and that the DBMS you are using supports them.    &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="17"&gt;16. How can I retrieve a &lt;code&gt;String&lt;/code&gt; or other object type without creating a new object each time?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="17"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt; Creating and garbage collecting potentially large numbers of objects (millions) unnecessarily can really hurt performance. It may be better to provide a way to retrieve data like strings using the JDBC API without always allocating a new object.&lt;/p&gt; &lt;p&gt;We are studying this issue to see if it is an area in which the JDBC API should be improved.  Stay tuned, and please send us any comments you have on this question.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="18"&gt;17. There is a method &lt;code&gt;getColumnCount&lt;/code&gt; in the JDBC API. Is there a similar method to find the number of rows in a result set?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="18"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;No, but it is easy to find the number of rows. If you are using a scrollable result set, &lt;code&gt;rs&lt;/code&gt;, you can call the methods &lt;code&gt;rs.last&lt;/code&gt; and then &lt;code&gt;rs.getRow&lt;/code&gt; to find out how many rows &lt;code&gt;rs&lt;/code&gt; has. If the result is not scrollable,  you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a &lt;code&gt;COUNT&lt;/code&gt; column in the &lt;code&gt;SELECT&lt;/code&gt; clause.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="19"&gt; 18. I would like to download the JDBC-ODBC Bridge for the Java 2 SDK, Standard Edition (formerly JDK 1.2). I'm a beginner with the JDBC API, and I would like to start with the Bridge.  How do I do it?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="19"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;The JDBC-ODBC Bridge is bundled with the Java 2 SDK, Standard  Edition, so there is no need to download it separately.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="20"&gt; 19. If I use the JDBC API, do I have to use ODBC underneath?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="20"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;No, this is just one of many possible solutions. We recommend using a pure Java JDBC technology-enabled driver, type 3 or 4, in order to get all of the benefits of the Java programming language and the JDBC API.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="21"&gt;20. Once I have the Java 2 SDK, Standard Edition, from Sun, what else do I need to connect to a database?&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;&lt;a name="21"&gt;&lt;br&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;You still need to get and install a JDBC technology-enabled driver that supports the database that you are using. There are many drivers available  from a variety of sources. You can also try using the JDBC-ODBC Bridge if you have ODBC connectivity set up already. The Bridge comes with the Java 2 SDK, Standard Edition, and Enterprise Edition, and it doesn't require any extra setup itself. The Bridge is a normal ODBC client. Note, however, that you should use the JDBC-ODBC Bridge only for experimental prototyping or when you have no other driver available.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;21. What are the different types of JDBC drivers?&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;br&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;JDBC technology drivers fit into one of four categories: &lt;/p&gt; &lt;ol&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt; A &lt;i&gt;JDBC-ODBC bridge&lt;/i&gt; provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client  code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important.  For information on the JDBC-ODBC bridge driver provided by Sun, see &lt;a href="http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html#996747"&gt; JDBC-ODBC Bridge Driver&lt;/a&gt;.  &lt;p&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;A &lt;i&gt;native-API partly Java technology-enabled driver&lt;/i&gt; converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.&lt;/li&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;A &lt;i&gt;net-protocol fully Java technology-enabled driver&lt;/i&gt; translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.&lt;/li&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;A &lt;i&gt;native-protocol fully Java technology-enabled driver&lt;/i&gt; converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress.&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;&lt;strong style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;22. Are there recommended programming practices for using JDBC connections?&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;The general rule is to get the connection from the connection pool as late as possible and give it back to the connection pool as soon as possible. Ensure that the connection is a method variable, and get and release the connection within the same method as where you use it (each thread should have its own connection). The cost of getting the connection is small, the prepared statement cache will reduce the preparation time, the set statements are small, the execute needs to be done no matter what the usage, and the close is small. It is not recommended to&lt;/p&gt;&lt;p&gt; create the connection at ejbCreate/activate and close it on ejbRemove/pasivate.&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;23. Why should I not use &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;DriverManager.getConnection&lt;/code&gt;&lt;span style="font-weight: bold;"&gt;?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501046"&gt;&lt;/a&gt;&lt;strong&gt;   &lt;/strong&gt; &lt;code style="font-family: courier;"&gt;DriverManager.getConnection&lt;/code&gt; can cause a deadlock. In the server, all &lt;code style="font-family: courier;"&gt;DriverManager&lt;/code&gt; calls are class-synchronized including many frequent calls that all drivers make, and JDBC drivers do a lot of synchronization internally. One long-waiting call can stop all JDBC work in the whole JVM and cause deadlocks. Also, you should not reregister the driver repeatedly. Regardless of the DBMS state, the one driver that is initially loaded at startup will always work. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;24. Can I use a prepared statement across multiple transactions?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501073"&gt;&lt;/a&gt;&lt;strong&gt;   &lt;/strong&gt; Yes. Every transaction uses a dedicated JDBC connection, and all database interaction needs to use this connection object in order to participate in the transaction. So a prepared statement is tied to a particular connection and can't be shared with other connections. But a prepared statement &lt;em&gt;can&lt;/em&gt; span transactions. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;25. Why do I get a &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;java.lang.AbstractMethodError&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; when calling a method on a driver?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501077"&gt;&lt;/a&gt;&lt;strong&gt;   &lt;/strong&gt; This usually indicates that the driver has not implemented the method. For instance, you might be calling a JDBC 3.0 method on a driver that has only implemented the JDBC 2.0 methods. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;26. Why do I get "ResourceException: No Resource Available"?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501093"&gt;&lt;/a&gt;&lt;strong&gt;   &lt;/strong&gt; One common reason is that you have too many consumers (connection users) for the number of configured JDBC connections in the connection pool or execute threads on the server. &lt;/p&gt; &lt;p&gt;&lt;a name="501095"&gt;&lt;/a&gt;Another reason may be that the refresh testing process has reserved one or more connections for testing so these connections are briefly unavailable. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;27. How do I ensure that a new database connection is created each time an EJB's  container-managed transaction is started (so that I get a new authentication/authorization each  time)?  &lt;/p&gt;&lt;p&gt;&lt;a style="font-weight: bold; color: rgb(255, 0, 0);" name="501099"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; The EJB should be tx-requires, which means it will start a transaction when called if one is not underway already, or will join the transaction in progress if there is one. Your code will use the standard JTS/JTA API to obtain and start a UserTransaction. Then you should obtain your JDBC connection from a tx data source, and it will be included in the transaction. To get a new connection each time, you could use the dynamic pool API to make a one-connection pool. We suggest configuring the server to have a one-connection pool and a tx data source for it at startup. Then when you want to do a transaction in an external client, you would destroy the initial pool and recreate it with the DBMS user you want. This will allow you to use the tx data source to get a connection, which if obtained in the context of a running UserTransaction, will get automatically included in the tx. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;28. If it is a WebLogic DataSource, then you get a stub for the Connection instance, not a connection pool in the local process.&lt;/p&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;If a distributed transaction involves JMS and JDBC, how do I ensure that the JDBC update is  available when the JMS message is processed?&lt;/span&gt;&lt;br style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;br&gt;  &lt;p&gt;&lt;a name="501107"&gt;&lt;/a&gt;&lt;strong&gt;   &lt;/strong&gt; The problem is that an application can receive the JMS message from the destination before the associated JDBC data is in the database. &lt;/p&gt; &lt;p&gt;&lt;a name="501110"&gt;&lt;/a&gt;Distributed transactions guarantee all involved changes will either succeed or fail as a unit, but cannot guarantee that they will happen exactly simultaneously (the transaction manager instructs all resource managers to commit but cannot control the timing of the completion of that operation). &lt;/p&gt;   &lt;p&gt;&lt;a name="501111"&gt;&lt;/a&gt;For the WebLogic transaction manager, if the JDBC connection pool and the JMS server are both on the same server, and the transaction starts on the same server, the changes are committed in the order in which they were asked for by the transaction. This is not supported behavior, it just happens to be the current behavior. So if you can co-locate JMS and the JDBC connection pool, then you may have a chance.&lt;/p&gt;   &lt;p&gt;&lt;a name="501112"&gt;&lt;/a&gt;You could send the JMS message with a delayed birth-time, and hope that this is good enough. &lt;/p&gt;   &lt;p&gt;&lt;a name="501113"&gt;&lt;/a&gt;If the receiver fails to find the associated JDBC record, it could rollback/recover the message. You could use the WebLogic JMS redelivery delay feature to prevent the message from being redelivered instantly. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;29. If an application calls &lt;code style="font-family: courier;"&gt;DataSource.getConnection&lt;/code&gt; multiple times in the same thread and  transaction, will WebLogic Server handle giving me the same connection and transaction?  &lt;/p&gt;&lt;p&gt;&lt;a style="font-weight: bold; color: rgb(255, 0, 0);" name="501117"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; A common scenario might be to have multiple methods that are called within a transaction (begin/commit) that do something like the following:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501119"&gt;&lt;/a&gt;Context ctx = new InitialContext();&lt;br&gt;DataSource ds = (javax.sql.DataSource) ctx.lookup("connpoll");&lt;br&gt;// work using Connection&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501123"&gt;&lt;/a&gt;In this case, all of the work will be done within the transaction and the same underlying JDBC connection will be used as long as the DataSource &lt;code style="font-family: courier;"&gt;ds&lt;/code&gt; is a tx data source. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;30.  Why do I get a SystemException failure when trying to enlist my XAResource in a client?&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;WebLogic Server does not allow you to register or enlist an XA resource on a client. The reason for this restriction is that a client is deemed to be less reliable than a server in terms of availability. This is also why a client is not allowed to act as a transaction coordinator and register Synchronization objects. &lt;/p&gt; &lt;p&gt;&lt;a name="501133"&gt;&lt;/a&gt;Your client could invoke a remote object on a server that accesses the resource within a transaction. If it's a JDBC resource, then you can configure a JDBCConnectionPool and JDBCTxDataSource using an Oracle XA driver (Oracle thin or WebLogic Type 4 driver for Oracle) and obtain a connection from the data source. Or the client could look up the data source using JNDI and retrieve and manipulate a connection in a transaction. Transaction enlistment is performed automatically. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;31.  What causes an &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;OCIW32.dll&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; error?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501155"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;You may see the following error message when using your JDBC driver for Oracle: "The ordinal 40 could not be loaded in the dynamic link library OCIW32.dll." This problem is caused by an out-of-date version of OCIW32.DLL in your system directory. Some programs install this file in the system directory in order to run. If you remove this file from the system directory you should no longer receive this error. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;32. What type of object is returned by &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;ResultSet.getObject()&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; when using the WebLogic  jDriver for Oracle?&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;a name="501236"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; WebLogic jDriver for Oracle always returns a Java object that preserves the precision of the data retrieved. It returns the following from the &lt;code style="font-family: courier;"&gt;getObject()&lt;/code&gt; method: &lt;/p&gt;&lt;ul type="square"&gt;&lt;li type="square"&gt;&lt;a name="501239"&gt;&lt;/a&gt;For columns of types NUMBER(n) and NUMBER(m,n): a Double is returned if the defined precision of the column can be represented by a Double; otherwise BigDecimal is returned. &lt;/li&gt;&lt;li type="square"&gt;&lt;a name="501241"&gt;&lt;/a&gt;For columns of type NUMBER: Because there is no explicit precision, the Java type to return is determined based on the actual value in each row, and this may vary from row to row. An Integer is returned if the value has a zero-valued fractional component and the value can be represented by an integer. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="501242"&gt;&lt;/a&gt;For example, 1.0000 will be an integer. A long is returned for a value such as 123456789123.00000. If a value has a non-zero fractional component, a Double is returned if the precision of the value can be represented by a Double; otherwise a BigDecimal is returned. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;33. How do I call Oracle stored procedures that take no parameters?&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501250"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; Try this: &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501252"&gt;&lt;/a&gt;  CallableStatement cstmt = conn.prepareCall("Begin procName;&lt;br&gt;      END;");&lt;br&gt;  cstmt.execute();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501255"&gt;&lt;/a&gt;where &lt;code style="font-family: courier;"&gt;procName&lt;/code&gt; is the name of an Oracle stored procedure. This is standard Oracle SQL syntax that works with any Oracle DBMS. You can also use the following syntax: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501257"&gt;&lt;/a&gt; CallableStatement cstmt = conn.prepareCall("{call procName};");&lt;br&gt;  cstmt.execute();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501259"&gt;&lt;/a&gt;This code, which conforms to the Java Extended SQL specification, will work with any DBMS, not just Oracle. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;34. How do I bind string values in a PreparedStatement?&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;a name="501263"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; Suppose you are trying to get the PreparedStatement class to bind Strings in a statement. The &lt;code style="font-family: courier;"&gt;setString()&lt;/code&gt; method doesn't seem to work. Here is how you have set up the PreparedStatement: &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501265"&gt;&lt;/a&gt;  String pstmt = "select n_name from n_table where n_name LIKE '?%'";&lt;br&gt;  PreparedStatement ps = conn.prepareStatement(pstmt);&lt;br&gt;  ps.setString(1, "SMIT");&lt;br&gt;  ResultSet rs = ps.executeQuery();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501269"&gt;&lt;/a&gt;The preceding code does not work because the complete value needs to be specified in a String (without using embedded quotes) and then bound to an unquoted question mark (?). Here is the corrected code: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501271"&gt;&lt;/a&gt;  String matchvalue = "smit%";&lt;br&gt;  String pstmt = "select n_name from n_table where n_name LIKE ?";&lt;br&gt;  PreparedStatement ps = conn.prepareStatement(pstmt);&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501275"&gt;&lt;/a&gt;  ps.setString(1, matchvalue);&lt;br&gt;  ResultSet rs = ps.executeQuery();&lt;br&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;35. Why do I get unexpected characters from 8-bit character sets in WebLogic jDriver for Oracle?&lt;/span&gt;  &lt;p&gt;&lt;a name="501280"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; If you are using an Oracle database with an 8-bit character set on Solaris, make sure you set NLS_LANG to the proper value on the client. If NLS_LANG is not set, it defaults to a 7-bit ASCII character set, and tries to map characters greater than ASCII 128 to a reasonable approximation (for example, &amp;amp;aacute;, &amp;amp;agrave;, &amp;amp;acirc; would all map to a). Other characters are mapped to a question mark (?). &lt;/p&gt;&lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;36. How do I learn what codesets are available in Oracle?&lt;/span&gt;  &lt;p&gt;&lt;a name="501284"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;To find out what codesets you currently have available in Oracle, execute the following SQL query from SQLPlus at the command line: &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501286"&gt;&lt;/a&gt; SQL&amp;gt; SELECT value FROM v$nls_valid_values&lt;br&gt;          WHERE parameter='CHARACTERSET';&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501288"&gt;&lt;/a&gt;The response lists all codesets currently installed on your system. This listing will look something like the following shortened list: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501290"&gt;&lt;/a&gt;  VALUE&lt;br&gt;  -----------------------------------------------------------&lt;br&gt;  US7ASCII&lt;br&gt;  WE8DEC&lt;br&gt;  WE8HP&lt;br&gt;  US8PC437&lt;br&gt;  WE8EBCDIC37&lt;br&gt;  WE8EBCDIC500&lt;br&gt;  WE8EBCDIC285&lt;br&gt;  ...&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501300"&gt;&lt;/a&gt;If you want to constrain the value in the query to a specific codeset you are searching for, you can use a SQL query like the following: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501302"&gt;&lt;/a&gt; SQL&amp;gt; SELECT value FROM v$nls_valid_values &lt;br&gt;          WHERE parameter='CHARACTERSET' and VALUE='AL24UTFFSS';&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501304"&gt;&lt;/a&gt;This would produce the following response if the codeset is installed: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501306"&gt;&lt;/a&gt;  VALUE&lt;br&gt;  -------------------------------------------------------------&lt;br&gt;  AL24UTFFSS&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501310"&gt;&lt;/a&gt;You can use Oracle's installation tools to install additional codesets. Contact Oracle for more information. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;37. How do I look up an "ORA" SQLException?&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;If your WebLogic jDriver for Oracle application produces an SQLException, you can look up the Oracle error by using the oerr command. For example, if you see the following SQLException: &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501316"&gt;&lt;/a&gt;  java.sql.SQLException: ORA-12536: TNS: operation would block&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501317"&gt;&lt;/a&gt;You can find the description of error ORA-12536 can be found with the command: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501319"&gt;&lt;/a&gt;  &amp;gt; oerr ora 12536&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;38. What is error "ORA-6502?"&lt;/span&gt;  &lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;The default length of a string bound to an OUTPUT parameter of a CallableStatement is 128 characters. If the value you assign to the bound parameter exceeds that length, you will get this error. &lt;/p&gt; &lt;p&gt;&lt;a name="501325"&gt;&lt;/a&gt;You can adjust the length of the value of the bound parameter by passing an explicit length with the scale argument to the &lt;code style="font-family: courier;"&gt;CallableStatement.registerOutputParameter()&lt;/code&gt; method. &lt;/p&gt;&lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;39. Why do I get an error while trying to retrieve the text for ORA-12705?&lt;/span&gt; &lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;This error occurs when you have not set the ORACLE_HOME environment variable properly. In order to use WebLogic jDriver for Oracle, the Oracle client software needs to be installed and ORACLE_HOME must be set. &lt;/p&gt; &lt;p&gt;&lt;a name="501333"&gt;&lt;/a&gt;You may also see this error message if you try to use WebLogic jDriver for Oracle's internationalization capabilities with a language/codeset combination that is not installed on your system. If you get the ORA-12705 error with the correct error text, then either you have set NLS_LANG improperly, or you do not have the right codesets installed on your system. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;40. Why do I run out of resources during updates with Oracle's database link?&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;When you use Oracle's database link to update your database, you may get error "maximum number of temporary table locks exceeded" even if you close your result sets and statements when you finish.&lt;/p&gt; &lt;p&gt;&lt;a name="501339"&gt;&lt;/a&gt;The database link is an object in the local database that allows you to access tables, views, and so forth in a remote database. The database link is controlled by the Oracle server, so the driver has no control over its use of resources. The link appears to perform the commit (since other processes could see the records that were being created), but it doesn't free any resources until the connection is closed. The solution is to remove the database link and use the JDBC driver to do your selects, inserts, and updates. &lt;/p&gt;  &lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;41. Why does executing the PreparedStatement class cause a "TRUNC fails: ORA-00932:  inconsistent datatypes" error?&lt;/span&gt;  &lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;According to Oracle Metalink Bug Database Doc ID: 144784.1, in the absence of explicit data typecasting, OCI assumes that a bind variable is a CHAR data type. If the SQL statement intends to use the bind variable as a DATE data type, but OCI thought it was a CHAR, the SQL parser will have a conflict in data types. The fix is to explicitly use data conversion functions to convert the bind variables in the problem queries. For example, a select string of &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501384"&gt;&lt;/a&gt;String st = "select count(*) from simple_table where TRUNC(mydate) = TRUNC(?)"; &lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a name="501385"&gt;&lt;/a&gt;should be changed to: &lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501387"&gt;&lt;/a&gt;String st = "select count(*) from simple_table where TRUNC(mydate) = TRUNC(TO_DATE(?))";&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;42. &lt;/span&gt;&lt;strong style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; How do I create and update Oracle Blob fields?&lt;/span&gt;  &lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;The following code sample shows how to create and update Oracle Blob fields.&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501393"&gt;&lt;/a&gt;public void insert() throws SQLException {&lt;br&gt;  try {&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501398"&gt;&lt;/a&gt;    // Connect to the database using WebLogic JDBC connection pool&lt;br&gt;    Hashtable ht = new Hashtable();&lt;br&gt;    ht.put(Context.INITIAL_CONTEXT_FACTORY,&lt;br&gt;      "weblogic.jndi.WLInitialContextFactory");&lt;br&gt;    ht.put(Context.PROVIDER_URL, "t3://localhost:7001");&lt;br&gt;    InitialContext ctx = new InitialContext(ht);&lt;br&gt;    javax.sql.DataSource ds = (javax.sql.DataSource)&lt;br&gt;      ctx.lookup("java:comp/env/jdbc/DSName");&lt;br&gt;    Connection conn = ds.getConnection();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501422"&gt;&lt;/a&gt;    // This is necessary in any case where you are doing&lt;br&gt;    // a select for update. Not doing this will result in a ORA-1002&lt;br&gt;    conn.setAutoCommit (false);&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501426"&gt;&lt;/a&gt;    BLOB blob = null;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501428"&gt;&lt;/a&gt;    // Create a Statement&lt;br&gt;    Statement stmt = conn.createStatement ();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501431"&gt;&lt;/a&gt;    // Drop the table if it exists&lt;br&gt;    try {&lt;br&gt;      stmt.execute ("drop table ImageTable");&lt;br&gt;      System.out.println("Table droped ...");&lt;br&gt;    }&lt;br&gt;    catch (SQLException e) {&lt;br&gt;      System.out.println("Table does not exist");&lt;br&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501440"&gt;&lt;/a&gt;    // Create the table&lt;br&gt;    stmt.execute ("create table ImageTable (column1 varchar2(20),&lt;br&gt;      image BLOB)");&lt;br&gt;    System.out.println("Table created ...");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501445"&gt;&lt;/a&gt;    // create a blob entry in the table&lt;br&gt;    stmt.execute("insert into ImageTable values ('one', empty_blob())");&lt;br&gt;    stmt.execute("commit");&lt;br&gt;    System.out.println("inserted empty blob");&lt;br&gt;    String cmd = "select * from ImageTable for update";&lt;br&gt;    ResultSet rset = stmt.executeQuery(cmd);&lt;br&gt;    if (rset.next())  {&lt;br&gt;          blob = ((OracleResultSet)rset).getBLOB(2);&lt;br&gt;          System.out.println("got blob reference");&lt;br&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501455"&gt;&lt;/a&gt;    else System.out.println("no row to get!!!!");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501457"&gt;&lt;/a&gt;    rset.close();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501459"&gt;&lt;/a&gt;    blob = readFromFile();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501461"&gt;&lt;/a&gt;    cmd = "update ImageTable set image = ? where column1 = 'one'";&lt;br&gt;    PreparedStatement pstmt = conn.prepareStatement(cmd);&lt;br&gt;    pstmt.setBlob(1, blob);&lt;br&gt;    pstmt.execute();&lt;br&gt;    stmt.execute("commit");&lt;br&gt;    System.out.println("blob updated");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="503037"&gt;&lt;/a&gt;    blob = null;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501470"&gt;&lt;/a&gt;    cmd = "select * from ImageTable for update";&lt;br&gt;    rset = stmt.executeQuery(cmd);&lt;br&gt;    if (rset.next())  {&lt;br&gt;      System.out.println("get blob");&lt;br&gt;      blob = ((OracleResultSet)rset).getBLOB(2);&lt;br&gt;      // do something with blob&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501476"&gt;&lt;/a&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501477"&gt;&lt;/a&gt;    else&lt;br&gt;      System.out.println("no row to get (2)!!!!");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501479"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501480"&gt;&lt;/a&gt;  catch (SQLException sqle) {&lt;br&gt;    System.out.println("SQL Exception occured: " + sqle.getMessage());&lt;br&gt;    sqle.printStackTrace();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501483"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501484"&gt;&lt;/a&gt;  catch(FileNotFoundException e) {&lt;br&gt;    System.out.println("File Not Found");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501486"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501487"&gt;&lt;/a&gt;  catch (IOException ioe) {&lt;br&gt;    System.out.println("IO Exception" + ioe.getMessage());&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501489"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501490"&gt;&lt;/a&gt;  catch (Exception ioe) {&lt;br&gt;    System.out.println("Exception" + ioe.getMessage());&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501492"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501493"&gt;&lt;/a&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;43. How do I enlist an Oracle XAResource?&lt;/span&gt;  &lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;This code will only work on the server side. It cannot be run in a client. Also note that enlistment is generally done transparently for JDBC resources that implement XAResource. &lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501501"&gt;&lt;/a&gt;// Here is the XAResource for oracle&lt;br&gt;String URL = "jdbc:oracle:thin:@DbmsHost:DbmsPort:DbmsName";&lt;br&gt;DriverManager.registerDriver(new OracleDriver());&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501506"&gt;&lt;/a&gt;// Create XA Connection&lt;br&gt;OracleXADataSource oxds1 = new OracleXADataSource();&lt;br&gt;oxds1.setURL(URL);&lt;br&gt;oxds1.setUser("scott");&lt;br&gt;oxds1.setPassword("tiger");&lt;br&gt;javax.sql.XAConnection pc1  = oxds1.getXAConnection();&lt;br&gt;m_oracleResource = pc1.getXAResource ();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501514"&gt;&lt;/a&gt;m_oracleConnection = pc1.getConnection();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501516"&gt;&lt;/a&gt;// Here is the source code for getting the TM.&lt;br&gt;Context ctx = null;&lt;br&gt;Hashtable env = new Hashtable();&lt;br&gt;env.put(Context.INITIAL_CONTEXT_FACTORY,&lt;br&gt;"weblogic.jndi.WLInitialContextFactory");&lt;br&gt;// Parameters for the WebLogic Server.&lt;br&gt;// Substitute the correct hostname, port number&lt;br&gt;// user name, and password for your environment:&lt;br&gt;env.put(Context.PROVIDER_URL, "t3://localhost:7001");&lt;br&gt;env.put(Context.SECURITY_PRINCIPAL, "system");&lt;br&gt;env.put(Context.SECURITY_CREDENTIALS, "managers");&lt;br&gt;ctx = new InitialContext(env);&lt;br&gt;m_tManager =&lt;br&gt;(TransactionManager)ctx.lookup("javax.transaction.TransactionManager");&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501532"&gt;&lt;/a&gt;//Here is the source code for registering the TM.&lt;br&gt;m_tManager.begin();&lt;br&gt;m_transaction = m_tManager.getTransaction();&lt;br&gt;weblogic.transaction.TransactionManager weblogicTManager =&lt;br&gt;((weblogic.transaction.TransactionManager) m_tManager);&lt;br&gt;weblogicTManager.registerStaticResource("oracle",m_oracleResource);&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501540"&gt;&lt;/a&gt;// enlist the resources with the transaction&lt;br&gt;m_transaction.enlistResource(m_oracleResource);&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;44. Why do I get "ORA-00600" ?&lt;/span&gt;  &lt;p&gt;&lt;a name="501546"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; This error generally means that version of Oracle server is newer than version of the driver you are using. In case you are using the Oracle thin driver, you will need to download the latest &lt;code style="font-family: courier;"&gt;ojdbc14.jar&lt;/code&gt; from Oracle and put it at the beginning of your CLASSPATH (and possibly update any scripts that start the server, such as &lt;code style="font-family: courier;"&gt;startweblogic.cmd&lt;/code&gt;, since they override the CLASSPATH). &lt;/p&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;45. Why do I get "ORA-24327" ?&lt;/span&gt;&lt;/span&gt;  &lt;p&gt;&lt;a name="501550"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;This error generally means that the environment ORACLE_HOME is not set or is set incorrectly or the D_LIBRARY_PATH or PATH does not include the right dynamic link libraries. It can also indicate a mismatch when trying to use &lt;code style="font-family: courier;"&gt;weblogic.jdbc.oci.Driver&lt;/code&gt; with an earlier or later version of the Oracle client software than is supported. In that case, try to use the Oracle Thin driver instead. &lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;46. &lt;/span&gt;&lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt; Why do I get "java.sql.SQLException: getOBJECT is not supported by the WebLogic JDBC  Driver"?&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;a name="501554"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;   &lt;/strong&gt; When using the WebLogic JDBC connection pool and &lt;code style="font-family: courier;"&gt;weblogic.jdbc.vendor.oracle.OracleResultSet&lt;/code&gt;, the error is returned (where OBJECT is the name of some Oracle object). It implies that this feature is not supported by WebLogic Server JDBC because the object type is not serializable. There are two alternatives. &lt;/p&gt;&lt;ul type="square"&gt;&lt;li type="square"&gt;&lt;a name="501556"&gt;&lt;/a&gt;You can switch to using the Oracle thin driver directly. That means that you will get a connection directly to the database using the Thin driver instead of getting the connection from a pool of JDBC connections. That means that you lose all advantages of using the WebLogic Server JDBC subsystem, such as transactions, connection pooling, and caching of prepared statements.&lt;/li&gt;&lt;li type="square"&gt;&lt;a name="501557"&gt;&lt;/a&gt;BEA recommends moving your processing to a stored procedure.&lt;/li&gt;&lt;li type="square"&gt;&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;47. Why do I get an "ORA-01453" when I use SET TRANSACTION?&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;When using Oracle, the message "java.sql.SQLException: ORA-01453: SET TRANSACTION must be first statement of transaction" may be logged. This is due to a limitation in the Oracle interfaces, starting in Oracle 8.1.7. WebLogic tries to minimize the problem by not calling SET TRANSACTION if the mode already matches the current state. &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-3903087605007073679?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/3903087605007073679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=3903087605007073679' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/3903087605007073679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/3903087605007073679'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-2928649363615954930</id><published>2007-01-18T17:39:00.004-08:00</published><updated>2007-01-18T17:41:39.147-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;font size="2"&gt; &lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;div style="text-align: left;"&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold; font-style: italic;"&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;br&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;41. Why does executing the PreparedStatement class cause a "TRUNC fails: ORA-00932: inconsistent datatypes" error?&lt;/span&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;According to Oracle Metalink Bug Database Doc ID: 144784.1, in the absence of explicit data typecasting, OCI assumes that a bind variable is a CHAR data type. If the SQL statement intends to use the bind variable as a DATE data type, but OCI thought it was a CHAR, the SQL parser will have a conflict in data types. The fix is to explicitly use data conversion functions to convert the bind variables in the problem queries. For example, a select string of &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501384"&gt;&lt;/a&gt;String st = "select count(*) from simple_table where TRUNC(mydate) = TRUNC(?)"; &lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501385"&gt;&lt;/a&gt;should be changed to: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501387"&gt;&lt;/a&gt;String st = "select count(*) from simple_table where TRUNC(mydate) = TRUNC(TO_DATE(?))";&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;42. &lt;/span&gt;&lt;strong style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; How do I create and update Oracle Blob fields?&lt;/span&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;The following code sample shows how to create and update Oracle Blob fields. &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501393"&gt;&lt;/a&gt;public void insert() throws SQLException {&lt;br&gt;  try {&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501398"&gt;&lt;/a&gt;    // Connect to the database using WebLogic JDBC connection pool&lt;br&gt;    Hashtable ht = new Hashtable();&lt;br&gt;    ht.put(Context.INITIAL_CONTEXT_FACTORY,&lt;br&gt;      "weblogic.jndi.WLInitialContextFactory");&lt;br&gt;    ht.put(Context.PROVIDER_URL, "t3://localhost:7001");&lt;br&gt;    InitialContext ctx = new InitialContext(ht);&lt;br&gt;    javax.sql.DataSource ds = (javax.sql.DataSource)&lt;br&gt;      ctx.lookup("java:comp/env/jdbc/DSName");&lt;br&gt;    Connection conn = ds.getConnection();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501422"&gt;&lt;/a&gt;    // This is necessary in any case where you are doing&lt;br&gt;    // a select for update. Not doing this will result in a ORA-1002&lt;br&gt;    conn.setAutoCommit (false);&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501426"&gt;&lt;/a&gt;    BLOB blob = null;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501428"&gt;&lt;/a&gt;    // Create a Statement&lt;br&gt;    Statement stmt = conn.createStatement ();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501431"&gt;&lt;/a&gt;    // Drop the table if it exists&lt;br&gt;    try {&lt;br&gt;      stmt.execute ("drop table ImageTable");&lt;br&gt;      System.out.println("Table droped ...");&lt;br&gt;    }&lt;br&gt;    catch (SQLException e) {&lt;br&gt;      System.out.println("Table does not exist");&lt;br&gt;    }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501440"&gt;&lt;/a&gt;    // Create the table&lt;br&gt;    stmt.execute ("create table ImageTable (column1 varchar2(20),&lt;br&gt;      image BLOB)");&lt;br&gt;    System.out.println("Table created ...");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501445"&gt;&lt;/a&gt;    // create a blob entry in the table&lt;br&gt;    stmt.execute("insert into ImageTable values ('one', empty_blob())");&lt;br&gt;    stmt.execute("commit");&lt;br&gt;    System.out.println("inserted empty blob");&lt;br&gt;    String cmd = "select * from ImageTable for update";&lt;br&gt;    ResultSet rset = stmt.executeQuery(cmd);&lt;br&gt;    if (rset.next())  {&lt;br&gt;          blob = ((OracleResultSet)rset).getBLOB(2);&lt;br&gt;          System.out.println("got blob reference");&lt;br&gt;    }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501455"&gt;&lt;/a&gt;    else System.out.println("no row to get!!!!");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501457"&gt;&lt;/a&gt;    rset.close();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501459"&gt;&lt;/a&gt;    blob = readFromFile();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501461"&gt;&lt;/a&gt;    cmd = "update ImageTable set image = ? where column1 = 'one'";&lt;br&gt;    PreparedStatement pstmt = conn.prepareStatement(cmd);&lt;br&gt;    pstmt.setBlob(1, blob);&lt;br&gt;    pstmt.execute();&lt;br&gt;    stmt.execute("commit");&lt;br&gt;    System.out.println("blob updated");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="503037"&gt;&lt;/a&gt;    blob = null;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501470"&gt;&lt;/a&gt;    cmd = "select * from ImageTable for update";&lt;br&gt;    rset = stmt.executeQuery(cmd);&lt;br&gt;    if (rset.next())  {&lt;br&gt;      System.out.println("get blob");&lt;br&gt;      blob = ((OracleResultSet)rset).getBLOB(2);&lt;br&gt;      // do something with blob&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501476"&gt;&lt;/a&gt;    }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501477"&gt;&lt;/a&gt;    else&lt;br&gt;      System.out.println("no row to get (2)!!!!");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501479"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501480"&gt;&lt;/a&gt;  catch (SQLException sqle) {&lt;br&gt;    System.out.println("SQL Exception occured: " + sqle.getMessage());&lt;br&gt;    sqle.printStackTrace();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501483"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501484"&gt;&lt;/a&gt;  catch(FileNotFoundException e) {&lt;br&gt;    System.out.println("File Not Found");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501486"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501487"&gt;&lt;/a&gt;  catch (IOException ioe) {&lt;br&gt;    System.out.println("IO Exception" + ioe.getMessage());&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501489"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501490"&gt;&lt;/a&gt;  catch (Exception ioe) {&lt;br&gt;    System.out.println("Exception" + ioe.getMessage());&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501492"&gt;&lt;/a&gt;  }&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501493"&gt;&lt;/a&gt;}&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;43. How do I enlist an Oracle XAResource?&lt;/span&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;This code will only work on the server side. It cannot be run in a client. Also note that enlistment is generally done transparently for JDBC resources that implement XAResource. &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501501"&gt;&lt;/a&gt;// Here is the XAResource for oracle&lt;br&gt;String URL = "jdbc:oracle:thin:@DbmsHost:DbmsPort:DbmsName";&lt;br&gt;DriverManager.registerDriver(new OracleDriver());&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501506"&gt;&lt;/a&gt;// Create XA Connection&lt;br&gt;OracleXADataSource oxds1 = new OracleXADataSource();&lt;br&gt;oxds1.setURL(URL);&lt;br&gt;oxds1.setUser("scott");&lt;br&gt;oxds1.setPassword("tiger");&lt;br&gt;javax.sql.XAConnection pc1  = oxds1.getXAConnection();&lt;br&gt;m_oracleResource = pc1.getXAResource ();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501514"&gt;&lt;/a&gt;m_oracleConnection = pc1.getConnection();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501516"&gt;&lt;/a&gt;// Here is the source code for getting the TM.&lt;br&gt;Context ctx = null;&lt;br&gt;Hashtable env = new Hashtable();&lt;br&gt;env.put(Context.INITIAL_CONTEXT_FACTORY,&lt;br&gt;"weblogic.jndi.WLInitialContextFactory");&lt;br&gt;// Parameters for the WebLogic Server.&lt;br&gt;// Substitute the correct hostname, port number&lt;br&gt;// user name, and password for your environment:&lt;br&gt;env.put(Context.PROVIDER_URL, "t3://localhost:7001");&lt;br&gt;env.put(Context.SECURITY_PRINCIPAL, "system");&lt;br&gt;env.put(Context.SECURITY_CREDENTIALS, "managers");&lt;br&gt;ctx = new InitialContext(env);&lt;br&gt;m_tManager =&lt;br&gt;(TransactionManager)ctx.lookup("javax.transaction.TransactionManager");&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501532"&gt;&lt;/a&gt;//Here is the source code for registering the TM.&lt;br&gt;m_tManager.begin();&lt;br&gt;m_transaction = m_tManager.getTransaction();&lt;br&gt;weblogic.transaction.TransactionManager weblogicTManager =&lt;br&gt;((weblogic.transaction.TransactionManager) m_tManager);&lt;br&gt;weblogicTManager.registerStaticResource("oracle",m_oracleResource);&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501540"&gt;&lt;/a&gt;// enlist the resources with the transaction&lt;br&gt;m_transaction.enlistResource(m_oracleResource);&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;44. Why do I get "ORA-00600" ?&lt;/span&gt; &lt;p&gt;   &lt;a name="501546"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; This error generally means that version of Oracle server is newer than version of the driver you are using. In case you are using the Oracle thin driver, you will need to download the latest &lt;code style="font-family: courier;"&gt;ojdbc14.jar&lt;/code&gt; from Oracle and put it at the beginning of your CLASSPATH (and possibly update any scripts that start the server, such as &lt;code style="font-family: courier;"&gt;startweblogic.cmd&lt;/code&gt;, since they override the CLASSPATH). &lt;/p&gt; &lt;span style="font-weight: bold;"&gt;&lt;br&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;45. Why do I get "ORA-24327" ?&lt;/span&gt;&lt;/span&gt; &lt;p&gt;   &lt;a name="501550"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;/span&gt;This error generally means that the environment ORACLE_HOME is not set or is set incorrectly or the D_LIBRARY_PATH or PATH does not include the right dynamic link libraries. It can also indicate a mismatch when trying to use &lt;code style="font-family: courier;"&gt;weblogic.jdbc.oci.Driver&lt;/code&gt; with an earlier or later version of the Oracle client software than is supported. In that case, try to use the Oracle Thin driver instead.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;46. &lt;/span&gt;&lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt; Why do I get "java.sql.SQLException: getOBJECT is not supported by the WebLogic JDBC Driver"?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501554"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; When using the WebLogic JDBC connection pool and &lt;code style="font-family: courier;"&gt;weblogic.jdbc.vendor.oracle.OracleResultSet&lt;/code&gt;, the error is returned (where OBJECT is the name of some Oracle object). It implies that this feature is not supported by WebLogic Server JDBC because the object type is not serializable. There are two alternatives. &lt;/p&gt; &lt;ul type="square"&gt;   &lt;li type="square"&gt;     &lt;a name="501556"&gt;&lt;/a&gt;You can switch to using the Oracle thin driver directly. That means that you will get a connection directly to the database using the Thin driver instead of getting the connection from a pool of JDBC connections. That means that you lose all advantages of using the WebLogic Server JDBC subsystem, such as transactions, connection pooling, and caching of prepared statements.   &lt;/li&gt;&lt;li type="square"&gt;     &lt;a name="501557"&gt;&lt;/a&gt;BEA recommends moving your processing to a stored procedure.   &lt;/li&gt;&lt;li type="square"&gt;     &lt;br&gt; &lt;/li&gt;&lt;/ul&gt; &lt;span style="font-weight: bold;"&gt;&lt;br&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;47. Why do I get an "ORA-01453" when I use SET TRANSACTION?&lt;br&gt; &lt;br&gt; &lt;/span&gt;&lt;/span&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;When using Oracle, the message "java.sql.SQLException: ORA-01453: SET TRANSACTION must be first statement of transaction" may be logged. This is due to a limitation in the Oracle interfaces, starting in Oracle 8.1.7. WebLogic tries to minimize the problem by not calling SET TRANSACTION if the mode already matches the current state. &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="font-weight: bold;"&gt;   Source : &lt;a href="http://www.javabeat.net" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt; &lt;/p&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-2928649363615954930?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/2928649363615954930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=2928649363615954930' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2928649363615954930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2928649363615954930'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or_18.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-8268797424098587842</id><published>2007-01-18T17:39:00.003-08:00</published><updated>2007-01-18T17:41:42.693-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;font size="2"&gt; &lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;div style="text-align: left;"&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold; font-style: italic;"&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;/div&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;/div&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;31.  What causes an &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;OCIW32.dll&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; error?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501155"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;You may see the following error message when using your JDBC driver for Oracle: "The ordinal 40 could not be loaded in the dynamic link library OCIW32.dll." This problem is caused by an out-of-date version of OCIW32.DLL in your system directory. Some programs install this file in the system directory in order to run. If you remove this file from the system directory you should no longer receive this error.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;32. What type of object is returned by &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;ResultSet.getObject()&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; when using the WebLogic jDriver for Oracle?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501236"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; WebLogic jDriver for Oracle always returns a Java object that preserves the precision of the data retrieved. It returns the following from the &lt;code style="font-family: courier;"&gt;getObject()&lt;/code&gt; method: &lt;/p&gt; &lt;ul type="square"&gt;   &lt;li type="square"&gt;     &lt;a name="501239"&gt;&lt;/a&gt;For columns of types NUMBER(n) and NUMBER(m,n): a Double is returned if the defined precision of the column can be represented by a Double; otherwise BigDecimal is returned.   &lt;/li&gt;&lt;li type="square"&gt;     &lt;a name="501241"&gt;&lt;/a&gt;For columns of type NUMBER: Because there is no explicit precision, the Java type to return is determined based on the actual value in each row, and this may vary from row to row. An Integer is returned if the value has a zero-valued fractional component and the value can be represented by an integer. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;   &lt;a name="501242"&gt;&lt;/a&gt;For example, 1.0000 will be an integer. A long is returned for a value such as 123456789123.00000. If a value has a non-zero fractional component, a Double is returned if the precision of the value can be represented by a Double; otherwise a BigDecimal is returned.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;33. How do I call Oracle stored procedures that take no parameters?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501250"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; Try this: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501252"&gt;&lt;/a&gt;  CallableStatement cstmt = conn.prepareCall("Begin procName;&lt;br&gt;      END;");&lt;br&gt;  cstmt.execute();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501255"&gt;&lt;/a&gt;where &lt;code style="font-family: courier;"&gt;procName&lt;/code&gt; is the name of an Oracle stored procedure. This is standard Oracle SQL syntax that works with any Oracle DBMS. You can also use the following syntax: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501257"&gt;&lt;/a&gt; CallableStatement cstmt = conn.prepareCall("{call procName};");&lt;br&gt;  cstmt.execute();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501259"&gt;&lt;/a&gt;This code, which conforms to the Java Extended SQL specification, will work with any DBMS, not just Oracle.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;34. How do I bind string values in a PreparedStatement?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501263"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; Suppose you are trying to get the PreparedStatement class to bind Strings in a statement. The &lt;code style="font-family: courier;"&gt;setString()&lt;/code&gt; method doesn't seem to work. Here is how you have set up the PreparedStatement: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501265"&gt;&lt;/a&gt;  String pstmt = "select n_name from n_table where n_name LIKE '?%'";&lt;br&gt;  PreparedStatement ps = conn.prepareStatement(pstmt);&lt;br&gt;  ps.setString(1, "SMIT");&lt;br&gt;  ResultSet rs = ps.executeQuery();&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501269"&gt;&lt;/a&gt;The preceding code does not work because the complete value needs to be specified in a String (without using embedded quotes) and then bound to an unquoted question mark (?). Here is the corrected code: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501271"&gt;&lt;/a&gt;  String matchvalue = "smit%";&lt;br&gt;  String pstmt = "select n_name from n_table where n_name LIKE ?";&lt;br&gt;  PreparedStatement ps = conn.prepareStatement(pstmt);&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501275"&gt;&lt;/a&gt;  ps.setString(1, matchvalue);&lt;br&gt;  ResultSet rs = ps.executeQuery();&lt;br&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;35. Why do I get unexpected characters from 8-bit character sets in WebLogic jDriver for Oracle?&lt;/span&gt; &lt;p&gt;   &lt;a name="501280"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; If you are using an Oracle database with an 8-bit character set on Solaris, make sure you set NLS_LANG to the proper value on the client. If NLS_LANG is not set, it defaults to a 7-bit ASCII character set, and tries to map characters greater than ASCII 128 to a reasonable approximation (for example, &amp;amp;aacute;, &amp;amp;agrave;, &amp;amp;acirc; would all map to a). Other characters are mapped to a question mark (?). &lt;/p&gt; &lt;br&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;36. How do I learn what codesets are available in Oracle?&lt;/span&gt; &lt;p&gt;   &lt;a name="501284"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;/span&gt;To find out what codesets you currently have available in Oracle, execute the following SQL query from SQLPlus at the command line: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501286"&gt;&lt;/a&gt; SQL&amp;gt; SELECT value FROM v$nls_valid_values&lt;br&gt;          WHERE parameter='CHARACTERSET';&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501288"&gt;&lt;/a&gt;The response lists all codesets currently installed on your system. This listing will look something like the following shortened list: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501290"&gt;&lt;/a&gt;  VALUE&lt;br&gt;  -----------------------------------------------------------&lt;br&gt;  US7ASCII&lt;br&gt;  WE8DEC&lt;br&gt;  WE8HP&lt;br&gt;  US8PC437&lt;br&gt;  WE8EBCDIC37&lt;br&gt;  WE8EBCDIC500&lt;br&gt;  WE8EBCDIC285&lt;br&gt;  ...&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501300"&gt;&lt;/a&gt;If you want to constrain the value in the query to a specific codeset you are searching for, you can use a SQL query like the following: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501302"&gt;&lt;/a&gt; SQL&amp;gt; SELECT value FROM v$nls_valid_values &lt;br&gt;          WHERE parameter='CHARACTERSET' and VALUE='AL24UTFFSS';&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501304"&gt;&lt;/a&gt;This would produce the following response if the codeset is installed: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501306"&gt;&lt;/a&gt;  VALUE&lt;br&gt;  -------------------------------------------------------------&lt;br&gt;  AL24UTFFSS&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501310"&gt;&lt;/a&gt;You can use Oracle's installation tools to install additional codesets. Contact Oracle for more information.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;37. How do I look up an "ORA" SQLException?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;If your WebLogic jDriver for Oracle application produces an SQLException, you can look up the Oracle error by using the oerr command. For example, if you see the following SQLException: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501316"&gt;&lt;/a&gt;  java.sql.SQLException: ORA-12536: TNS: operation would block&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501317"&gt;&lt;/a&gt;You can find the description of error ORA-12536 can be found with the command: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501319"&gt;&lt;/a&gt;  &amp;gt; oerr ora 12536&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;38. What is error "ORA-6502?"&lt;/span&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;The default length of a string bound to an OUTPUT parameter of a CallableStatement is 128 characters. If the value you assign to the bound parameter exceeds that length, you will get this error. &lt;/p&gt; &lt;p&gt;   &lt;a name="501325"&gt;&lt;/a&gt;You can adjust the length of the value of the bound parameter by passing an explicit length with the scale argument to the &lt;code style="font-family: courier;"&gt;CallableStatement.registerOutputParameter()&lt;/code&gt; method. &lt;/p&gt; &lt;br&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;39. Why do I get an error while trying to retrieve the text for ORA-12705?&lt;/span&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;This error occurs when you have not set the ORACLE_HOME environment variable properly. In order to use WebLogic jDriver for Oracle, the Oracle client software needs to be installed and ORACLE_HOME must be set. &lt;/p&gt; &lt;p&gt;   &lt;a name="501333"&gt;&lt;/a&gt;You may also see this error message if you try to use WebLogic jDriver for Oracle's internationalization capabilities with a language/codeset combination that is not installed on your system. If you get the ORA-12705 error with the correct error text, then either you have set NLS_LANG improperly, or you do not have the right codesets installed on your system.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;40. Why do I run out of resources during updates with Oracle's database link?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;br&gt;   &lt;strong&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;When you use Oracle's database link to update your database, you may get error "maximum number of temporary table locks exceeded" even if you close your result sets and statements when you finish. &lt;/p&gt; &lt;p&gt;   &lt;a name="501339"&gt;&lt;/a&gt;The database link is an object in the local database that allows you to access tables, views, and so forth in a remote database. The database link is controlled by the Oracle server, so the driver has no control over its use of resources. The link appears to perform the commit (since other processes could see the records that were being created), but it doesn't free any resources until the connection is closed. The solution is to remove the database link and use the JDBC driver to do your selects, inserts, and updates. &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="font-weight: bold;"&gt;   Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt; &lt;/p&gt; &lt;br&gt; &lt;br&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-8268797424098587842?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/8268797424098587842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=8268797424098587842' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8268797424098587842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8268797424098587842'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or_8197.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-4346652876707794118</id><published>2007-01-18T17:39:00.002-08:00</published><updated>2007-01-18T17:41:46.081-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;div style="text-align: center;"&gt; &lt;/div&gt;&lt;div style="text-align: center;"&gt;   &lt;/div&gt;&lt;div style="text-align: center;"&gt;   &lt;/div&gt;&lt;div style="text-align: center;"&gt;     &lt;/div&gt;&lt;div style="text-align: center;"&gt;     &lt;/div&gt;&lt;div style="text-align: center;"&gt;       &lt;/div&gt;&lt;div style="text-align: center;"&gt;       &lt;/div&gt;&lt;div style="text-align: center;"&gt;         &lt;/div&gt;&lt;div style="text-align: center;"&gt;         &lt;/div&gt;&lt;div style="text-align: center;"&gt;           &lt;/div&gt;&lt;div style="text-align: center;"&gt;           &lt;/div&gt;&lt;div style="text-align: center;"&gt;             &lt;/div&gt;&lt;div style="text-align: center;"&gt;             &lt;/div&gt;&lt;div style="text-align: center;"&gt;               &lt;/div&gt;&lt;div style="text-align: center;"&gt;               &lt;/div&gt;&lt;div style="text-align: center;"&gt;                 &lt;/div&gt;&lt;div style="text-align: center;"&gt;                 &lt;/div&gt;&lt;div style="text-align: center;"&gt;                   &lt;/div&gt;&lt;div style="text-align: center;"&gt;                   &lt;/div&gt;&lt;div style="text-align: center;"&gt;                     &lt;/div&gt;&lt;div style="text-align: center;"&gt;                     &lt;/div&gt;&lt;div style="text-align: center;"&gt;                       &lt;/div&gt;&lt;div style="text-align: center;"&gt;                       &lt;/div&gt;&lt;div style="text-align: center;"&gt;                         &lt;/div&gt;&lt;div style="text-align: center;"&gt;                         &lt;/div&gt;&lt;div style="text-align: center;"&gt;                           &lt;/div&gt;&lt;div style="text-align: center;"&gt;                           &lt;/div&gt;&lt;div style="text-align: center;"&gt;                             &lt;font size="2"&gt;                             &lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;div style="text-align: left;"&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold; font-style: italic;"&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;/div&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/font&gt;&lt;/div&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;                               21. What are the different types of JDBC drivers?                             &lt;/p&gt;                             &lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;                               &lt;br&gt;                             &lt;/p&gt;                             &lt;/font&gt;                           &lt;/p&gt;                           &lt;/font&gt;                         &lt;/p&gt;                         &lt;/font&gt;                       &lt;/p&gt;                       &lt;/font&gt;                     &lt;/p&gt;                     &lt;/font&gt;                   &lt;/p&gt;                   &lt;/font&gt;                 &lt;/p&gt;                 &lt;/font&gt;               &lt;/p&gt;               &lt;/font&gt;             &lt;/p&gt;             &lt;/font&gt;           &lt;/p&gt;           &lt;/font&gt;         &lt;/p&gt;         &lt;/font&gt;       &lt;/p&gt;       &lt;/font&gt;     &lt;/p&gt;     &lt;/font&gt;   &lt;/p&gt;   &lt;/font&gt; &lt;/p&gt; &lt;/font&gt; &lt;p&gt;   JDBC technology drivers fit into one of four categories: &lt;/p&gt; &lt;ol&gt;   &lt;p&gt;   &lt;/p&gt;   &lt;li&gt;     A &lt;i&gt;JDBC-ODBC bridge&lt;/i&gt; provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. For information on the JDBC-ODBC bridge driver provided by Sun, see &lt;a href="http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html#996747"&gt; JDBC-ODBC Bridge Driver&lt;/a&gt;.     &lt;p&gt;     &lt;/p&gt;   &lt;/li&gt;&lt;li&gt;     A &lt;i&gt;native-API partly Java technology-enabled driver&lt;/i&gt; converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.     &lt;p&gt;     &lt;/p&gt;   &lt;/li&gt;&lt;li&gt;     A &lt;i&gt;net-protocol fully Java technology-enabled driver&lt;/i&gt; translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.     &lt;p&gt;     &lt;/p&gt;   &lt;/li&gt;&lt;li&gt;     A &lt;i&gt;native-protocol fully Java technology-enabled driver&lt;/i&gt; converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress. &lt;/li&gt;&lt;/ol&gt; &lt;br&gt; &lt;strong style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;22. Are there recommended programming practices for using JDBC connections?&lt;/span&gt;&lt;br&gt; &lt;br&gt; &lt;/span&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;The general rule is to get the connection from the connection pool as late as possible and give it back to the connection pool as soon as possible. Ensure that the connection is a method variable, and get and release the connection within the same method as where you use it (each thread should have its own connection). The cost of getting the connection is small, the prepared statement cache will reduce the preparation time, the set statements are small, the execute needs to be done no matter what the usage, and the close is small. It is not recommended to &lt;/p&gt; &lt;p&gt;   create the connection at ejbCreate/activate and close it on ejbRemove/pasivate. &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;23. Why should I not use &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;DriverManager.getConnection&lt;/code&gt;&lt;span style="font-weight: bold;"&gt;?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501046"&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; &lt;code style="font-family: courier;"&gt;DriverManager.getConnection&lt;/code&gt; can cause a deadlock. In the server, all &lt;code style="font-family: courier;"&gt;DriverManager&lt;/code&gt; calls are class-synchronized including many frequent calls that all drivers make, and JDBC drivers do a lot of synchronization internally. One long-waiting call can stop all JDBC work in the whole JVM and cause deadlocks. Also, you should not reregister the driver repeatedly. Regardless of the DBMS state, the one driver that is initially loaded at startup will always work.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;24. Can I use a prepared statement across multiple transactions?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501073"&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; Yes. Every transaction uses a dedicated JDBC connection, and all database interaction needs to use this connection object in order to participate in the transaction. So a prepared statement is tied to a particular connection and can't be shared with other connections. But a prepared statement &lt;em&gt;can&lt;/em&gt; span transactions.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;25. Why do I get a &lt;/span&gt;&lt;code style="font-family: courier; font-weight: bold;"&gt;java.lang.AbstractMethodError&lt;/code&gt;&lt;span style="font-weight: bold;"&gt; when calling a method on a driver?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501077"&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; This usually indicates that the driver has not implemented the method. For instance, you might be calling a JDBC 3.0 method on a driver that has only implemented the JDBC 2.0 methods.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;span style="font-weight: bold;"&gt;26. Why do I get "ResourceException: No Resource Available"?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-weight: bold;"&gt;&lt;br&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;a name="501093"&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; One common reason is that you have too many consumers (connection users) for the number of configured JDBC connections in the connection pool or execute threads on the server. &lt;/p&gt; &lt;p&gt;   &lt;a name="501095"&gt;&lt;/a&gt;Another reason may be that the refresh testing process has reserved one or more connections for testing so these connections are briefly unavailable.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   27. How do I ensure that a new database connection is created each time an EJB's container-managed transaction is started (so that I get a new authentication/authorization each time)? &lt;/p&gt; &lt;p&gt;   &lt;a name="501099" style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; The EJB should be tx-requires, which means it will start a transaction when called if one is not underway already, or will join the transaction in progress if there is one. Your code will use the standard JTS/JTA API to obtain and start a UserTransaction. Then you should obtain your JDBC connection from a tx data source, and it will be included in the transaction. To get a new connection each time, you could use the dynamic pool API to make a one-connection pool. We suggest configuring the server to have a one-connection pool and a tx data source for it at startup. Then when you want to do a transaction in an external client, you would destroy the initial pool and recreate it with the DBMS user you want. This will allow you to use the tx data source to get a connection, which if obtained in the context of a running UserTransaction, will get automatically included in the tx.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   28. If it is a WebLogic DataSource, then you get a stub for the Connection instance, not a connection pool in the local process. &lt;/p&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;If a distributed transaction involves JMS and JDBC, how do I ensure that the JDBC update is available when the JMS message is processed?&lt;/span&gt;&lt;br style="font-weight: bold; color: rgb(255, 0, 0);"&gt; &lt;br&gt; &lt;p&gt;   &lt;a name="501107"&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; The problem is that an application can receive the JMS message from the destination before the associated JDBC data is in the database. &lt;/p&gt; &lt;p&gt;   &lt;a name="501110"&gt;&lt;/a&gt;Distributed transactions guarantee all involved changes will either succeed or fail as a unit, but cannot guarantee that they will happen exactly simultaneously (the transaction manager instructs all resource managers to commit but cannot control the timing of the completion of that operation). &lt;/p&gt; &lt;p&gt;   &lt;a name="501111"&gt;&lt;/a&gt;For the WebLogic transaction manager, if the JDBC connection pool and the JMS server are both on the same server, and the transaction starts on the same server, the changes are committed in the order in which they were asked for by the transaction. This is not supported behavior, it just happens to be the current behavior. So if you can co-locate JMS and the JDBC connection pool, then you may have a chance. &lt;/p&gt; &lt;p&gt;   &lt;a name="501112"&gt;&lt;/a&gt;You could send the JMS message with a delayed birth-time, and hope that this is good enough. &lt;/p&gt; &lt;p&gt;   &lt;a name="501113"&gt;&lt;/a&gt;If the receiver fails to find the associated JDBC record, it could rollback/recover the message. You could use the WebLogic JMS redelivery delay feature to prevent the message from being redelivered instantly.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   29. If an application calls &lt;code style="font-family: courier;"&gt;DataSource.getConnection&lt;/code&gt; multiple times in the same thread and transaction, will WebLogic Server handle giving me the same connection and transaction? &lt;/p&gt; &lt;p&gt;   &lt;a name="501117" style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt; &lt;/strong&gt; A common scenario might be to have multiple methods that are called within a transaction (begin/commit) that do something like the following: &lt;/p&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code style="font-family: courier; font-size: 10pt;"&gt;&lt;a name="501119"&gt;&lt;/a&gt;Context ctx = new InitialContext();&lt;br&gt;DataSource ds = (javax.sql.DataSource) ctx.lookup("connpoll");&lt;br&gt;// work using Connection&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; &lt;p&gt;   &lt;a name="501123"&gt;&lt;/a&gt;In this case, all of the work will be done within the transaction and the same underlying JDBC connection will be used as long as the DataSource &lt;code style="font-family: courier;"&gt;ds&lt;/code&gt; is a tx data source.&lt;br&gt; &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;30.  Why do I get a SystemException failure when trying to enlist my XAResource in a client?&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;br&gt;   &lt;/strong&gt; &lt;/p&gt; &lt;p&gt;   &lt;strong&gt;&lt;/strong&gt;WebLogic Server does not allow you to register or enlist an XA resource on a client. The reason for this restriction is that a client is deemed to be less reliable than a server in terms of availability. This is also why a client is not allowed to act as a transaction coordinator and register Synchronization objects. &lt;/p&gt; &lt;p&gt;   &lt;a name="501133"&gt;&lt;/a&gt;Your client could invoke a remote object on a server that accesses the resource within a transaction. If it's a JDBC resource, then you can configure a JDBCConnectionPool and JDBCTxDataSource using an Oracle XA driver (Oracle thin or WebLogic Type 4 driver for Oracle) and obtain a connection from the data source. Or the client could look up the data source using JNDI and retrieve and manipulate a connection in a transaction. Transaction enlistment is performed automatically.&lt;br&gt; &lt;/p&gt; &lt;br&gt;&lt;span style="font-weight: bold;"&gt; Source : &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;&lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;strong style="font-weight: bold;"&gt;&lt;/strong&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-4346652876707794118?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/4346652876707794118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=4346652876707794118' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4346652876707794118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4346652876707794118'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or_5978.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-6448262441303026188</id><published>2007-01-18T17:39:00.001-08:00</published><updated>2007-01-18T17:41:49.117-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;br&gt;&lt;div style="text-align: left;"&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;span style="font-weight: bold; font-style: italic;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;&lt;a name="12"&gt;11. Why does the ODBC driver manager return 'Data source name not found and no default driver specified Vendor: 0'&lt;/a&gt;&lt;/b&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;&lt;a name="12"&gt;&lt;br&gt;   &lt;/a&gt;&lt;/b&gt; &lt;/p&gt; &lt;p&gt;   This type of error occurs during an attempt to connect to a database with the bridge. First, note that the error is coming from the ODBC driver manager. This indicates that the bridge-which is a normal ODBC client-has successfully called ODBC, so the problem isn't due to native libraries not being present. In this case, it appears that the error is due to the fact that an ODBC DSN (data source name) needs to be configured on the client machine. Developers often forget to do this, thinking that the bridge will magically find the DSN they configured on their remote server machine. &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p&gt;   &lt;font size="2"&gt;   &lt;p style="color: rgb(255, 0, 0);"&gt;     &lt;b&gt;&lt;a name="13"&gt;12. Are all the required JDBC drivers to establish connectivity to my database part of the JDK?&lt;/a&gt;&lt;/b&gt;   &lt;/p&gt;   &lt;p style="color: rgb(255, 0, 0);"&gt;     &lt;b&gt;&lt;a name="13"&gt;&lt;br&gt;     &lt;/a&gt;&lt;/b&gt;   &lt;/p&gt;   &lt;p&gt;     No. There aren't any JDBC technology-enabled drivers bundled with the JDK 1.1.x or Java 2 Platform releases other than the JDBC-ODBC Bridge. So, developers need to get a driver and install it before they can connect to a database. We are considering bundling JDBC technology- enabled drivers in the future.   &lt;/p&gt;   &lt;br&gt;   &lt;p&gt;     &lt;br&gt;   &lt;/p&gt;   &lt;p&gt;     &lt;font size="2"&gt;     &lt;p style="color: rgb(255, 0, 0);"&gt;       &lt;b&gt;&lt;a name="14"&gt;13. Is the JDBC-ODBC Bridge multi-threaded?&lt;/a&gt;&lt;/b&gt;     &lt;/p&gt;     &lt;p style="color: rgb(255, 0, 0);"&gt;       &lt;b&gt;&lt;a name="14"&gt;&lt;br&gt;       &lt;/a&gt;&lt;/b&gt;     &lt;/p&gt;     &lt;p&gt;       No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading. In addition, deadlocks can occur between locks held in the database and the semaphore used by the Bridge. We are thinking about removing the synchronized methods in the future. They were added originally to make things simple for folks writing Java programs that use a single-threaded ODBC driver.     &lt;/p&gt;     &lt;br&gt;     &lt;p&gt;       &lt;br&gt;     &lt;/p&gt;     &lt;p&gt;       &lt;font size="2"&gt;       &lt;p style="color: rgb(255, 0, 0);"&gt;         &lt;b&gt;&lt;a name="15"&gt;14. Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?&lt;/a&gt;&lt;/b&gt;       &lt;/p&gt;       &lt;p style="color: rgb(255, 0, 0);"&gt;         &lt;b&gt;&lt;a name="15"&gt;&lt;br&gt;         &lt;/a&gt;&lt;/b&gt;       &lt;/p&gt;       &lt;p&gt;         No. You can open only one &lt;code&gt;Statement&lt;/code&gt; object per connection when you are using the JDBC-ODBC Bridge.       &lt;/p&gt;       &lt;br&gt;       &lt;p&gt;         &lt;br&gt;       &lt;/p&gt;       &lt;p&gt;         &lt;font size="2"&gt;         &lt;p style="color: rgb(255, 0, 0);"&gt;           &lt;b&gt;&lt;a name="16"&gt;15. Why can't I invoke the &lt;code&gt;ResultSet&lt;/code&gt; methods &lt;code&gt;afterLast&lt;/code&gt; and &lt;code&gt;beforeFirst&lt;/code&gt; when the method &lt;code&gt;next&lt;/code&gt; works?&lt;/a&gt;&lt;/b&gt;         &lt;/p&gt;         &lt;p&gt;           You are probably using a driver implemented for the JDBC 1.0 API. You need to upgrade to a JDBC 2.0 driver that implements scrollable result sets. Also be sure that your code has created scrollable result sets and that the DBMS you are using supports them.   &lt;br&gt;         &lt;/p&gt;         &lt;br&gt;         &lt;p&gt;           &lt;br&gt;         &lt;/p&gt;         &lt;p&gt;           &lt;font size="2"&gt;           &lt;p style="color: rgb(255, 0, 0);"&gt;             &lt;b&gt;&lt;a name="17"&gt;16. How can I retrieve a &lt;code&gt;String&lt;/code&gt; or other object type without creating a new object each time?&lt;/a&gt;&lt;/b&gt;           &lt;/p&gt;           &lt;p style="color: rgb(255, 0, 0);"&gt;             &lt;b&gt;&lt;a name="17"&gt;&lt;br&gt;             &lt;/a&gt;&lt;/b&gt;           &lt;/p&gt;           &lt;p&gt;             Creating and garbage collecting potentially large numbers of objects (millions) unnecessarily can really hurt performance. It may be better to provide a way to retrieve data like strings using the JDBC API without always allocating a new object.           &lt;/p&gt;           &lt;p&gt;             We are studying this issue to see if it is an area in which the JDBC API should be improved. Stay tuned, and please send us any comments you have on this question.           &lt;/p&gt;           &lt;br&gt;           &lt;p&gt;             &lt;br&gt;           &lt;/p&gt;           &lt;p&gt;             &lt;font size="2"&gt;             &lt;p style="color: rgb(255, 0, 0);"&gt;               &lt;b&gt;&lt;a name="18"&gt;17. There is a method &lt;code&gt;getColumnCount&lt;/code&gt; in the JDBC API. Is there a similar method to find the number of rows in a result set?&lt;/a&gt;&lt;/b&gt;             &lt;/p&gt;             &lt;p style="color: rgb(255, 0, 0);"&gt;               &lt;b&gt;&lt;a name="18"&gt;&lt;br&gt;               &lt;/a&gt;&lt;/b&gt;             &lt;/p&gt;             &lt;p&gt;               No, but it is easy to find the number of rows. If you are using a scrollable result set, &lt;code&gt;rs&lt;/code&gt;, you can call the methods &lt;code&gt;rs.last&lt;/code&gt; and then &lt;code&gt;rs.getRow&lt;/code&gt; to find out how many rows &lt;code&gt;rs&lt;/code&gt; has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a &lt;code&gt;COUNT&lt;/code&gt; column in the &lt;code&gt;SELECT&lt;/code&gt; clause.             &lt;/p&gt;             &lt;br&gt;             &lt;p&gt;               &lt;br&gt;             &lt;/p&gt;             &lt;p&gt;               &lt;font size="2"&gt;               &lt;p style="color: rgb(255, 0, 0);"&gt;                 &lt;b&gt;&lt;a name="19"&gt;&lt;/a&gt;&lt;/b&gt;&lt;a name="19"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;JDBC - Frequently Asked Questions(FAQs)(Part -&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; 1)&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;               &lt;/p&gt;               &lt;p style="color: rgb(255, 0, 0);"&gt;                 &lt;a name="19"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;                 &lt;/a&gt;&lt;b&gt;&lt;a name="19"&gt;&lt;/a&gt;&lt;/b&gt;               &lt;/p&gt;               &lt;p style="color: rgb(255, 0, 0);"&gt;                 &lt;b&gt;&lt;a name="19"&gt; 18. I would like to download the JDBC-ODBC Bridge for the Java 2 SDK, Standard Edition (formerly JDK 1.2). I'm a beginner with the JDBC API, and I would like to start with the Bridge. How do I do it?&lt;/a&gt;&lt;/b&gt;               &lt;/p&gt;               &lt;p style="color: rgb(255, 0, 0);"&gt;                 &lt;b&gt;&lt;a name="19"&gt;&lt;br&gt;                 &lt;/a&gt;&lt;/b&gt;               &lt;/p&gt;               &lt;p&gt;                 The JDBC-ODBC Bridge is bundled with the Java 2 SDK, Standard Edition, so there is no need to download it separately.               &lt;/p&gt;               &lt;br&gt;               &lt;p&gt;                 &lt;br&gt;               &lt;/p&gt;               &lt;p&gt;                 &lt;font size="2"&gt;                 &lt;p style="color: rgb(255, 0, 0);"&gt;                   &lt;b&gt;&lt;a name="20"&gt; 19. If I use the JDBC API, do I have to use ODBC underneath?&lt;/a&gt;&lt;/b&gt;                 &lt;/p&gt;                 &lt;p style="color: rgb(255, 0, 0);"&gt;                   &lt;b&gt;&lt;a name="20"&gt;&lt;br&gt;                   &lt;/a&gt;&lt;/b&gt;                 &lt;/p&gt;                 &lt;p&gt;                   No, this is just one of many possible solutions. We recommend using a pure Java JDBC technology-enabled driver, type 3 or 4, in order to get all of the benefits of the Java programming language and the JDBC API.                 &lt;/p&gt;                 &lt;br&gt;                 &lt;p&gt;                   &lt;br&gt;                 &lt;/p&gt;                 &lt;p&gt;                   &lt;font size="2"&gt;                   &lt;p style="color: rgb(255, 0, 0);"&gt;                     &lt;b&gt;&lt;a name="21"&gt;20. Once I have the Java 2 SDK, Standard Edition, from Sun, what else do I need to connect to a database?&lt;/a&gt;&lt;/b&gt;                   &lt;/p&gt;                   &lt;p style="color: rgb(255, 0, 0);"&gt;                     &lt;b&gt;&lt;a name="21"&gt;&lt;br&gt;                     &lt;/a&gt;&lt;/b&gt;                   &lt;/p&gt;                   &lt;p&gt;                     You still need to get and install a JDBC technology-enabled driver that supports the database that you are using. There are many drivers available from a variety of sources. You can also try using the JDBC-ODBC Bridge if you have ODBC connectivity set up already. The Bridge comes with the Java 2 SDK, Standard Edition, and Enterprise Edition, and it doesn't require any extra setup itself. The Bridge is a normal ODBC client. Note, however, that you should use the JDBC-ODBC Bridge only for experimental prototyping or when you have no other driver available.                   &lt;/p&gt;                   &lt;br&gt;                   &lt;p style="font-weight: bold;"&gt;                     Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;                   &lt;/p&gt;                   &lt;p style="color: rgb(255, 0, 0); font-weight: bold;"&gt;                     &lt;br&gt;                   &lt;/p&gt;                   &lt;/font&gt;                 &lt;/p&gt;                 &lt;/font&gt;               &lt;/p&gt;               &lt;/font&gt;             &lt;/p&gt;             &lt;/font&gt;           &lt;/p&gt;           &lt;/font&gt;         &lt;/p&gt;         &lt;/font&gt;       &lt;/p&gt;       &lt;/font&gt;     &lt;/p&gt;     &lt;/font&gt;   &lt;/p&gt;   &lt;/font&gt; &lt;/p&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-6448262441303026188?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/6448262441303026188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=6448262441303026188' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6448262441303026188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6448262441303026188'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or_4097.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-536466618380664017</id><published>2007-01-18T17:39:00.000-08:00</published><updated>2007-01-18T17:41:53.790-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>JDBC Interview Questions - FAQs</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;a title="JDBC - Frequently Asked Questions or Interview Questions(FAQs)" href="http://faqs.javabeat.net/index.php?page=JDBC"&gt;JDBC - Frequently Asked Questions or Interview Questions(FAQs)&lt;/a&gt; &lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255); font-style: italic;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;1. &lt;/span&gt;&lt;span class="boldbodycopy" style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;a name="01_01"&gt;What is JDBC?&lt;/a&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span class="bodycopy"&gt;&lt;br&gt; &lt;br&gt; &lt;/span&gt;&lt;span class="bodycopy"&gt;JDBC technology is an API that lets you access virtually any tabular data source from the Java programming language. It provides cross-DBMS connectivity to a wide range of SQL databases, and now, with the new JDBC API, it also provides access to other tabular data sources, such as spreadsheets or flat files.&lt;/span&gt;&lt;br&gt; &lt;span class="bodycopy"&gt;&lt;/span&gt;&lt;span class="bodycopy"&gt;&lt;br&gt; &lt;/span&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;a name="1"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;2. What's the JDBC 3.0 API?&lt;/span&gt;&lt;br&gt; &lt;br&gt; &lt;/b&gt;&lt;/a&gt; &lt;p&gt;   The JDBC 3.0 API is the latest update of the JDBC API. It contains many features, including scrollable result sets and the SQL:1999 data types. &lt;/p&gt; &lt;br&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt;   &lt;font&gt;&lt;font size="2"&gt;&lt;b&gt;&lt;a name="2"&gt;3. Does the JDBC-ODBC Bridge support the new features in the JDBC 3.0 API?&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font&gt;&lt;font size="2"&gt;&lt;b&gt;&lt;a name="2"&gt;&lt;br&gt;   &lt;/a&gt;&lt;/b&gt;   &lt;p&gt;     The JDBC-ODBC Bridge provides a limited subset of the JDBC 3.0 API.   &lt;/p&gt;   &lt;br&gt;   &lt;p&gt;     &lt;br&gt;   &lt;/p&gt;   &lt;p&gt;     &lt;font size="2"&gt;     &lt;p style="color: rgb(255, 0, 0);"&gt;       &lt;b&gt;&lt;a name="3"&gt;4. Can the JDBC-ODBC Bridge be used with applets?&lt;/a&gt;&lt;/b&gt;     &lt;/p&gt;     &lt;p&gt;       &lt;b&gt;&lt;a name="3"&gt;&lt;br&gt;       &lt;/a&gt;&lt;/b&gt;     &lt;/p&gt;     &lt;p&gt;       Use of the JDBC-ODBC bridge from an untrusted applet running in a browser, such as Netscape Navigator, isn't allowed. The JDBC-ODBC bridge doesn't allow untrusted code to call it for security reasons. This is good because it means that an untrusted applet that is downloaded by the browser can't circumvent Java security by calling ODBC. Remember that ODBC is native code, so once ODBC is called the Java programming language can't guarantee that a security violation won't occur. On the other hand, Pure Java JDBC drivers work well with applets. They are fully downloadable and do not require any client-side configuration.     &lt;/p&gt;     &lt;p&gt;       Finally, we would like to note that it is possible to use the JDBC-ODBC bridge with applets that will be run in appletviewer since appletviewer assumes that applets are trusted. In general, it is dangerous to turn applet security off, but it may be appropriate in certain controlled situations, such as for applets that will only be used in a secure intranet environment. Remember to exercise caution if you choose this option, and use an all-Java JDBC driver whenever possible to avoid security problems.     &lt;/p&gt;     &lt;br&gt;     &lt;p&gt;       &lt;br&gt;     &lt;/p&gt;     &lt;p&gt;       &lt;font size="2"&gt;       &lt;p style="color: rgb(255, 0, 0);"&gt;         &lt;b&gt;&lt;a name="4"&gt;5. How do I start debugging problems related to the JDBC API?&lt;/a&gt;&lt;/b&gt;       &lt;/p&gt;       &lt;p&gt;         &lt;b&gt;&lt;a name="4"&gt;&lt;br&gt;         &lt;/a&gt;&lt;/b&gt;       &lt;/p&gt;       &lt;p&gt;         A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.       &lt;/p&gt;       &lt;p&gt;         If you use the &lt;code&gt;DriverManager&lt;/code&gt; facility to establish your database connection, you use the &lt;code&gt;DriverManager.setLogWriter&lt;/code&gt; method to enable tracing of JDBC operations. If you use a &lt;code&gt;DataSource&lt;/code&gt; object to get a connection, you use the &lt;code&gt;DataSource.setLogWriter&lt;/code&gt; method to enable tracing. (For pooled connections, you use the &lt;code&gt;ConnectionPoolDataSource.setLogWriter&lt;/code&gt; method, and for connections that can participate in distributed transactions, you use the &lt;code&gt;XADataSource.setLogWriter&lt;/code&gt; method.)       &lt;/p&gt;       &lt;/font&gt;     &lt;/p&gt;     &lt;/font&gt;   &lt;/p&gt;   &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;/font&gt;&lt;/font&gt;&lt;br&gt; &lt;font size="2"&gt; &lt;/font&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;  &lt;b&gt;&lt;a name="5"&gt;6. How can I use the JDBC API to access a desktop database like Microsoft Access over the network?&lt;/a&gt;&lt;/b&gt; &lt;/font&gt;&lt;/p&gt; &lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;  &lt;b&gt;&lt;a name="5"&gt;&lt;br&gt;   &lt;/a&gt;&lt;/b&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt; &lt;font size="2"&gt;  Most desktop databases currently require a JDBC solution that uses ODBC underneath. This is because the vendors of these database products haven't implemented all-Java JDBC drivers. &lt;/font&gt;&lt;/p&gt; &lt;p&gt; &lt;font size="2"&gt;  The best approach is to use a commercial JDBC driver that supports ODBC and the database you want to use. See the &lt;a href="http://industry.java.sun.com/products/jdbc/drivers"&gt;JDBC drivers page&lt;/a&gt; for a list of available JDBC drivers. &lt;/font&gt;&lt;/p&gt; &lt;p&gt; &lt;font size="2"&gt;  The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers for desktop databases like Access aren't networked. The JDBC-ODBC bridge can be used together with the &lt;a href="http://www.objectweb.org/"&gt;RMI-JDBC bridge&lt;/a&gt;, however, to access a desktop database like Access over the net. This RMI-JDBC-ODBC solution is free. &lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;br&gt; &lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;  &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt; &lt;font size="2"&gt;  &lt;font size="2"&gt;   &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;b&gt;&lt;a name="8"&gt;7. Are there any ODBC drivers that do not work with the JDBC-ODBC Bridge?&lt;/a&gt;&lt;/b&gt;   &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;  &lt;/font&gt;&lt;/font&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;b&gt;&lt;a name="8"&gt;&lt;br&gt;     &lt;/a&gt;&lt;/b&gt;   &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;  &lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;    Most ODBC 2.0 drivers should work with the Bridge. Since there is some variation in functionality between ODBC drivers, the functionality of the bridge may be affected. The bridge works with popular PC databases, such as Microsoft Access and FoxPro.   &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;  &lt;br&gt;   &lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;br&gt;   &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;  &lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;font size="2"&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;b&gt;&lt;a name="9"&gt;8. What causes the "No suitable driver" error?&lt;/a&gt;&lt;/b&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;b&gt;&lt;a name="9"&gt;&lt;br&gt;       &lt;/a&gt;&lt;/b&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      "No suitable driver" is an error that usually occurs during a call to the &lt;code&gt;DriverManager.getConnection&lt;/code&gt; method. The cause can be failing to load the appropriate JDBC drivers before calling the &lt;code&gt;getConnection&lt;/code&gt; method, or it can be specifying an invalid JDBC URL--one that isn't recognized by your JDBC driver. Your best bet is to check the documentation for your JDBC driver or contact your JDBC driver vendor if you suspect that the URL you are specifying is not being recognized by your JDBC driver.     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      In addition, when you are using the JDBC-ODBC Bridge, this error can occur if one or more the the shared libraries needed by the Bridge cannot be loaded. If you think this is the cause, check your configuration to be sure that the shared libraries are accessible to the Bridge.     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;br&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;br&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;font size="2"&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        &lt;b&gt;&lt;a name="10"&gt;9. Why isn't the &lt;code&gt;java.sql.DriverManager&lt;/code&gt; class being found?&lt;/a&gt;&lt;/b&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p style="color: rgb(255, 0, 0);"&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        &lt;b&gt;&lt;a name="10"&gt;&lt;br&gt;         &lt;/a&gt;&lt;/b&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        This problem can be caused by running a JDBC applet in a browser that supports the JDK 1.0.2, such as Netscape Navigator 3.0. The JDK 1.0.2 does not contain the JDBC API, so the &lt;code&gt;DriverManager&lt;/code&gt; class typically isn't found by the Java virtual machine running in the browser.       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        Here's a solution that doesn't require any additional configuration of your web clients. Remember that classes in the &lt;code&gt;java.*&lt;/code&gt; packages cannot be downloaded by most browsers for security reasons. Because of this, many vendors of all-Java JDBC drivers supply versions of the &lt;code&gt;java.sql.*&lt;/code&gt; classes that have been renamed to &lt;code&gt;jdbc.sql.*&lt;/code&gt;, along with a version of their driver that uses these modified classes. If you import &lt;code&gt;jdbc.sql.*&lt;/code&gt; in your applet code instead of &lt;code&gt;java.sql.*&lt;/code&gt;, and add the &lt;code&gt;jdbc.sql.*&lt;/code&gt; classes provided by your JDBC driver vendor to your applet's codebase, then all of the JDBC classes needed by the applet can be downloaded by the browser at run time, including the &lt;code&gt;DriverManager&lt;/code&gt; class.       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        This solution will allow your applet to work in any client browser that supports the JDK 1.0.2. Your applet will also work in browsers that support the JDK 1.1, although you may want to switch to the JDK 1.1 classes for performance reasons. Also, keep in mind that the solution outlined here is just an example and that other solutions are possible.       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;br&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        &lt;br&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;        &lt;font size="2"&gt;         &lt;p style="color: rgb(255, 0, 0);"&gt;           &lt;b&gt;&lt;a name="11"&gt;10. How do I retrieve a whole row of data at once, instead of calling an individual &lt;code&gt;ResultSet.getXXX&lt;/code&gt; method for each column?&lt;/a&gt;&lt;/b&gt;         &lt;/p&gt;         &lt;p style="color: rgb(255, 0, 0);"&gt;           &lt;b&gt;&lt;a name="11"&gt;&lt;br&gt;           &lt;/a&gt;&lt;/b&gt;         &lt;/p&gt;         &lt;p&gt;           The &lt;code&gt;ResultSet.getXXX&lt;/code&gt; methods are the only way to retrieve data from a &lt;code&gt;ResultSet&lt;/code&gt; object, which means that you have to make a method call for each column of a row. It is unlikely that this is the cause of a performance problem, however, because it is difficult to see how a column could be fetched without at least the cost of a function call in any scenario. We welcome input from developers on this issue.         &lt;/p&gt;         &lt;br&gt;         &lt;p style="font-weight: bold;"&gt;           Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;         &lt;/p&gt;         &lt;/font&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;      &lt;/font&gt;     &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;    &lt;/font&gt;   &lt;/font&gt;&lt;/font&gt;&lt;p&gt; &lt;/p&gt; &lt;font size="2"&gt;&lt;font size="2"&gt;  &lt;/font&gt; &lt;/font&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-536466618380664017?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/536466618380664017/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=536466618380664017' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/536466618380664017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/536466618380664017'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/jdbc-frequently-asked-questions-or_4339.html' title='JDBC Interview Questions - FAQs'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-4970090750016058327</id><published>2007-01-18T17:33:00.000-08:00</published><updated>2007-01-18T17:34:17.657-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Java Interview Questions - Part1</title><content type='html'>&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;a title="Java - Frequently Asked Questions(FAQs)(Part - 1)" href="http://faqs.javabeat.net/index.php?page=Java"&gt;Java Interview Questions(FAQs)(Part - 3)&lt;/a&gt; &lt;/div&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;b&gt;21. What's the difference between a queue and a stack?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div&gt;   &lt;strong style="color: rgb(255, 0, 0);"&gt;22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?&lt;/strong&gt;   &lt;div&gt;     &lt;br&gt;     A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.   &lt;/div&gt; &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;23. What comes to mind when you hear about a young generation in Java?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Garbage collection. &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;24. What comes to mind when someone mentions a shallow copy in Java?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Object cloning. &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;25. If you're overriding the method equals() of an object, which other method you might also consider?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. hashCode() &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:&lt;br&gt;   ArrayList or LinkedList?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. ArrayList &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;27. How would you make a copy of an entire Java object with its state?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Have this class implement Cloneable interface and call its method clone(). &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;28. How can you minimize the need of garbage collection and make the memory use more effective?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Use object pooling and weak object references. &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface. &lt;/div&gt; &lt;div&gt;     &lt;/div&gt; &lt;div style="color: rgb(255, 0, 0);"&gt;   &lt;b&gt;30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?&lt;/b&gt; &lt;/div&gt; &lt;br&gt; A. You do not need to specify any access level, and Java will use a default package access level.&lt;br&gt; &lt;br&gt; Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-4970090750016058327?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/4970090750016058327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=4970090750016058327' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4970090750016058327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/4970090750016058327'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/java-interview-questionsfaqspart-3-21.html' title='Java Interview Questions - Part1'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-5077756733459757649</id><published>2007-01-18T17:32:00.002-08:00</published><updated>2007-01-18T17:34:22.874-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Java Interview Questions - Part2</title><content type='html'>&lt;font&gt;&lt;font size="2"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;a title="Java - Frequently Asked Questions(FAQs)(Part - 1)" href="http://faqs.javabeat.net/index.php?page=Java"&gt;Java Interview Questions(FAQs)(Part - 2)&lt;/a&gt;  &lt;/div&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;b&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;11. Explain the usage of Java packages.&lt;/span&gt;&lt;/b&gt; &lt;div&gt;   &lt;br&gt;   A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:devcomxyzhrEmployee.java. In this case, you'd need to add c:dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;c:&amp;gt;java com.xyz.hr.Employee&lt;/span&gt; &lt;/div&gt; &lt;div&gt;    &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;13. What's the difference between J2SDK 1.5 and J2SDK 5.0?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A.There's no difference, Sun Microsystems just re-branded this version.&lt;br&gt;   &lt;br&gt;   &lt;strong style="color: rgb(255, 0, 0);"&gt;14. What would you use to compare two String variables - the operator == or the method equals()?&lt;/strong&gt;   &lt;div&gt;     &lt;br&gt;     A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.&lt;br&gt;     &lt;br&gt;       &lt;strong style="color: rgb(255, 0, 0);"&gt;15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?&lt;/strong&gt;     &lt;div&gt;       &lt;br&gt;       A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.     &lt;/div&gt;     &lt;div&gt;       &lt;b&gt;&lt;br&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt; 16. Can an inner class declared inside of a method access local variables of this method?&lt;/span&gt;&lt;/b&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;br&gt;       A. It's possible if these variables are final.     &lt;/div&gt;     &lt;b&gt;     &lt;div&gt;       &lt;br&gt;         &lt;span style="color: rgb(255, 0, 0);"&gt;17. What can go wrong if you replace &amp;amp;&amp;amp; with &amp;amp; in the following code:&lt;/span&gt;&lt;br style="color: rgb(255, 0, 0);"&gt;       &lt;br style="color: rgb(255, 0, 0);"&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;span class="Code"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;String a=null; if (a!=null &amp;amp;&amp;amp; a.length()&amp;gt;10) {...}&lt;/span&gt;&lt;br style="color: rgb(255, 0, 0);"&gt;       &lt;br&gt;       &lt;/span&gt;     &lt;/div&gt;     &lt;/b&gt;     &lt;div&gt;       &lt;div&gt;         A. A single ampersand here would lead to a NullPointerException.       &lt;/div&gt;     &lt;/div&gt;   &lt;/div&gt;   &lt;br&gt;     &lt;strong style="color: rgb(255, 0, 0);"&gt;18. What's the main difference between a Vector and an ArrayList&lt;/strong&gt;   &lt;div&gt;     &lt;br&gt;     A. Java Vector class is internally synchronized and ArrayList is not.&lt;b&gt;&lt;br&gt;     &lt;br&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt;19. When should the method invokeLater()be used?&lt;/span&gt;&lt;/b&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;br&gt;     A. This method is used to ensure that Swing components are updated through the event-dispatching thread.&lt;br&gt;     &lt;br&gt;     &lt;div&gt;         &lt;b style="color: rgb(255, 0, 0);"&gt;20. How can a subclass call a method or a constructor defined in a superclass?&lt;/b&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;br&gt;       A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.&lt;br&gt;       &lt;br&gt;       Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;&lt;br&gt;     &lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-5077756733459757649?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/5077756733459757649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=5077756733459757649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5077756733459757649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5077756733459757649'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/java-interview-questionsfaqspart-2-11.html' title='Java Interview Questions - Part2'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-323793013606838312</id><published>2007-01-18T17:32:00.001-08:00</published><updated>2007-01-18T17:34:31.010-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Java Interview Questions - Part3</title><content type='html'>&lt;font&gt;&lt;font size="2"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt; &lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;a title="Java - Frequently Asked Questions(FAQs)(Part - 1)" href="http://faqs.javabeat.net/index.php?page=Java"&gt;Java Interview Questions(FAQs)(Part - 1)&lt;/a&gt; &lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;   &lt;br&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt; &lt;/div&gt; &lt;b style="color: rgb(255, 0, 0);"&gt;1. How could Java classes direct program messages to the system console, but error messages, say to a file?&lt;/b&gt; &lt;div&gt;   &lt;br&gt;   A. The class System has a variable &lt;i&gt;out&lt;/i&gt; that represents the standard output, and the variable &lt;i&gt;err&lt;/i&gt; that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);&lt;/span&gt;  &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;2. What's the difference between an interface and an abstract class?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt; 3. Why would you use a synchronized block vs. synchronized method?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Synchronized blocks place locks for shorter periods than synchronized methods. &lt;/div&gt; &lt;div&gt;   &lt;div&gt;     &lt;strong&gt;&lt;br&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt;4. Explain the usage of the keyword transient?&lt;/span&gt;&lt;/strong&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;br&gt;     A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).&lt;b&gt;&lt;br&gt;     &lt;br&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt;5. How can you force garbage collection?&lt;/span&gt;&lt;/b&gt;   &lt;/div&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;6. How do you know if an explicit object casting is needed?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;   &lt;div&gt;     Object a; Customer b; b = (Customer) a;   &lt;/div&gt;   &lt;/span&gt;&lt;br&gt;   When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.  &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;7. What's the difference between the methods sleep() and wait()&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. The code &lt;span class="Code"&gt;sleep(1000); &lt;/span&gt;puts thread aside for exactly one second. The code &lt;span class="Code"&gt;wait(1000), &lt;/span&gt;causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;   &lt;span style="color: rgb(255, 0, 0);"&gt;  8. Can you write a Java class that could be used both as an applet as well as an application?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Yes. Add a main() method to the applet. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;9. What's the difference between constructors and other methods?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;     &lt;span style="color: rgb(255, 0, 0);"&gt;10. Can you call one constructor from another if a class has multiple constructors&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Yes. Use this() syntax.&lt;br&gt;   &lt;br&gt;   Source : &lt;a href="http://www.javabeat.net/" title="www.javabeat.net"&gt;www.javabeat.net&lt;/a&gt;&lt;br&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-323793013606838312?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/323793013606838312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=323793013606838312' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/323793013606838312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/323793013606838312'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/java-interview-questionsfaqspart-1-1.html' title='Java Interview Questions - Part3'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-5444598500306534489</id><published>2007-01-18T17:32:00.000-08:00</published><updated>2007-01-18T17:34:38.174-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Interview Questions'/><title type='text'>Java Interview Questions - Part4</title><content type='html'>&lt;a title="Java - Frequently Asked Questions(FAQs)(Part - 1)" href="http://faqs.javabeat.net/index.php?page=Java"&gt;Java Interview Questions(FAQs)(Part - 4)&lt;/a&gt; &lt;font&gt;&lt;font size="2"&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;b style="color: rgb(255, 0, 0);"&gt;1. How could Java classes direct program messages to the system console, but error messages, say to a file?&lt;/b&gt; &lt;div&gt;   &lt;br&gt;   A. The class System has a variable &lt;i&gt;out&lt;/i&gt; that represents the standard output, and the variable &lt;i&gt;err&lt;/i&gt; that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);&lt;/span&gt;  &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;2. What's the difference between an interface and an abstract class?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt; &lt;span style="color: rgb(255, 0, 0);"&gt; 3. Why would you use a synchronized block vs. synchronized method?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Synchronized blocks place locks for shorter periods than synchronized methods. &lt;/div&gt; &lt;div&gt;   &lt;div&gt;     &lt;strong&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;4. Explain the usage of the keyword transient?&lt;/span&gt;&lt;/strong&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;br&gt;     A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).&lt;b&gt;&lt;br&gt;     &lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;5. How can you force garbage collection?&lt;/span&gt;&lt;/b&gt;   &lt;/div&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;6. How do you know if an explicit object casting is needed?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;   &lt;div&gt;     Object a; Customer b; b = (Customer) a;   &lt;/div&gt;   &lt;/span&gt;&lt;br&gt;   When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.  &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;7. What's the difference between the methods sleep() and wait()&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. The code &lt;span class="Code"&gt;sleep(1000); &lt;/span&gt;puts thread aside for exactly one second. The code &lt;span class="Code"&gt;wait(1000), &lt;/span&gt;causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  8. Can you write a Java class that could be used both as an applet as well as an application?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Yes. Add a main() method to the applet. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;9. What's the difference between constructors and other methods?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;10. Can you call one constructor from another if a class has multiple constructors&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. Yes. Use this() syntax. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;11. Explain the usage of Java packages.&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes. &lt;/div&gt; &lt;div&gt;   &lt;b&gt;&lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:devcomxyzhrEmployee.java. In this case, you'd need to add c:dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:&lt;br&gt;   &lt;br&gt; &lt;/div&gt; &lt;div&gt;   &lt;span class="Code"&gt;c:&amp;gt;java com.xyz.hr.Employee&lt;/span&gt; &lt;/div&gt; &lt;div&gt;    &lt;b&gt;&lt;br&gt;    &lt;span style="color: rgb(255, 0, 0);"&gt;13. What's the difference between J2SDK 1.5 and J2SDK 5.0?&lt;/span&gt;&lt;/b&gt; &lt;/div&gt; &lt;div&gt;   &lt;br&gt;   A.There's no difference, Sun Microsystems just re-branded this version.&lt;br&gt;   &lt;br&gt;   &lt;strong style="color: rgb(255, 0, 0);"&gt;14. What would you use to compare two String variables - the operator == or the method equals()?&lt;/strong&gt;   &lt;div&gt;     &lt;br&gt;     A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.&lt;br&gt;     &lt;br&gt;  &lt;strong style="color: rgb(255, 0, 0);"&gt;15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?&lt;/strong&gt;     &lt;div&gt;       &lt;br&gt;       A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.     &lt;/div&gt;     &lt;div&gt;       &lt;b&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;       16. Can an inner class declared inside of a method access local variables of this method?&lt;/span&gt;&lt;/b&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;br&gt;       A. It's possible if these variables are final.     &lt;/div&gt;     &lt;b&gt;     &lt;div&gt;       &lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;17. What can go wrong if you replace &amp;amp;&amp;amp; with &amp;amp; in the following code:&lt;/span&gt;&lt;br style="color: rgb(255, 0, 0);"&gt;       &lt;br style="color: rgb(255, 0, 0);"&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;span class="Code"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;String a=null; if (a!=null &amp;amp;&amp;amp; a.length()&amp;gt;10) {...}&lt;/span&gt;&lt;br style="color: rgb(255, 0, 0);"&gt;       &lt;br&gt;       &lt;/span&gt;     &lt;/div&gt;     &lt;/b&gt;     &lt;div&gt;       &lt;div&gt;         A. A single ampersand here would lead to a NullPointerException.       &lt;/div&gt;     &lt;/div&gt;   &lt;/div&gt;   &lt;br&gt;  &lt;strong style="color: rgb(255, 0, 0);"&gt;18. What's the main difference between a Vector and an ArrayList&lt;/strong&gt;   &lt;div&gt;     &lt;br&gt;     A. Java Vector class is internally synchronized and ArrayList is not.&lt;b&gt;&lt;br&gt;     &lt;br&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;19. When should the method invokeLater()be used?&lt;/span&gt;&lt;/b&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;br&gt;     A. This method is used to ensure that Swing components are updated through the event-dispatching thread.&lt;br&gt;     &lt;br&gt;     &lt;div&gt;  &lt;b style="color: rgb(255, 0, 0);"&gt;20. How can a subclass call a method or a constructor defined in a superclass?&lt;/b&gt;     &lt;/div&gt;     &lt;div&gt;       &lt;br&gt;       A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.&lt;br&gt;&lt;br&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;21. What's the difference between a queue and a stack?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;&lt;strong style="color: rgb(255, 0, 0);"&gt;22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?&lt;/strong&gt; &lt;div&gt;&lt;br&gt;A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.&lt;/div&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;23. What comes to mind when you hear about a young generation in Java?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. Garbage collection.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;24. What comes to mind when someone mentions a shallow copy in Java?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. Object cloning.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;25. If you're overriding the method equals() of an object, which other method you might also consider?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. hashCode()&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: &lt;br&gt;ArrayList or LinkedList?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. ArrayList&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;27. How would you make a copy of an entire Java object with its state?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. Have this class implement Cloneable interface and call its method clone().&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;28. How can you minimize the need of garbage collection and make the memory use more effective?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. Use object pooling and weak object references.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div style="color: rgb(255, 0, 0);"&gt;&lt;b&gt;30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?&lt;/b&gt;&lt;/div&gt;&lt;br&gt;A. You do not need to specify any access level, and Java will use a default package access level.       &lt;br&gt;       &lt;br&gt;     &lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-5444598500306534489?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/5444598500306534489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=5444598500306534489' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5444598500306534489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5444598500306534489'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/java-interview-questionsfaqspart-4-1.html' title='Java Interview Questions - Part4'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-488117661935966191</id><published>2007-01-18T17:21:00.000-08:00</published><updated>2007-01-18T17:23:17.752-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Complete Hibernate 3.0 Tutorial</title><content type='html'>&lt;h1 align="left"&gt;&lt;a title="Complete Hibernate 3.0 Tutorial" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Complete Hibernate 3.0 Tutorial&lt;/a&gt;  &lt;/h1&gt; &lt;br&gt; &lt;font color="#000080"&gt;This tutorial provide step by step instructions on using Hibernate 3.0. &lt;a href="http://www.hibernate.org/" target="_blank"&gt;Hibernate&lt;/a&gt; is popular open source object relational mapping tool for Java platform. It provides powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. The &lt;em&gt;Hibernate Query Language&lt;/em&gt;, designed as a "minimal" object-oriented extension to SQL, provides an elegant bridge between the object and relational worlds. Hibernate also allows you to express queries using native SQL or Java-based Criteria and Example queries. Hibernate is now the most popular object/relational mapping solution for Java.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;ol&gt;&lt;li&gt;&lt;a title="What is Hibernate?" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;What is Hibernate?&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Hibernate Architecture" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Architecture&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Writing First Hibernate Code" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Writing First Hibernate Code&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Understanding Hibernate O/R Mapping" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Understanding Hibernate O/R Mapping&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Understanding Hibernate  element" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Understanding Hibernate  element&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Using Hibernate  to generate id incrementally" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Using Hibernate  to generate id incrementally&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Hibernate Query Language" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Query Language&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Preparing table for HQL Examples" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Preparing table for HQL Examples&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Writing ORM for Insurance table" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Writing ORM for Insurance table&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="HQL from clause Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;HQL from clause Example&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Hibernate Select Clause" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Select Clause&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="HQL Where Clause Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;HQL Where Clause Example&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="HQL Group By Clause Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;HQL Group By Clause Example&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="HQL Order By Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;HQL Order By Example&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Hibernate Criteria Query Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Criteria Query Example&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Criteria Query Examples" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Criteria Query Examples&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a title="Hibernate Native SQL Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Native SQL Example&lt;/a&gt;  &lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-488117661935966191?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/488117661935966191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=488117661935966191' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/488117661935966191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/488117661935966191'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/complete-hibernate-3.html' title='Complete Hibernate 3.0 Tutorial'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-6027908222004368132</id><published>2007-01-18T17:20:00.003-08:00</published><updated>2007-01-18T17:23:27.644-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Writing ORM for Insurance table</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Writing ORM for Insurance table" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Writing ORM for Insurance table&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;In this lesson we will write the java class and add necessary code in the contact.hbm.xml file. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Create POJO class:&lt;br&gt; &lt;/b&gt;Here is the code of our java file (Insurance.java), which we will map to the insurance table.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.Date;&lt;/font&gt;&lt;br&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Insurance &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngInsuranceId;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String insuranceName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;int &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;investementAmount;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Date investementDate;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the insuranceName.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String getInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;insuranceName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;insuranceName The insuranceName to set.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String insuranceName&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.insuranceName = insuranceName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the investementAmount.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;int &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;getInvestementAmount&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;investementAmount;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;investementAmount The investementAmount to set.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setInvestementAmount&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;int &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;investementAmount&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.investementAmount = investementAmount;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the investementDate.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Date getInvestementDate&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;investementDate;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;investementDate The investementDate to set.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setInvestementDate&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Date investementDate&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.investementDate = investementDate;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the lngInsuranceId.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;getLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngInsuranceId;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;lngInsuranceId The lngInsuranceId to set.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.lngInsuranceId = lngInsuranceId;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Adding mappings into  contact.hbm.xml file&lt;/b&gt;&lt;br&gt; Add the following code into &lt;/font&gt;&lt;font color="#000080"&gt; contact.hbm.xml file.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&amp;lt;class name="roseindia.tutorial.hibernate.Insurance" table="insurance"&amp;gt;&lt;br&gt;  &amp;lt;id name="lngInsuranceId" type="long" column="ID" &amp;gt;&lt;br&gt;   &amp;lt;generator class="increment"/&amp;gt;&lt;br&gt;  &amp;lt;/id&amp;gt;&lt;br&gt;&lt;br&gt;  &amp;lt;property name="insuranceName"&amp;gt;&lt;br&gt;   &amp;lt;column name="insurance_name" /&amp;gt;&lt;br&gt;  &amp;lt;/property&amp;gt;&lt;br&gt;  &amp;lt;property name="investementAmount"&amp;gt;&lt;br&gt;   &amp;lt;column name="invested_amount" /&amp;gt;&lt;br&gt;  &amp;lt;/property&amp;gt;&lt;br&gt;  &amp;lt;property name="investementDate"&amp;gt;&lt;br&gt;   &amp;lt;column name="investement_date" /&amp;gt;&lt;br&gt;  &amp;lt;/property&amp;gt;&lt;br&gt; &amp;lt;/class&amp;gt;&lt;br&gt;&lt;/blockquote&gt;&lt;pre&gt;&lt;br&gt;&lt;font color="#000080"&gt;Now we have created the POJO class and necessary&lt;br&gt;mapping into contact.hbm.xml file. &lt;/font&gt;&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-6027908222004368132?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/6027908222004368132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=6027908222004368132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6027908222004368132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6027908222004368132'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/writing-orm-for-insurance-table-in-this.html' title='Writing ORM for Insurance table'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-9181789495741488983</id><published>2007-01-18T17:20:00.002-08:00</published><updated>2007-01-18T17:23:33.655-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Preparing table for HQL Examples</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Preparing table for HQL Examples" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Preparing table for HQL Examples&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;In this lesson we will create insurance table and populate it with the data. We will use insurance table for rest of the HQL tutorial.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;To create the insurance table and insert the sample data, run the following sql query:&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;/*Table structure for table `insurance` */&lt;br&gt;&lt;br&gt;drop table if exists `insurance`;&lt;br&gt;&lt;br&gt;CREATE TABLE `insurance` (&lt;br&gt;  `ID` int(11) NOT NULL default '0',&lt;br&gt;  `insurance_name` varchar(50) default NULL,&lt;br&gt;  `invested_amount` int(11) default NULL,&lt;br&gt;  `investement_date` datetime default NULL,&lt;br&gt;  PRIMARY KEY  (`ID`)&lt;br&gt;) TYPE=MyISAM;&lt;br&gt;&lt;br&gt;/*Data for the table `insurance` */&lt;br&gt;&lt;/blockquote&gt;&lt;pre&gt;&lt;br&gt;&lt;/pre&gt;&lt;blockquote&gt;insert into `insurance` values (1,'Car Insurance',1000,'2005-01-05 00:00:00');&lt;br&gt;insert into `insurance` values (2,'Life Insurance',100,'2005-10-01 00:00:00');&lt;br&gt;insert into `insurance` values (3,'Life Insurance',500,'2005-10-15 00:00:00');&lt;br&gt;insert into `insurance` values (4,'Car Insurance',2500,'2005-01-01 00:00:00');&lt;br&gt;insert into `insurance` values (5,'Dental Insurance',500,'2004-01-01 00:00:00');&lt;br&gt;insert into `insurance` values (6,'Life Insurance',900,'2003-01-01 00:00:00');&lt;br&gt;insert into `insurance` values (7,'Travel Insurance',2000,'2005-02-02 00:00:00');&lt;br&gt;insert into `insurance` values (8,'Travel Insurance',600,'2005-03-03 00:00:00');&lt;br&gt;insert into `insurance` values (9,'Medical Insurance',700,'2005-04-04 00:00:00');&lt;br&gt;insert into `insurance` values (10,'Medical Insurance',900,'2005-03-03 00:00:00');&lt;br&gt;insert into `insurance` values (11,'Home Insurance',800,'2005-02-02 00:00:00');&lt;br&gt;insert into `insurance` values (12,'Home Insurance',750,'2004-09-09 00:00:00');&lt;br&gt;insert into `insurance` values (13,'Motorcycle Insurance',900,'2004-06-06 00:00:00');&lt;br&gt;&lt;/blockquote&gt;&lt;pre&gt;&lt;br&gt;&lt;font color="#000080"&gt;Above Sql query will create insurance table and add the&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;div&gt;&lt;table bgcolor="#cccccc" border="1" cellpadding="1" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="medium" bgcolor="silver"&gt;&lt;b&gt;ID&lt;/b&gt;&lt;/td&gt;       &lt;td class="medium" bgcolor="silver"&gt;&lt;b&gt;insurance_name&lt;/b&gt;&lt;/td&gt;       &lt;td class="medium" bgcolor="silver"&gt;&lt;b&gt;invested_amount&lt;/b&gt;&lt;/td&gt;       &lt;td class="medium" bgcolor="silver"&gt;&lt;b&gt;investement_date&lt;/b&gt;&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;1&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Car Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;1000&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-01-05 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;2&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Life Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;100&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-10-01 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;3&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Life Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;500&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-10-15 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;4&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Car Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2500&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-01-01 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;5&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Dental Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;500&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2004-01-01 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;6&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Life Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;900&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2003-01-01 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;7&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Travel Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2000&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-02-02 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;8&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Travel Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;600&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-03-03 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;9&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Medical Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;700&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-04-04 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;10&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Medical Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;900&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-03-03 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;11&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Home Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;800&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-02-02 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;12&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Home Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;750&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2004-09-09 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;13&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Motorcycle Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;900&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2004-06-06 00:00:00&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td class="normal" valign="top"&gt;14&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;Motorcycle Insurance&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;780&lt;/td&gt;       &lt;td class="normal" valign="top"&gt;2005-03-03 00:00:00&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;pre&gt;&lt;font color="#000080"&gt;In the future lessons we will use this table to write&lt;br&gt;different HQL examples.&lt;/font&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-9181789495741488983?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/9181789495741488983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=9181789495741488983' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/9181789495741488983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/9181789495741488983'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/preparing-table-for-hql-examples-in.html' title='Preparing table for HQL Examples'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-2151144523050705614</id><published>2007-01-18T17:20:00.001-08:00</published><updated>2007-01-18T17:23:42.126-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Using Hibernate  to generate id incrementally</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Using Hibernate  to generate id incrementally" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Using Hibernate  to generate id incrementally&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;As we have seen in the last section that the increment class generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. In this lesson I will show you how to write running program to demonstrate it. You should not use this method to generate the primary key in case of clustured environment.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;In this we will create a new table in database, add mappings in the contact.hbm.xml file, develop the POJO class (Book.java), write the program to test it out.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;font color="#000080"&gt;Create Table in the mysql database:&lt;br&gt; &lt;/font&gt;&lt;/b&gt;&lt;font color="#000080"&gt;User the following sql statement to create a new table in the database.&lt;br&gt; &lt;/font&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;font color="#0000ff"&gt; CREATE TABLE `book` ( &lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;           `id` int(11) NOT NULL default '0', &lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;           `bookname` varchar(50) default NULL, &lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;           PRIMARY KEY  (`id`) &lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;         ) TYPE=MyISAM &lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Developing POJO Class (Book.java)&lt;/b&gt;&lt;br&gt; Book.java is our POJO class which is to be persisted to the database table "book". &lt;br&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;br&gt; &lt;/code&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Book &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngBookId;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String strBookName;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the lngBookId.&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;getLngBookId&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngBookId;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;lngBookId The lngBookId to set.&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setLngBookId&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lngBookId&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.lngBookId = lngBookId;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Returns the strBookName.&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String getStrBookName&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;strBookName;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;strBookName The strBookName to set.&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setStrBookName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String strBookName&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;.strBookName = strBookName;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Adding Mapping entries to contact.hbm.xml&lt;/b&gt;&lt;br&gt; Add the following mapping code into the contact.hbm.xml file&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;   &amp;lt;class name="roseindia.tutorial.hibernate.Book" table="book"&amp;gt;&lt;br&gt;              &amp;lt;id name="lngBookId" type="long" column="id" &amp;gt;&lt;br&gt;                 &lt;b&gt;&amp;lt;generator class="increment"/&amp;gt;&lt;br&gt;         &lt;/b&gt;     &amp;lt;/id&amp;gt;&lt;br&gt;         &lt;br&gt;             &amp;lt;property name="strBookName"&amp;gt;&lt;br&gt;                  &amp;lt;column name="bookname" /&amp;gt;&lt;br&gt;              &amp;lt;/property&amp;gt;&lt;br&gt;  &amp;lt;/class&amp;gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;Note that we have used &lt;b&gt;increment&lt;/b&gt; for the generator class. *&lt;font size="2"&gt;After adding the entries to the xml file copy it to the bin directory of your hibernate eclipse project(this step is required if you are using eclipse).&lt;/font&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Write the client program and test it out&lt;/b&gt;&lt;br&gt; Here is the code of our client program to test the application.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Hibernate Imports&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.SessionFactory;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.Configuration;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;IdIncrementExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session =sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Transaction tx = session.beginTransaction&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Create new instance of Contact and set values in it by reading them from form object&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Inserting Book object into database.."&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;Book book = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Book&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;book.setStrBookName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Hibernate Tutorial"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session.save&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;book&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Book object persisted to the database."&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;tx.commit&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;session.flush&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;finally&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;To test the program Select Run-&amp;gt;Run As -&amp;gt; Java Application from the eclipse menu bar. This will create a new record into the book table.&lt;/font&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-2151144523050705614?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/2151144523050705614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=2151144523050705614' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2151144523050705614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2151144523050705614'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/using-hibernate-to-generate-id.html' title='Using Hibernate  to generate id incrementally'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-656241571453050661</id><published>2007-01-18T17:20:00.000-08:00</published><updated>2007-01-18T17:23:47.597-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Query Language</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Hibernate Query Language" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Query Language&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;Hibernate Query Language or HQL for short is extremely powerful query language. HQL is much like SQL  and are case-insensitive, except for the names of the Java Classes and properties. Hibernate Query Language is used to execute queries against database. Hibernate automatically generates the sql query and execute it against underlying database if HQL is used in the application. HQL is based on the relational object models and makes the SQL object oriented. Hibernate Query Language uses Classes and properties instead of tables and columns. Hibernate Query Language is extremely powerful and it supports Polymorphism, Associations, Much less verbose than SQL.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;There are other options that can be used while using Hibernate. These are &lt;b&gt;Query By Criteria (QBC)&lt;/b&gt; and &lt;b&gt;Query BY Example (QBE) &lt;/b&gt;using Criteria API and the &lt;b&gt;Native SQL&lt;/b&gt; queries. In this lesson we will understand HQL in detail.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;font color="#000080"&gt;Why to use HQL?&lt;/font&gt;&lt;/b&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Full support for relational operations: &lt;/b&gt;HQL     allows representing SQL queries in the form of objects. Hibernate Query     Language uses Classes and properties instead of tables and columns.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Return result as Object: &lt;/b&gt;The HQL queries     return the query result(s) in the form of object(s), which is easy to use.     This elemenates the need of creating the object and populate the data from     result set.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Polymorphic Queries:&lt;/b&gt; HQL fully supports &lt;b&gt;polymorphic     queries&lt;/b&gt;. Polymorphic queries results the query results along with all     the child objects if any.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Easy to Learn:&lt;/b&gt; Hibernate Queries are easy to     learn and it can be easily implemented in the applications.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Support for Advance features:&lt;/b&gt; HQL contains     many advance features such as pagination, fetch join with dynamic profiling,     Inner/outer/full joins, Cartesian products. It also supports Projection,     Aggregation (max, avg) and grouping, Ordering, Sub queries and SQL function     calls.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;Database independent:&lt;/b&gt; Queries written in HQL     are database independent (If database supports the underlying feature).&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font color="#000080"&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Understanding HQL Syntax&lt;br&gt; &lt;/b&gt;Any Hibernate Query Language may consist of following elements:&lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;font color="#000080"&gt;Clauses&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Aggregate functions&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Subqueries&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Clauses in the HQL are:&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;font color="#000080"&gt;from&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;select&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;where&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;order by&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;group by&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Aggregate functions are:&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;     &lt;font color="#000080"&gt;     avg(...), sum(...), min(...), max(...) &lt;/font&gt;     &lt;/li&gt;&lt;li&gt;     &lt;font color="#000080"&gt;count(*)&lt;/font&gt;     &lt;/li&gt;&lt;li&gt;     &lt;font color="#000080"&gt;count(...), count(distinct ...), count(all...)&lt;/font&gt;     &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Subqueries&lt;/b&gt;&lt;br&gt; Subqueries are nothing but its a query within another query. Hibernate supports Subqueries if the underlying database supports it.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;   &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-656241571453050661?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/656241571453050661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=656241571453050661' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/656241571453050661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/656241571453050661'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-query-language-hibernate.html' title='Hibernate Query Language'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-5826727635362009295</id><published>2007-01-18T17:18:00.005-08:00</published><updated>2007-01-18T17:23:55.346-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Understanding Hibernate  element</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Understanding Hibernate  element" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Understanding Hibernate  element&lt;/a&gt;  &lt;/h1&gt; &lt;br&gt; &lt;p&gt;   &lt;font color="#000080"&gt;In this lesson you will learn about hibernate &amp;lt;generator&amp;gt; method in detail. Hibernate generator element generates the primary key for new record. There are many options provided by the generator method to be used in different situations. &lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;&lt;b&gt;The &amp;lt;generator&amp;gt; element&lt;/b&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;This is the optional element under &amp;lt;id&amp;gt; element. The &amp;lt;generator&amp;gt; element is used to specify the class name to be used to generate the primary key for new record while saving a new record. The &amp;lt;param&amp;gt; element is used to pass the parameter (s) to the  class. Here is the example of generator element from our first application:&lt;br&gt;   &lt;/font&gt;&lt;b&gt;&lt;font color="#0000ff"&gt;&amp;lt;generator class="assigned"/&amp;gt;&lt;/font&gt;&lt;font color="#000080"&gt;&lt;br&gt;   &lt;/font&gt;&lt;/b&gt;&lt;font color="#000080"&gt;In this case &amp;lt;generator&amp;gt; element do not generate the primary key and it is required to set the primary key value before calling save() method.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;font color="#000080"&gt;Here are the list of some commonly used generators in hibernate:&lt;/font&gt; &lt;/p&gt; &lt;p&gt;   &lt;br&gt; &lt;/p&gt; &lt;div&gt;&lt;table bgcolor="#cccccc" border="1" cellpadding="0" cellspacing="0" width="80%"&gt;   &lt;tbody&gt;   &lt;tr bgcolor="#cccccc"&gt;     &lt;td bgcolor="#ffff99" width="16%"&gt;       &lt;b&gt;Generator&lt;/b&gt;     &lt;/td&gt;     &lt;td bgcolor="#ffff99" width="84%"&gt;       &lt;b&gt;Description&lt;/b&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       increment     &lt;/td&gt;     &lt;td width="84%"&gt;       It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not the used in the clustered environment.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       identity     &lt;/td&gt;     &lt;td width="84%"&gt;       It supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       sequence     &lt;/td&gt;     &lt;td width="84%"&gt;       The sequence generator uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       hilo     &lt;/td&gt;     &lt;td width="84%"&gt;       The hilo generator uses a hi/lo algorithm to efficiently generate identifiers of type long, short or int, given a table and column (by default hibernate_unique_key and next_hi respectively) as a source of hi values. The hi/lo algorithm generates identifiers that are unique only for a particular database. Do not use this generator with connections enlisted with JTA or with a user-supplied connection.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       seqhilo     &lt;/td&gt;     &lt;td width="84%"&gt;       The seqhilo generator uses a hi/lo algorithm to efficiently generate identifiers of type long, short or int, given a named database sequence.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       uuid     &lt;/td&gt;     &lt;td width="84%"&gt;       The uuid generator uses a 128-bit UUID algorithm to generate identifiers of type string, unique within a network (the IP address is used). The UUID is encoded as a string of hexadecimal digits of length 32.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       guid     &lt;/td&gt;     &lt;td width="84%"&gt;       It uses a database-generated GUID string on MS SQL Server and MySQL.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       native     &lt;/td&gt;     &lt;td width="84%"&gt;       It picks identity, sequence or hilo depending upon the capabilities of the underlying database.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       assigned     &lt;/td&gt;     &lt;td width="84%"&gt;       lets the application to assign an identifier to the object before save() is called. This is the default strategy if no &amp;lt;generator&amp;gt; element is specified.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       select     &lt;/td&gt;     &lt;td width="84%"&gt;       retrieves a primary key assigned by a database trigger by selecting the row by some unique key and retrieving the primary key value.     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%"&gt;       foreign     &lt;/td&gt;     &lt;td width="84%"&gt;       uses the identifier of another associated object. Usually used in conjunction with a &amp;lt;one-to-one&amp;gt; primary key association.     &lt;/td&gt;   &lt;/tr&gt;   &lt;/tbody&gt; &lt;/table&gt;&lt;/div&gt; &lt;p&gt; &lt;/p&gt; &lt;br&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-5826727635362009295?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/5826727635362009295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=5826727635362009295' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5826727635362009295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5826727635362009295'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/understanding-hibernate-element-in-this.html' title='Understanding Hibernate  element'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-1012569839732580019</id><published>2007-01-18T17:18:00.004-08:00</published><updated>2007-01-18T17:24:03.801-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Understanding Hibernate O/R Mapping</title><content type='html'>&lt;a title="Understanding Hibernate O/R Mapping" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Understanding Hibernate O/R Mapping&lt;/a&gt; &lt;br&gt;&lt;font style="font-weight: bold;" size="3"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;In the last example we created contact.hbm.xml to map Contact Object to the Contact table in the database. Now let's understand the each component of the mapping file.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#000080"&gt;To recall here is the content of contact.hbm.xml:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;blockquote&gt;&lt;font color="#000000"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;         &amp;lt;!DOCTYPE hibernate-mapping PUBLIC &lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;         &lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;         &amp;lt;hibernate-mapping&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;            &amp;lt;id name="id" type="long" column="ID" &amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;            &amp;lt;generator class="assigned"/&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;/id&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;         &lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;property name="firstName"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;              &amp;lt;column name="FIRSTNAME" /&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;/property&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;property name="lastName"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;             &amp;lt;column name="LASTNAME"/&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;/property&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;property name="email"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;             &amp;lt;column name="EMAIL"/&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;           &amp;lt;/property&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;          &amp;lt;/class&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;font color="#000000"&gt;         &amp;lt;/hibernate-mapping&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;/blockquote&gt;&lt;font color="#000000"&gt;&lt;br&gt;&lt;/font&gt; Hibernate mapping documents are simple xml documents. Here are important elements of the mapping file:.&lt;br&gt; &lt;ol&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;&amp;lt;hibernate-mapping&amp;gt; element&lt;/b&gt;&lt;br&gt;     The first or root element of hibernate mapping document is     &amp;lt;hibernate-mapping&amp;gt; element. Between the &amp;lt;&lt;b&gt;hibernate-mapping&amp;gt;&lt;/b&gt;     tag class element(s) are present.&lt;br&gt;             &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;     &lt;b&gt; &amp;lt;class&amp;gt; element&lt;/b&gt;&lt;br&gt;     The &amp;lt;Class&amp;gt; element maps the class object with corresponding entity     in the database. It also tells what table in the database has to access and     what column in that table it should use. Within one &amp;lt;hibernate-mapping&amp;gt; element,     several &amp;lt;class&amp;gt; mappings are possible.&lt;br&gt;            &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;     &lt;b&gt; &amp;lt;id&amp;gt; element&lt;/b&gt;&lt;br&gt;     The &amp;lt;id&amp;gt; element in unique identifier to identify and object. In fact     &amp;lt;id&amp;gt; element map with the primary key of the table. In our code :&lt;br&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt; &amp;lt;id name="id" type="long" column="ID" &amp;gt;&lt;br&gt;     &lt;/font&gt;&lt;font color="#000080"&gt;primary key maps to the &lt;b&gt;ID&lt;/b&gt; field of the     table &lt;b&gt;CONTACT&lt;/b&gt;. The attributes of the &lt;code&gt;id&lt;/code&gt; element are:&lt;/font&gt;     &lt;ul type="disc"&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;name: &lt;/b&gt;The property name used by the         persistent class.&lt;/font&gt;       &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;column:&lt;/b&gt; The column used to store the         primary key value.&lt;/font&gt;       &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;type:&lt;/b&gt; The Java data type used.&lt;/font&gt;       &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;unsaved-value:&lt;/b&gt; This is the value used to         determine if a class has been made persistent. If the value of the id         attribute is null, then it means that this object has not been         persisted.&lt;br&gt;             &lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;     &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt;&amp;lt;generator&amp;gt; element&lt;/b&gt;&lt;br&gt;     The &lt;b&gt; &amp;lt;generator&amp;gt; &lt;/b&gt;method&lt;b&gt; &lt;/b&gt;is used to generate the primary     key for the new record. Here is some of the commonly used generators :&lt;br&gt;        &lt;br&gt;     &lt;b&gt;*&lt;/b&gt; &lt;b&gt; Increment &lt;/b&gt; - This is used to generate primary keys of type long, short or int that are     unique only. It should not be used in the clustered deployment environment.&lt;br&gt;        &lt;br&gt;     &lt;b&gt;*  Sequence&lt;/b&gt; - Hibernate can also use the sequences to generate     the primary key. It can be used with DB2, PostgreSQL, Oracle, SAP DB     databases.&lt;br&gt;       &lt;br&gt;     &lt;b&gt;* Assigned&lt;/b&gt; - Assigned method is used when application code generates     the primary key. &lt;br&gt;        &lt;br&gt;        &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;&lt;b&gt; &amp;lt;property&amp;gt; element&lt;/b&gt;&lt;br&gt;     The &lt;code&gt;property&lt;/code&gt; elements define standard Java attributes and their     mapping into database schema. The &lt;code&gt;property&lt;/code&gt; element supports the     &lt;code&gt;column&lt;/code&gt; child element to specify additional properties, such as     the index name on a column or a specific column type. &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-1012569839732580019?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/1012569839732580019/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=1012569839732580019' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1012569839732580019'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1012569839732580019'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/understanding-hibernate-or-mapping-in.html' title='Understanding Hibernate O/R Mapping'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-1820832139095825819</id><published>2007-01-18T17:18:00.003-08:00</published><updated>2007-01-18T17:24:47.366-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Native SQL Example</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Hibernate Native SQL Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Native SQL Example&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;b&gt;Native SQL&lt;/b&gt; is handwritten SQL for all database operations like create, update, delete and select. &lt;b&gt;Hibernate Native Query&lt;/b&gt; also supports stored procedures. Hibernate allows you to run Native SQL Query for all the database operations, so you can use your existing handwritten sql with Hibernate, this also helps you in migrating your SQL/JDBC based application to Hibernate.&lt;/p&gt; &lt;p&gt;In this example we will show you how you can use Native SQL with hibernate. You will learn how to use Native to calculate average and then in another example select all the objects from table.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Here is the code of Hibernate Native SQL:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.criterion.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;NativeQueryExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session =sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Hibernate Native Query Average Examle*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;String sql =&lt;/font&gt;&lt;font color="#2a00ff"&gt;"select stddev(ins.invested_amount) as stdErr, "&lt;/font&gt;&lt;font color="#000000"&gt;+&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#2a00ff"&gt;" avg(ins.invested_amount) as mean "&lt;/font&gt;&lt;font color="#000000"&gt;+&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#2a00ff"&gt;" from insurance ins"&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;Query query = session.createSQLQuery&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;sql&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;.addScalar&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"stdErr"&lt;/font&gt;&lt;font color="#000000"&gt;,Hibernate.DOUBLE&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#000000"&gt;addScalar&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"mean"&lt;/font&gt;&lt;font color="#000000"&gt;,Hibernate.DOUBLE&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Double [] amount = (Double []) query.uniqueResult(); &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;Object &lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;amount = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Object &lt;/font&gt;&lt;font color="#000000"&gt;[]) &lt;/font&gt;&lt;font color="#000000"&gt;query.uniqueResult&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"mean amount: " &lt;/font&gt;&lt;font color="#000000"&gt;+ amount&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"stdErr amount: " &lt;/font&gt;&lt;font color="#000000"&gt;+ amount&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Example to show Native query to select all the objects from database */&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Selecting all the objects from insurance table */&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;List insurance = session.createSQLQuery&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"select  {ins.*}  from insurance ins"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;.addEntity&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ins"&lt;/font&gt;&lt;font color="#000000"&gt;, Insurance.&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;.list&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;for &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Iterator it = insurance.iterator&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;; it.hasNext&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;Insurance insuranceObject = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance&lt;/font&gt;&lt;font color="#000000"&gt;) &lt;/font&gt;&lt;font color="#000000"&gt;it.next&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ID: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insuranceObject.getLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Name: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insuranceObject.getInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;e.printStackTrace&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Following query is used to calculate the average of  invested amount:&lt;/p&gt; &lt;font size="2"&gt; &lt;/font&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font color="#008000"&gt;/*Hibernate Native Query Average Examle*/&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;String sql ="select stddev(ins.invested_amount) as stdErr, "+ " avg(ins.invested_amount) as mean "+ " from insurance ins";&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;The following code:&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;    Query query = session.createSQLQuery(sql).addScalar("stdErr",Hibernate.DOUBLE).&lt;br&gt;      addScalar("mean",Hibernate.DOUBLE);&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;          &lt;p&gt;Creates a new instance of SQLQuery for the given SQL query string and the entities returned by the query are detached. &lt;/p&gt; &lt;p&gt;To return all the entities from database we have used the following query:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;  /* Example to show Native query to select all the objects from database */&lt;br&gt;     /* Selecting all the objects from insurance table */&lt;br&gt;     List insurance = session.createSQLQuery("&lt;b&gt;select  {ins.*}  from insurance ins&lt;/b&gt;")&lt;br&gt; .addEntity("&lt;b&gt;ins&lt;/b&gt;", &lt;b&gt;Insurance.class&lt;/b&gt;)&lt;br&gt;       .list();&lt;br&gt;     for (Iterator it = insurance.iterator(); it.hasNext();) {&lt;br&gt;     Insurance insuranceObject = (Insurance) it.next();&lt;br&gt;     System.out.println("ID: " + insuranceObject.getLngInsuranceId());&lt;br&gt;    System.out.println("Name: " + insuranceObject.getInsuranceName());&lt;br&gt;    }&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;When you run the program through it should display the following result:&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font color="#ff0000" size="2"&gt;log4j:WARN No appenders         could be found for logger (org.hibernate.cfg.Environment).         &lt;p&gt;log4j:WARN Please initialize the log4j system properly.&lt;/p&gt;         &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;         &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Hibernate: select stddev(ins.invested_amount) as stdErr,         avg(ins.invested_amount) as mean from insurance ins&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;mean amount: 592.1584&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;stdErr amount: 923.5714&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Hibernate: select ins.ID as ID0_, ins.insurance_name as         insurance2_2_0_, ins.invested_amount as invested3_2_0_,         ins.investement_date as investem4_2_0_ from insurance ins&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 1&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 2&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 3&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 4&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;......&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;.......&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;             &lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;In this example you learned how to use Native Query with Hibernate. &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-1820832139095825819?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/1820832139095825819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=1820832139095825819' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1820832139095825819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/1820832139095825819'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-native-sql-example-native-sql.html' title='Hibernate Native SQL Example'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-8243029504797464177</id><published>2007-01-18T17:18:00.002-08:00</published><updated>2007-01-18T17:24:53.726-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Native SQL Example</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Hibernate Native SQL Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Native SQL Example&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;b&gt;Native SQL&lt;/b&gt; is handwritten SQL for all database operations like create, update, delete and select. &lt;b&gt;Hibernate Native Query&lt;/b&gt; also supports stored procedures. Hibernate allows you to run Native SQL Query for all the database operations, so you can use your existing handwritten sql with Hibernate, this also helps you in migrating your SQL/JDBC based application to Hibernate.&lt;/p&gt; &lt;p&gt;In this example we will show you how you can use Native SQL with hibernate. You will learn how to use Native to calculate average and then in another example select all the objects from table.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Here is the code of Hibernate Native SQL:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.criterion.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;NativeQueryExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session =sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Hibernate Native Query Average Examle*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;String sql =&lt;/font&gt;&lt;font color="#2a00ff"&gt;"select stddev(ins.invested_amount) as stdErr, "&lt;/font&gt;&lt;font color="#000000"&gt;+&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#2a00ff"&gt;" avg(ins.invested_amount) as mean "&lt;/font&gt;&lt;font color="#000000"&gt;+&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#2a00ff"&gt;" from insurance ins"&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;Query query = session.createSQLQuery&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;sql&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;.addScalar&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"stdErr"&lt;/font&gt;&lt;font color="#000000"&gt;,Hibernate.DOUBLE&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;.&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#000000"&gt;addScalar&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"mean"&lt;/font&gt;&lt;font color="#000000"&gt;,Hibernate.DOUBLE&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Double [] amount = (Double []) query.uniqueResult(); &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;Object &lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;amount = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Object &lt;/font&gt;&lt;font color="#000000"&gt;[]) &lt;/font&gt;&lt;font color="#000000"&gt;query.uniqueResult&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"mean amount: " &lt;/font&gt;&lt;font color="#000000"&gt;+ amount&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"stdErr amount: " &lt;/font&gt;&lt;font color="#000000"&gt;+ amount&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Example to show Native query to select all the objects from database */&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#3f7f5f"&gt;/* Selecting all the objects from insurance table */&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;List insurance = session.createSQLQuery&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"select  {ins.*}  from insurance ins"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;.addEntity&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ins"&lt;/font&gt;&lt;font color="#000000"&gt;, Insurance.&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;.list&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;for &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Iterator it = insurance.iterator&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;; it.hasNext&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;Insurance insuranceObject = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance&lt;/font&gt;&lt;font color="#000000"&gt;) &lt;/font&gt;&lt;font color="#000000"&gt;it.next&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ID: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insuranceObject.getLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Name: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insuranceObject.getInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;e.printStackTrace&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Following query is used to calculate the average of  invested amount:&lt;/p&gt; &lt;font size="2"&gt; &lt;/font&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font color="#008000"&gt;/*Hibernate Native Query Average Examle*/&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;String sql ="select stddev(ins.invested_amount) as stdErr, "+ " avg(ins.invested_amount) as mean "+ " from insurance ins";&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;The following code:&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;    Query query = session.createSQLQuery(sql).addScalar("stdErr",Hibernate.DOUBLE).&lt;br&gt;      addScalar("mean",Hibernate.DOUBLE);&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;          &lt;p&gt;Creates a new instance of SQLQuery for the given SQL query string and the entities returned by the query are detached. &lt;/p&gt; &lt;p&gt;To return all the entities from database we have used the following query:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;  /* Example to show Native query to select all the objects from database */&lt;br&gt;     /* Selecting all the objects from insurance table */&lt;br&gt;     List insurance = session.createSQLQuery("&lt;b&gt;select  {ins.*}  from insurance ins&lt;/b&gt;")&lt;br&gt; .addEntity("&lt;b&gt;ins&lt;/b&gt;", &lt;b&gt;Insurance.class&lt;/b&gt;)&lt;br&gt;       .list();&lt;br&gt;     for (Iterator it = insurance.iterator(); it.hasNext();) {&lt;br&gt;     Insurance insuranceObject = (Insurance) it.next();&lt;br&gt;     System.out.println("ID: " + insuranceObject.getLngInsuranceId());&lt;br&gt;    System.out.println("Name: " + insuranceObject.getInsuranceName());&lt;br&gt;    }&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;When you run the program through it should display the following result:&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font color="#ff0000" size="2"&gt;log4j:WARN No appenders         could be found for logger (org.hibernate.cfg.Environment).         &lt;p&gt;log4j:WARN Please initialize the log4j system properly.&lt;/p&gt;         &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;         &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Hibernate: select stddev(ins.invested_amount) as stdErr,         avg(ins.invested_amount) as mean from insurance ins&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;mean amount: 592.1584&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;stdErr amount: 923.5714&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Hibernate: select ins.ID as ID0_, ins.insurance_name as         insurance2_2_0_, ins.invested_amount as invested3_2_0_,         ins.investement_date as investem4_2_0_ from insurance ins&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 1&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 2&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 3&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 4&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;......&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;.......&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;             &lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;In this example you learned how to use Native Query with Hibernate. &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-8243029504797464177?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/8243029504797464177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=8243029504797464177' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8243029504797464177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8243029504797464177'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-native-sql-example-native-sql_18.html' title='Hibernate Native SQL Example'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-8320893327748153426</id><published>2007-01-18T17:18:00.001-08:00</published><updated>2007-01-18T17:24:58.411-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Architecture</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Hibernate Architecture" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Architecture&lt;/a&gt;  &lt;/h1&gt; &lt;font color="#000080"&gt;In this lesson you will learn the architecture of Hibernate.  The following diagram describes the high level architecture of hibernate:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;img style="height: 375px; width: 375px;" title="Hibernate Architecture" src="http://docs.google.com/File?id=dgz5f8nn_128f76jqk" align="middle"&gt; &lt;br&gt;&lt;br&gt;&lt;p align="left"&gt;&lt;font color="#000080"&gt;The above diagram shows that Hibernate is using the database and configuration data to provide persistence services (and&lt;/font&gt; &lt;font color="#000080"&gt;persistent objects) to the application.&lt;/font&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;br&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;font color="#000080"&gt;To use Hibernate, it is required to create Java classes that represents the table in the database and then map the instance variable in the class with the columns in the database. Then Hibernate can be used to perform operations on the database like select, insert, update and delete the records in the table. Hibernate automatically creates the query to perform these operations.&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;Hibernate architecture has three main components:&lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;     &lt;p align="left"&gt;&lt;font color="#000080"&gt;&lt;b&gt;Connection Management&lt;/b&gt;&lt;br&gt;     Hibernate Connection management service provide efficient management of the     database connections. Database connection is the most expensive part of     interacting with the database as it requires a lot of resources of open and     close the database connection.&lt;br&gt;       &lt;/font&gt;   &lt;/p&gt;&lt;/li&gt;&lt;li&gt;     &lt;p align="left"&gt;&lt;font color="#000080"&gt;&lt;b&gt;Transaction management:&lt;/b&gt;&lt;br&gt;     Transaction management service provide the ability to the user to execute     more than one database statements at a time.&lt;br&gt;       &lt;/font&gt;   &lt;/p&gt;&lt;/li&gt;&lt;li&gt;     &lt;p align="left"&gt;&lt;font color="#000080"&gt;&lt;b&gt;Object relational mapping:&lt;/b&gt;&lt;br&gt;     Object relational mapping is technique of mapping the data representation     from an object model to a relational data model. This part of the hibernate     is used to select, insert, update and delete the records form the underlying     table. When we pass an object to a &lt;b&gt;Session.save()&lt;/b&gt; method, Hibernate     reads the state of the variables of that object and executes the necessary     query.&lt;/font&gt;   &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;Hibernate is very good tool as far as object relational mapping is concern, but in terms of connection management and transaction management, it is lacking in performance and capabilities. So usually hibernate is being used with other connection management and transaction management tools. For example apache DBCP is used for connection pooling with the Hibernate.&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;Hibernate provides a lot of flexibility in use. It is called "&lt;b&gt;Lite&lt;/b&gt;" architecture when we only uses the object relational mapping component. While in "&lt;b&gt;Full Cream&lt;/b&gt;" architecture all the three component Object Relational mapping, Connection Management and Transaction Management) are used.&lt;/font&gt;&lt;/p&gt;&lt;br&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-8320893327748153426?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/8320893327748153426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=8320893327748153426' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8320893327748153426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8320893327748153426'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-architecture-in-this-lesson.html' title='Hibernate Architecture'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-5063076581586400991</id><published>2007-01-18T17:18:00.000-08:00</published><updated>2007-01-18T17:25:08.386-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Writing First Hibernate Code</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Writing First Hibernate Code" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Writing First Hibernate Code&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;In this section I will show you how to create a simple program to insert record in MySQL database. You can run this program from Eclipse or from command prompt as well. I am assuming that you are familiar with MySQL and Eclipse environment.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Configuring Hibernate&lt;/b&gt;&lt;br&gt; In this application Hibernate provided connection pooling and transaction management is used for simplicity. Hibernate uses the hibernate.cfg.xml to create the connection pool and setup required environment.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;font color="#000080"&gt; Here is the code:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font color="#000000"&gt;&amp;lt;?xml version='1.0' encoding='utf-8'?&amp;gt;&lt;br&gt;         &amp;lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br&gt;         "-//Hibernate/Hibernate Configuration DTD//EN"&lt;br&gt;         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&amp;gt;&lt;br&gt;         &lt;br&gt;         &amp;lt;hibernate-configuration&amp;gt;&lt;br&gt;  &amp;lt;session-factory&amp;gt;&lt;br&gt;               &amp;lt;property name="hibernate.connection.driver_class"&amp;gt;com.mysql.jdbc.Driver&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="hibernate.connection.url"&amp;gt;&lt;b&gt;jdbc:mysql://localhost/hibernatetutorial&lt;/b&gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="hibernate.connection.username"&amp;gt;&lt;b&gt;root&lt;/b&gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="hibernate.connection.password"&amp;gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="hibernate.connection.pool_size"&amp;gt;10&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="show_sql"&amp;gt;&lt;b&gt;true&lt;/b&gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property name="dialect"&amp;gt;&lt;b&gt;org.hibernate.dialect.MySQLDialect&lt;/b&gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;property         name="hibernate.hbm2ddl.auto"&amp;gt;&lt;b&gt;update&lt;/b&gt;&amp;lt;/property&amp;gt;&lt;br&gt;               &amp;lt;!-- Mapping files --&amp;gt;&lt;br&gt;               &amp;lt;mapping resource="&lt;b&gt;contact.hbm.xml&lt;/b&gt;"/&amp;gt;&lt;br&gt;  &amp;lt;/session-factory&amp;gt;&lt;br&gt;         &amp;lt;/hibernate-configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;In the above configuration file we specified to use the "&lt;b&gt;hibernatetutorial"&lt;/b&gt; which is running on &lt;b&gt;localhost&lt;/b&gt; and the user of the database is root with no password. The &lt;b&gt;dialect&lt;/b&gt; property  is &lt;b&gt;org.hibernate.dialect.MySQLDialect&lt;/b&gt; which tells the Hibernate that we are using MySQL Database. Hibernate supports many database. With the use of the &lt;a title="Visit page outside Confluence" href="http://www.hibernate.org/" target="_blank"&gt;Hibernate&lt;/a&gt; (Object/Relational Mapping and Transparent Object Persistence for Java and SQL Databases),  we can use the following databases dialect type property:&lt;/font&gt;&lt;/p&gt; &lt;ul class="star"&gt;&lt;li&gt;&lt;font color="#000080"&gt;DB2 - &lt;tt class="monospaced"&gt;org.hibernate.dialect.DB2Dialect&lt;/tt&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;HypersonicSQL - &lt;tt class="monospaced"&gt;org.hibernate.dialect.HSQLDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Informix - &lt;tt class="monospaced"&gt;org.hibernate.dialect.InformixDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Ingres - &lt;tt class="monospaced"&gt;org.hibernate.dialect.IngresDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Interbase - &lt;tt class="monospaced"&gt;org.hibernate.dialect.InterbaseDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Pointbase - &lt;tt class="monospaced"&gt;org.hibernate.dialect.PointbaseDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;PostgreSQL - &lt;tt class="monospaced"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Mckoi SQL - &lt;tt class="monospaced"&gt;org.hibernate.dialect.MckoiDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Microsoft SQL Server - &lt;tt class="monospaced"&gt;org.hibernate.dialect.SQLServerDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;MySQL - &lt;tt class="monospaced"&gt;org.hibernate.dialect.MySQLDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Oracle (any version) - &lt;tt class="monospaced"&gt;org.hibernate.dialect.OracleDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Oracle 9 - &lt;tt class="monospaced"&gt;org.hibernate.dialect.Oracle9Dialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Progress - &lt;tt class="monospaced"&gt;org.hibernate.dialect.ProgressDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;FrontBase - &lt;tt class="monospaced"&gt;org.hibernate.dialect.FrontbaseDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;SAP DB - &lt;tt class="monospaced"&gt;org.hibernate.dialect.SAPDBDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Sybase - &lt;tt class="monospaced"&gt;org.hibernate.dialect.SybaseDialect&lt;/tt&gt;&lt;/font&gt;   &lt;/li&gt;&lt;li&gt;&lt;font color="#000080"&gt;Sybase Anywhere - &lt;tt class="monospaced"&gt;org.hibernate.dialect.SybaseAnywhereDialect&lt;/tt&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font color="#000080"&gt;The  &amp;lt;mapping resource="&lt;b&gt;contact.hbm.xml&lt;/b&gt;"/&amp;gt; property is the mapping for our contact table.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Writing First Persistence Class&lt;/b&gt;&lt;br&gt; Hibernate uses the Plain Old Java Objects (POJOs) classes to map to the database table. We can configure the variables to map to the database column. Here is the code for Contact.java:&lt;/font&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Contact &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String firstName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String lastName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String email;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;private &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;id;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Email&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String getEmail&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;email;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;First Name&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String getFirstName&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;firstName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/** &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;Last name&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;String getLastName&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;lastName;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;string Sets the Email&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setEmail&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String string&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;email = string;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;string Sets the First Name&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setFirstName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String string&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;firstName = string;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;string sets the Last Name&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setLastName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String string&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;lastName = string;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@return &lt;/font&gt;&lt;font color="#3f5fbf"&gt;ID Returns ID&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;getId&lt;/font&gt;&lt;font color="#000000"&gt;() {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;id;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;* &lt;/font&gt;&lt;font color="#7f9fbf"&gt;@param &lt;/font&gt;&lt;font color="#3f5fbf"&gt;l Sets the ID&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;   &lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;setId&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;long &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;l&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;id = l;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;font color="#000080"&gt;Mapping the Contact Object to the Database Contact table&lt;/font&gt;&lt;/b&gt;&lt;font color="#000080"&gt;&lt;br&gt; The file contact.hbm.xml is used to map Contact Object to the Contact table in the database. Here is the code for contact.hbm.xml:&lt;/font&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000000"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br&gt;         &amp;lt;!DOCTYPE hibernate-mapping PUBLIC &lt;br&gt;     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"&lt;br&gt;     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&amp;gt;&lt;br&gt;         &lt;br&gt;         &amp;lt;hibernate-mapping&amp;gt;&lt;br&gt;           &amp;lt;class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"&amp;gt;&lt;br&gt;            &amp;lt;id name="id" type="long" column="ID" &amp;gt;&lt;br&gt;            &amp;lt;generator class="assigned"/&amp;gt;&lt;br&gt;           &amp;lt;/id&amp;gt;&lt;br&gt;         &lt;br&gt;           &amp;lt;property name="firstName"&amp;gt;&lt;br&gt;              &amp;lt;column name="FIRSTNAME" /&amp;gt;&lt;br&gt;           &amp;lt;/property&amp;gt;&lt;br&gt;           &amp;lt;property name="lastName"&amp;gt;&lt;br&gt;             &amp;lt;column name="LASTNAME"/&amp;gt;&lt;br&gt;           &amp;lt;/property&amp;gt;&lt;br&gt;           &amp;lt;property name="email"&amp;gt;&lt;br&gt;             &amp;lt;column name="EMAIL"/&amp;gt;&lt;br&gt;           &amp;lt;/property&amp;gt;&lt;br&gt;          &amp;lt;/class&amp;gt;&lt;br&gt;         &amp;lt;/hibernate-mapping&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Setting Up MySQL Database&lt;/b&gt;&lt;br&gt; In the configuration file(hibernate.cfg.xml) we have specified to use &lt;b&gt;hibernatetutorial&lt;/b&gt; database running on localhost.  So, create the databse ("&lt;b&gt;hibernatetutorial") &lt;/b&gt;on the MySQL server running on localhost.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;Developing Code to Test Hibernate example&lt;/b&gt;&lt;br&gt; Now we are ready to write a program to insert the data into database. We should first understand about the Hibernate's Session. Hibernate Session is the main runtime interface between a Java application and Hibernate. First we are required to get the Hibernate Session.SessionFactory allows application to create the Hibernate Sesssion by reading the configuration from hibernate.cfg.xml file.  Then the save method on session object is used to save the contact information to the database:&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#000080"&gt;&lt;b&gt;session.save(contact)&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;Here is the code of FirstExample.java&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;package &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;roseindia.tutorial.hibernate;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.SessionFactory;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.Configuration;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;FirstExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;session =sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Create new instance of Contact and set values in it by reading them from form object&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;         &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Inserting Record"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;Contact contact = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Contact&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;contact.setId&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#990000"&gt;3&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;contact.setFirstName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Deepak"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;contact.setLastName&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Kumar"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;contact.setEmail&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"deepak_38@yahoo.com"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;session.save&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;contact&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Done"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;finally&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// Actual contact insertion will happen at this step&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session.flush&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;br&gt;&lt;/blockquote&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-5063076581586400991?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/5063076581586400991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=5063076581586400991' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5063076581586400991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5063076581586400991'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/writing-first-hibernate-code-in-this.html' title='Writing First Hibernate Code'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-2499032818766298372</id><published>2007-01-18T17:17:00.001-08:00</published><updated>2007-01-18T17:25:14.836-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Criteria Query Examples</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Criteria Query Examples" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Criteria Query Examples&lt;/a&gt;  &lt;/h1&gt; &lt;br&gt; &lt;font color="#000080"&gt;In the last lesson we learnt how to use Criteria Query to select all the records from Insurance table. In this lesson we will learn how to restrict the results returned from the database. Different method provided by Criteria interface can be used with the help of Restrictions to restrict the records fetched from database.&lt;br&gt; &lt;br&gt; &lt;/font&gt;&lt;b&gt;&lt;font color="#000080"&gt;Criteria Interface provides the following methods:&lt;br&gt; &lt;br&gt; &lt;/font&gt;&lt;/b&gt; &lt;div&gt;&lt;table bgcolor="#cccccc" border="1" bordercolor="#c0c0c0" cellpadding="0" cellspacing="0" width="639"&gt;   &lt;tbody&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;b&gt;&lt;font color="#000000"&gt;Method&lt;/font&gt;&lt;/b&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;b&gt;&lt;font color="#000000"&gt;Description&lt;/font&gt;&lt;/b&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="335"&gt;       &lt;font color="#000000"&gt;add&lt;/font&gt;     &lt;/td&gt;     &lt;td width="477"&gt;       &lt;font color="#000000"&gt;The Add method adds a Criterion to constrain the results to be retrieved.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;addOrder&lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;Add an Order to the result set.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;createAlias&lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;Join an association, assigning an alias to the joined entity&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr bgcolor="#cccccc"&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;createCriteria&lt;/font&gt;     &lt;/td&gt;     &lt;td bgcolor="#cccccc" width="909"&gt;       &lt;font color="#000000"&gt;This method is used to create a new Criteria, "rooted" at the associated entity.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;setFetchSize&lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;This method is used to set a fetch size for the underlying JDBC query.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;setFirstResult&lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;This method is used to set the first result to be retrieved.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;setMaxResults&lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;This method is used to set a limit upon the number of objects to be retrieved.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="1"&gt;       &lt;font color="#000000"&gt;uniqueResult&lt;br&gt;                 &lt;/font&gt;     &lt;/td&gt;     &lt;td width="909"&gt;       &lt;font color="#000000"&gt;This method is used to instruct the Hibernate to fetch and return the unique records from database.&lt;/font&gt;     &lt;/td&gt;   &lt;/tr&gt;   &lt;/tbody&gt; &lt;/table&gt;&lt;/div&gt; &lt;br&gt; &lt;font color="#000080"&gt;Class Restriction provides built-in criterion via static factory methods. Important methods of the Restriction class are:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;div&gt;&lt;table bgcolor="#cccccc" border="1" bordercolor="#c0c0c0" cellpadding="0" cellspacing="0" width="718"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width="1"&gt;&lt;b&gt;&lt;font color="#000000"&gt;Method&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;     &lt;td width="909"&gt;&lt;b&gt;&lt;font color="#000000"&gt;Description&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;allEq&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an       "equals" constraint to each property in the key set of a &lt;tt&gt;Map&lt;/tt&gt;&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;between&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a       "between" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;eq&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an       "equal" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;ge&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "greater       than or equal" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;gt&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "greater       than" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;idEq&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an       "equal" constraint to the identifier property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;ilike&lt;/b&gt;&lt;/code&gt;&lt;br&gt;                 &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is case-insensitive       "like", similar to Postgres &lt;tt&gt;ilike&lt;/tt&gt; operator&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;in&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an       "in" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;isNotNull&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an "is not       null" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;isNull&lt;/b&gt;&lt;/code&gt;          &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply an "is       null" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;le&lt;/b&gt;&lt;/code&gt;         &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "less       than or equal" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;like&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a       "like" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;lt&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "less       than" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;ltProperty&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "less       than" constraint to two properties&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;ne&lt;/b&gt;&lt;/code&gt;         &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "not       equal" constraint to the named property&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;neProperty&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This is used to apply a "not       equal" constraint to two properties&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;code&gt;&lt;b&gt;not&lt;/b&gt;&lt;/code&gt;  &lt;/font&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt;This returns the negation of an       expression&lt;/font&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="250"&gt;&lt;font color="#000000"&gt;Restriction.&lt;/font&gt;&lt;code&gt;&lt;b&gt;&lt;font color="#000000"&gt;or&lt;/font&gt;&lt;/b&gt;&lt;/code&gt;&lt;/td&gt;     &lt;td width="454"&gt;&lt;font color="#000000"&gt; This returns the disjuction of       two expressions&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br&gt;&lt;font color="#000080"&gt;Here is an example code that shows how to use     &lt;code&gt; Restrictions.like method and restrict the maximum rows returned by query by setting the Criteria.setMaxResults() value to 5.&lt;br&gt;&lt;br&gt;&lt;/code&gt;&lt;/font&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;/code&gt;&lt;blockquote&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.*;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.criterion.*;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.*;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.*;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;HibernateCriteriaQueryExample2 &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// use&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session = sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Criteria Query Example&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;Criteria crit = session.createCriteria&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance.&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;crit.add&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Restrictions.like&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"insuranceName"&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#2a00ff"&gt;"%a%"&lt;/font&gt;&lt;font color="#000000"&gt;))&lt;/font&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Like condition&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;crit.setMaxResults&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#990000"&gt;5&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Restricts the max rows to 5&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;List insurances = crit.list&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Iterator it = insurances.iterator&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;it.hasNext&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;Insurance insurance = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance&lt;/font&gt;&lt;font color="#000000"&gt;) &lt;/font&gt;&lt;font color="#000000"&gt;it.next&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ID: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insurance.getLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Name: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insurance.getInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;} &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;} &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;finally &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}    &lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;br&gt;&lt;/blockquote&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-2499032818766298372?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/2499032818766298372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=2499032818766298372' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2499032818766298372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/2499032818766298372'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/criteria-query-examples-in-last-lesson.html' title='Criteria Query Examples'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-6694010152529793830</id><published>2007-01-18T17:17:00.000-08:00</published><updated>2007-01-18T17:25:21.805-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Criteria Query Example</title><content type='html'>&lt;h1 align="left"&gt;   &lt;a title="Hibernate Criteria Query Example" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Criteria Query Example&lt;/a&gt; &lt;/h1&gt;&lt;br&gt;&lt;p align="left"&gt;&lt;font color="#000080"&gt;The Criteria interface allows to create and execute object-oriented queries. It is powerful alternative to the HQL but has own limitations. Criteria Query is used mostly in case of multi criteria search screens, where HQL is not very effective. &lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;The interface org.hibernate.Criteria is used to create the criterion for the search. The org.hibernate.Criteria interface represents a query against a persistent class. The Session is a factory for Criteria instances. Here is a simple example of Hibernate Criterial Query:&lt;/font&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p align="left"&gt;&lt;code&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt;  &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.*;&lt;/font&gt;&lt;br&gt;  &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.*;&lt;/font&gt;&lt;br&gt;  &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.*;&lt;/font&gt;&lt;br&gt;  &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;HibernateCriteriaQueryExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// use&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;          &lt;/font&gt;&lt;font color="#000000"&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session = sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Criteria Query Example&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;Criteria crit = session.createCriteria&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance.&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;List insurances = crit.list&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Iterator it = insurances.iterator&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;it.hasNext&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;Insurance insurance = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Insurance&lt;/font&gt;&lt;font color="#000000"&gt;) &lt;/font&gt;&lt;font color="#000000"&gt;it.next&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ID: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insurance.getLngInsuranceId&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Name: " &lt;/font&gt;&lt;font color="#000000"&gt;+ insurance.getInsuranceName&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;} &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;      &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;} &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;finally &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}    &lt;/font&gt;&lt;br&gt;  &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt;  &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p align="left"&gt;&lt;br&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;font color="#000080"&gt;The above Criteria Query example selects all the records from the table and displays on the console. In the above code the following code creates a new &lt;tt&gt;Criteria&lt;/tt&gt; instance, for the class &lt;b&gt;Insurance&lt;/b&gt;:&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#0000ff"&gt;Criteria crit = session.createCriteria(Insurance.class);&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;The code:&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#0000ff"&gt;List insurances = crit.list();&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font color="#000080"&gt;creates the sql query and execute against database to retrieve the data.&lt;/font&gt;&lt;/p&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-6694010152529793830?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/6694010152529793830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=6694010152529793830' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6694010152529793830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6694010152529793830'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-criteria-query-example.html' title='Hibernate Criteria Query Example'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-6253695545365451133</id><published>2007-01-18T17:15:00.000-08:00</published><updated>2007-01-18T17:25:29.248-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Story</title><content type='html'>&lt;a title="Hibernate Story" href="http://hibernate.javabeat.net/index.php"&gt;Hibernate Story&lt;/a&gt; &lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;br&gt;&lt;br&gt;&lt;/span&gt;Hibernate is an object-relational mapping (ORM) solution for the Java language. It is free, open source software that is distributed under the GNU Lesser General Public License. It provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database.&lt;br&gt;&lt;br&gt;&lt;p&gt;The purpose of Hibernate is to relieve the developer from a significant amount of common data persistence-related programming tasks. Hibernate adapts to the developer's development process, whether starting from scratch or from a legacy database.&lt;/p&gt; &lt;p&gt;Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. Hibernate generates the SQL calls and relieves the developer from manual result set handling and object conversion, keeping the application portable to all SQL databases.&lt;/p&gt; &lt;p&gt;Hibernate provides transparent persistence for "Plain Old Java Objects"; the only strict requirement for a persistent class is a no-argument constructor. (Proper behavior in some applications also requires special attention to the &lt;i&gt;equals()&lt;/i&gt; and &lt;i&gt;hashCode()&lt;/i&gt; methods.)&lt;/p&gt; &lt;p&gt;Hibernate is typically used both in standalone Java applications and in Java EE applications using servlets or EJB session beans.&lt;/p&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Who founded Hibernate?&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;div&gt;&lt;table border="0" cellpadding="3" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width="10%"&gt;&lt;img style="height: 125px; width: 100px;" title="Hibernate Founder - Gavin King" src="http://docs.google.com/File?id=dgz5f8nn_164cq38rz" align="left"&gt;&lt;/td&gt;&lt;td width="50%"&gt;Hibernate was developed by a team of Java software developers around the world led by Gavin King. JBoss group later hired the lead Hibernate developers and worked with them in supporting Hibernate. This move brought Hibernate development under Java EE Specifications.The current version of Hibernate is Version 3.1, which enriched the platform with new features like a new Interceptor/Callback architecture, user defined filters, and JDK 5.0 Annotations (Java's metadata feature). Hibernate 3 is also very close to the EJB 3.0 specification (although it was finished before the EJB 3.0 specification was released by the Java Community Process) and serves as the backbone for the EJB 3.0 implementation of JBoss.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;a title="Creator fo Hibernate - Gavin King" target="blank_" href="http://www.javafree.org/content/view.jf?idContent=3"&gt;Interview With Gavin King&lt;/a&gt;  &lt;br&gt;&lt;span style="font-weight: bold;"&gt;What is Object-Relational Mapping(ORM)?&lt;br&gt;&lt;br&gt;&lt;/span&gt;Object-Relational mapping is a programming technique that links databases to object-oriented language concepts, creating (in effect) a "virtual object database." There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to code their own object-relational mapping for their systems.&lt;br&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;Architecture&lt;br&gt;&lt;/span&gt;&lt;br&gt;A (very) high-level view of the Hibernate architecture:&lt;br&gt;&lt;br&gt;&lt;img style="height: 380px; width: 340px;" title="HighLevel Architecture - Hibernate" src="http://docs.google.com/File?id=dgz5f8nn_16663b8cv"&gt;&lt;br&gt;             This diagram shows Hibernate using the database and configuration data to             provide persistence services (and persistent objects) to the application.&lt;br&gt;&lt;br&gt;             We would like to show a more detailed view of the runtime architecture.             Unfortunately, Hibernate is flexible and supports several approaches. We will             show the two extremes. The "lite" architecture has the application             provide its own JDBC connections and manage its own transactions. This approach             uses a minimal subset of Hibernate's APIs:&lt;br&gt;&lt;br&gt;&lt;img style="height: 295px; width: 454px;" title="Hibernate Architecture" src="http://docs.google.com/File?id=dgz5f8nn_167wrf7bd"&gt;&lt;br&gt;             The "full cream" architecture abstracts the application away from the             underlying JDBC/JTA APIs and lets Hibernate take care of the details.&lt;br&gt;&lt;br&gt;&lt;img style="height: 394px; width: 482px;" title="Hibernate Architecture" src="http://docs.google.com/File?id=dgz5f8nn_168d6hmv3"&gt;&lt;br&gt;&lt;p&gt;             Heres some definitions of the objects in the diagrams:              &lt;/p&gt;&lt;div class="variablelist"&gt;&lt;dl&gt;&lt;dt&gt;&lt;span class="term"&gt;SessionFactory (&lt;tt class="literal"&gt;net.sf.hibernate.SessionFactory&lt;/tt&gt;)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             A threadsafe (immutable) cache of compiled mappings for a single database.                             A factory for &lt;tt class="literal"&gt;Session&lt;/tt&gt; and a client of                             &lt;tt class="literal"&gt;ConnectionProvider&lt;/tt&gt;. Might hold an optional (second-level)                             cache of data that is reusable between transactions, at a                             process- or cluster-level.                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;Session (&lt;tt class="literal"&gt;net.sf.hibernate.Session&lt;/tt&gt;)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             A single-threaded, short-lived object representing a conversation between                             the application and the persistent store. Wraps a JDBC connection. Factory                             for &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;. Holds a mandatory (first-level) cache                             of persistent objects, used when navigating the object graph or looking up                             objects by identifier.                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;Persistent Objects and Collections&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             Short-lived, single threaded objects containing persistent state and business                             function. These might be ordinary JavaBeans/POJOs, the only special thing about                             them is that they are currently associated with (exactly one)                             &lt;tt class="literal"&gt;Session&lt;/tt&gt;. As soon as the &lt;tt class="literal"&gt;Session&lt;/tt&gt; is closed,                             they will be detached and free to use in any application layer (e.g. directly                             as data transfer objects to and from presentation).                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;Transient Objects and Collections&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             Instances of persistent classes that are not currently associated with a                             &lt;tt class="literal"&gt;Session&lt;/tt&gt;. They may have been instantiated by                             the application and not (yet) persisted or they may have been instantiated by a                             closed &lt;tt class="literal"&gt;Session&lt;/tt&gt;.                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;Transaction (&lt;tt class="literal"&gt;net.sf.hibernate.Transaction&lt;/tt&gt;)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             (Optional) A single-threaded, short-lived object used by the application to                             specify atomic units of work. Abstracts application from underlying JDBC,                             JTA or CORBA transaction. A &lt;tt class="literal"&gt;Session&lt;/tt&gt; might span several                             &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;s in some cases.                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;ConnectionProvider (&lt;tt class="literal"&gt;net.sf.hibernate.connection.ConnectionProvider&lt;/tt&gt;)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             (Optional) A factory for (and pool of) JDBC connections. Abstracts application from                             underlying &lt;tt class="literal"&gt;Datasource&lt;/tt&gt; or &lt;tt class="literal"&gt;DriverManager&lt;/tt&gt;.                             Not exposed to application, but can be extended/implemented by the developer.                         &lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="term"&gt;TransactionFactory (&lt;tt class="literal"&gt;net.sf.hibernate.TransactionFactory&lt;/tt&gt;)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;&lt;p&gt;                             (Optional) A factory for &lt;tt class="literal"&gt;Transaction&lt;/tt&gt; instances. Not exposed to the                             application, but can be extended/implemented by the developer.                         &lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;p&gt;         &lt;/p&gt;&lt;p&gt;             Given a "lite" architecture, the application bypasses the             &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;/&lt;tt class="literal"&gt;TransactionFactory&lt;/tt&gt; and/or             &lt;tt class="literal"&gt;ConnectionProvider&lt;/tt&gt; APIs to talk to JTA or JDBC directly.         &lt;/p&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both;"&gt;&lt;a name="architecture-jmx"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;Books for reference&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;a title="Hibernate: A Developer's Notebook" target="blank_" href="http://www.oreilly.com/catalog/hibernate/index.html?CMP=ILL-4GV796923290"&gt;Hibernate: A Developer's Notebook&lt;/a&gt;  &lt;br&gt;&lt;br&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-6253695545365451133?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/6253695545365451133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=6253695545365451133' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6253695545365451133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/6253695545365451133'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-story-introduction-hibernate.html' title='Hibernate Story'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-5703718473295825037</id><published>2007-01-18T17:14:00.000-08:00</published><updated>2007-01-18T17:26:21.353-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>What is Hibernate?</title><content type='html'>&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;h1 align="left"&gt;&lt;font size="2"&gt;&lt;a title="Hibernate Tutorials and Articles - Part10" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Tutorials and Articles - Part1&lt;/a&gt;&lt;/font&gt;&lt;/h1&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;br&gt;&lt;font color="#000080"&gt;&lt;b&gt;What is Hibernate?&lt;br&gt;&lt;br&gt; &lt;/b&gt;Hibernate 3.0, the latest Open Source persistence technology at the heart of J2EE EJB 3.0 is available for download from &lt;a href="http://www.hibernate.org/Download/DownloadOverview" target="_blank"&gt;Hibernet.org&lt;/a&gt;.The Hibernate 3.0 core is 68,549 lines of Java code together with 27,948 lines of unit tests, all freely available under the LGPL, and has been in development for well over a year. Hibernate maps the Java classes to the database tables. It also provides the data query and retrieval facilities that significantly reduces the development time.  Hibernate is not the best solutions for data centric applications that only uses the stored-procedures to implement the business logic in database. It is most useful with object-oriented domain modes and business logic in the Java-based middle-tier. Hibernate allows transparent persistence that enables the applications to switch any database. Hibernate can be used in Java Swing applications, Java Servlet-based applications, or J2EE applications using EJB session beans.&lt;br&gt; &lt;br&gt; &lt;/font&gt; &lt;ul&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Hibernate 3.0 provides three full-featured query facilities: &lt;b&gt;Hibernate Query Language&lt;/b&gt;, the newly enhanced &lt;b&gt;Hibernate Criteria Query API&lt;/b&gt;, and enhanced support for queries expressed in the &lt;b&gt;native SQL &lt;/b&gt;dialect of the database.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Filters for working with temporal (historical), regional or permissioned data.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Enhanced Criteria query API: with full support for projection/aggregation and subselects.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Runtime performance monitoring: via JMX or local Java API, including a second-level cache browser.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Eclipse support, including a suite of Eclipse plug-ins for working with Hibernate 3.0, including mapping editor, interactive query prototyping, schema reverse engineering tool.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Hibernate is Free under LGPL: Hibernate can be used to develop/package and distribute the applications for free.&lt;br&gt;        &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Hibernate is Scalable: Hibernate is very performant and due to its dual-layer architecture can be used in the clustered environments.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Less Development Time: Hibernate reduces the development timings as it supports inheritance, polymorphism, composition and the Java Collection framework.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Automatic Key Generation: Hibernate supports the automatic generation of primary key for your.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt; JDK 1.5 Enhancements: The new JDK has been released as a preview earlier this year and we expect a slow migration to the new 1.5 platform throughout 2004. While Hibernate3 still runs perfectly with JDK 1.2, Hibernate3 will make use of some new JDK features. JSR 175 annotations, for example, are a perfect fit for Hibernate metadata and we will embrace them aggressively. We will also support Java generics, which basically boils down to allowing type safe collections.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;EJB3-style persistence operations: EJB3 defines the &lt;tt&gt;create()&lt;/tt&gt; and &lt;tt&gt;merge()&lt;/tt&gt; operations, which are slightly different to Hibernate's &lt;tt&gt;saveOrUpdate()&lt;/tt&gt; and &lt;tt&gt;saveOrUpdateCopy()&lt;/tt&gt; operations. Hibernate3 will support all four operations as methods of the &lt;tt&gt;Session&lt;/tt&gt; interface.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;Hibernate XML binding enables data to&lt;/font&gt; &lt;font color="#000080"&gt;be represented as XML and POJOs&lt;/font&gt; &lt;font color="#000080"&gt;interchangeably.&lt;br&gt;       &lt;/font&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;font color="#000080"&gt;The EJB3 draft specification support for POJO persistence and annotations.&lt;/font&gt;   &lt;/li&gt; &lt;/ul&gt; &lt;p&gt;   &lt;font color="#000080"&gt;Detailed features are available at &lt;a href="http://www.hibernate.org/About/RoadMap" target="_blank"&gt;http://www.hibernate.org/About/RoadMap&lt;/a&gt;.&lt;/font&gt; &lt;/p&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-5703718473295825037?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/5703718473295825037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=5703718473295825037' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5703718473295825037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/5703718473295825037'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-tutorials-and-articles-part1.html' title='What is Hibernate?'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-8509170539684694226</id><published>2007-01-18T17:13:00.000-08:00</published><updated>2007-01-18T17:26:30.556-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Select Clause</title><content type='html'>&lt;h1 align="left"&gt;&lt;font&gt;&lt;font size="2"&gt;&lt;a title="Hibernate Tutorials and Articles - Part10" href="http://hibernate.javabeat.net/tutorials/index.php"&gt;Hibernate Tutorials and Articles - Part11&lt;/a&gt;&lt;/font&gt;&lt;/font&gt;&lt;/h1&gt;&lt;h1 align="left"&gt;   &lt;font size="3"&gt;Hibernate Select Clause&lt;/font&gt;&lt;/h1&gt;&lt;br&gt;&lt;p&gt;&lt;font color="#000080"&gt;In this lesson we will write example code to select the data from Insurance table using Hibernate Select Clause. The select clause picks up objects and properties to return in the query result set. Here is the query:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#0000ff"&gt;Select insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate from Insurance insurance&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;which selects all the rows (&lt;b&gt;insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate&lt;/b&gt;) from Insurance table.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#000080"&gt;Hibernate generates the necessary sql query and selects all the records from Insurance table. Here is the code of our java file which shows how select HQL can be used:&lt;/font&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.Session;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.*;&lt;/font&gt;&lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;org.hibernate.cfg.*;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#7f0055"&gt;&lt;b&gt;import &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;java.util.*;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#3f5fbf"&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public class &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;SelectClauseExample &lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public static &lt;/b&gt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;void &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;String&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;args&lt;/font&gt;&lt;font color="#000000"&gt;) {&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;Session session = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#3f7f5f"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;SessionFactory sessionFactory = &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new &lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Configuration&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;.configure&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;&lt;br&gt;.buildSessionFactory&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;session =sessionFactory.openSession&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#3f7f5f"&gt;//Create Select Clause HQL&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;font color="#000000"&gt;String SQL_QUERY =&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Select insurance.lngInsuranceId,insurance.insuranceName," &lt;/font&gt;&lt;font color="#000000"&gt;+ &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;font color="#2a00ff"&gt;"insurance.investementAmount,insurance.investementDate from Insurance insurance"&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;font color="#000000"&gt;Query query = session.createQuery&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;SQL_QUERY&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Iterator it=query.iterate&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;it.hasNext&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;Object&lt;/font&gt;&lt;font color="#000000"&gt;[] &lt;/font&gt;&lt;font color="#000000"&gt;row = &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Object&lt;/font&gt;&lt;font color="#000000"&gt;[]) &lt;/font&gt;&lt;font color="#000000"&gt;it.next&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"ID: " &lt;/font&gt;&lt;font color="#000000"&gt;+ row&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Name: " &lt;/font&gt;&lt;font color="#000000"&gt;+ row&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;       &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#2a00ff"&gt;"Amount: " &lt;/font&gt;&lt;font color="#000000"&gt;+ row&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#990000"&gt;2&lt;/font&gt;&lt;font color="#000000"&gt;])&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;     &lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;        &lt;/font&gt;&lt;font color="#000000"&gt;session.close&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Exception e&lt;/font&gt;&lt;font color="#000000"&gt;){&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;System.out.println&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;e.getMessage&lt;/font&gt;&lt;font color="#000000"&gt;())&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;finally&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;    &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#ffffff"&gt;  &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br&gt; &lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br&gt;&lt;font color="#000080"&gt;To run the example select Run-&amp;gt; Run As -&amp;gt; Java Application from the menu bar. Following out is displayed in the Eclipse console:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;blockquote&gt;&lt;font color="#0000ff" size="2"&gt;Hibernate:         select insurance0_.ID as col_0_0_, insurance0_.insurance_name as         col_1_0_, insurance0_.invested_amount as col_2_0_,         insurance0_.investement_date as col_3_0_ from insurance insurance0_         &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 1&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 1000&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 2&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 100&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 3&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 500&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 4&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Car Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 2500&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 5&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Dental Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 500&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 6&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Life Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 900&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 7&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Travel Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 2000&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 8&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Travel Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 600&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 9&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Medical Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 700&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 10&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Medical Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 900&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 11&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Home Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 800&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 12&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Home Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 750&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 13&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Motorcycle Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 900&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;ID: 14&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Name: Motorcycle Insurance&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;        &lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;Amount: 780&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;                                         &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/513216235819956207-8509170539684694226?l=javabeat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javabeat.blogspot.com/feeds/8509170539684694226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=513216235819956207&amp;postID=8509170539684694226' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8509170539684694226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/513216235819956207/posts/default/8509170539684694226'/><link rel='alternate' type='text/html' href='http://javabeat.blogspot.com/2007/01/hibernate-tutorials-and-articles-part11.html' title='Hibernate Select Clause'/><author><name>Krishna</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/4896/1357/1600/krishna.1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-513216235819956207.post-8714310972834100280</id><published>2007-01-18T17:12:00.003-08:00</published><updated>2007-01-18T17:26:41.914-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>HQL from clause Exampl</title><content type='html'>&lt;h1 align="left"&gt;&lt;font size="2"&gt;&
