{"id":5049,"date":"2016-09-01T12:56:04","date_gmt":"2016-09-01T10:56:04","guid":{"rendered":"http:\/\/techmoz.net\/?p=5049"},"modified":"2021-05-05T14:26:05","modified_gmt":"2021-05-05T12:26:05","slug":"java-data-access-objects-considerations-p-1","status":"publish","type":"post","link":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/","title":{"rendered":"Java &#8211; Data Access Objects &#8211; Considerations (p. 1)"},"content":{"rendered":"<p>This article is about some implications of how you implement the Data Access Objects pattern on your Java applications.<\/p>\n<p><em>This article uses the terms &#8220;connection&#8221; and &#8220;database connection&#8221; to refer to a link to a data source. No matter the way this link is stablished. This is not about JDBC or anything else. This article is not targeting a specific technology of database connectivity nor a method of data persistence.<\/em><\/p>\n<p>At some point, this article refers to Dependency Injection (DI), considering the <a href=\"http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/giwhl.html\" target=\"_blank\" rel=\"noopener\">CDI API<\/a>.<\/p>\n<h3>One connection per operation &#8211; implications<\/h3>\n<p>It\u2019s a common practice among starters to create DAO Implementations that open a new database connection on each operation method without the knowledge of the implications it brings to their applications. I&#8217;m talking about a DAO Implementation like this one:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQGiQHzTOWJDNQ\/article-inline_image-shrink_1000_1488\/0\/1520147301414?e=1619654400&amp;v=beta&amp;t=KTUCONldJ5yGvWA_ABGcaiozEQae2UQWzk554WlWHRk\" width=\"1342\" height=\"934\" \/><\/p>\n<p>What is wrong with this? First, You are adding the overhead of opening a new db connection to each of your DAO Methods. Invoking any of the methods will open a new database connection even on the same DAO instance. The second problem is: How are you going to group DAO Operations in a single transaction?<\/p>\n<p>The one-connection-per-operation approach wont help you on this. It will actually make it hard to implement this because your methods are not sharing the connection.<\/p>\n<p>But this is not bad at all. The good thing here is that you will never have a connection leak on this case. The second good thing is that you DAO is naturally <a href=\"http:\/\/en.wikipedia.org\/wiki\/Thread_safety\" target=\"_blank\" rel=\"noopener\">Thread-Safe.<\/a><\/p>\n<h3>Premature Connection issue (DAOs with DI)<\/h3>\n<p>Some people are not adepts of the one-connection-per-operation approach and prefer to open a database connection right on the DAO constructor, like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQEAyHd3wHMOGQ\/article-inline_image-shrink_1000_1488\/0\/1520234805364?e=1619654400&amp;v=beta&amp;t=9kVbo_rHGhoj6RJLFUc_rYvm5pmp143-Cn0wLQ7g5dg\" width=\"1344\" height=\"892\" \/><\/p>\n<p>Note that the constructor of StudentDaoImpl connects to the database. Is it bad? Its not bad until you start using DI (Dependency injection), then it becomes. Lets see how it works without DI:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4E12AQEnNy3QS-irKg\/article-inline_image-shrink_1000_1488\/0\/1520440454599?e=1619654400&amp;v=beta&amp;t=jjwDW1x2QhW-u-3yIpWeI9fwbOkRB9xGc097Bqlxaio\" width=\"1342\" height=\"176\" \/><\/p>\n<p>When you are not using DI, you instantiate the DAO Implementations classes by yourself while when you are using DI, the DI container does it for you. There few bad things that may happen if you keep connecting to the database on DAO Implementations constructor when introducing DI.<\/p>\n<p>The Data Access beans are intended to be injected into beans of the Business Layer.<\/p>\n<p>A single bean of the business layer, may inject into itself more than one DAO instance.<\/p>\n<p>From now on, lets assume there three DAO Implementations : <strong>StudentDAOImpl<\/strong>, <strong>CourseDAOImpl<\/strong> and <strong>StudentSubscriptionsDAOImpl<\/strong> correspondent to three DAO Interfaces: <strong>StudentDAO<\/strong>, <strong>CourseDAO<\/strong>, <strong>StudentSubscriptionsDAO<\/strong>.<\/p>\n<p><em>Each of the DAO implementations opens a new connection to the database on its constructor.<\/em><\/p>\n<p>In order to understand the Premature connection issue its necessary to emulate a scenario with a Business bean that injects multiple DAO instances into itself. Check out the following example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQHhwT3e1tFxXw\/article-inline_image-shrink_1000_1488\/0\/1520144849156?e=1619654400&amp;v=beta&amp;t=b4UDFcqFiimfpbVeJAWhqLf0AEbYlby9b6J8hVdci00\" width=\"1350\" height=\"976\" \/><\/p>\n<p>The Subscriptions bean injects into itself 3 DAO instances and it has two business methods: newSubscription and getStudentCourse. The first business method uses 2 of the 3 DAO instances (<strong>studentDao<\/strong> and <strong>courseDao<\/strong>) and the second business method uses a single DAO Instance (<strong>studentSubsDao<\/strong>).<\/p>\n<p>Imagine a scenario where we have a <a href=\"http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/bnafd.html\" target=\"_blank\" rel=\"noopener\">Servlet<\/a> that injects into itself an instance of the<strong> Subscriptions<\/strong> bean. The subscriptions bean is <a href=\"http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/gjbbk.html\" target=\"_blank\" rel=\"noopener\">RequestScoped<\/a>, meaning that, a new instance of the <strong>Subscriptions<\/strong> bean will be created for each new HTTP Request :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQEsO9WOn4MfQQ\/article-inline_image-shrink_1000_1488\/0\/1520173967523?e=1619654400&amp;v=beta&amp;t=Z_xfKGcjUBGMJta0-HI3YbMtubVnL3o73V5S1-ZHOLY\" width=\"1346\" height=\"592\" \/><\/p>\n<p>By the time the <strong>Subscriptions<\/strong> bean instance get injected into the <a href=\"http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/bnafd.html\" target=\"_blank\" rel=\"noopener\">Servlet<\/a>, three connections to the database will be opened. Why? Because the CDI container will instantiate the three DAO Implementations correspondent to <strong>StudentDAO<\/strong>, <strong>CourseDAO<\/strong> and <strong>StudentSubscriptionsDAO<\/strong> and inject them into the Subscriptions bean instance.<\/p>\n<p>Honestly, you don\u2019t need three database connections to handle a single client request, do you? Imagine if you simply want to get the course to which a student subscribed (<em>getStudentCourse<\/em>). Three connections is a waste of resources.<\/p>\n<p>The worst thing is that you will have connection leaks. Imagine if a user performs an HTTP Request simply to get the course to which a student subscribed: The <em>getStudentCource<\/em> method of the <strong>Subscriptions<\/strong> bean, only uses the <strong>studentSubsDao<\/strong>, that\u2019s why it only closes the connection of that single DAO. The other two connections (opened automatically for <strong>studentSubsDao<\/strong> and <strong>courseDao<\/strong>) will remain open. Soon or later you will end up facing the &#8220;<em>Too Many connections<\/em>&#8221; error.<\/p>\n<h3>The first attempt of fixing the Premature connection issue<\/h3>\n<p>The worst thing you can do is to close all connections on each business method:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQEnQbqsZb-bdw\/article-inline_image-shrink_1000_1488\/0\/1520145906989?e=1619654400&amp;v=beta&amp;t=x1e38Wy_YSJOl96-rfOAovvKnokm0jqvmfrNCV-Ia9E\" width=\"1344\" height=\"510\" \/><\/p>\n<p><em>Do not engage on this approach. It\u2019s a suicide mission.<\/em><\/p>\n<p>You will be creating another problem here. If you do this. It will be impossible to invoke the two business methods (getStudentCourse and newSubscription ) sequentially from the TestServlet, no matter the order of invocation. I will say it again: If you close the connection of all the DAO instances on each of the business methods, it will be impossible to invoke both business methods on the same Http Request:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4E12AQGdIWhh0eSIdA\/article-inline_image-shrink_1000_1488\/0\/1520440454740?e=1619654400&amp;v=beta&amp;t=YXfHiqXBePlQJydaqbVPujRqAlxbm9Sex9PQwxYoZnI\" width=\"1352\" height=\"686\" \/><\/p>\n<p>This code will fail on the line tagged as &#8220;second line&#8221;. Why? Because you will be trying to use DAO instances with closed connections. The line tagged as &#8220;first line&#8221; closes the connection of each DAO instance of the Subscriptions bean instance declared as subs.<\/p>\n<h3>The definitive solution<\/h3>\n<p>How do you get rid of this issue? Avoid connecting to the database on the DAO Implementations constructors. You might be like &#8220;should I create a public method to connect to the database?&#8221;. If that though passed through your mind. I will clarify your ideas: Your don\u2019t have to create a public method to connect to the database.<\/p>\n<p>All you have to do is check if a connection already exists before you perform any operations and open a new connection if no connection exists. That would be a smart change.<\/p>\n<h3>Check closed state<\/h3>\n<p>You should provide a way of checking if a DAO instance is closed (the internal datasource connection) in order to allow your business layer Beans to close it at any cost and avoid connections leaks.<\/p>\n<h3>Auto-close<\/h3>\n<p>Java 7 came out with a new feature that I personally believe was a smart update. The feature is designated <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/tryResourceClose.html\" target=\"_blank\" rel=\"noopener\">try-with-resource statement<\/a> . What is it?<\/p>\n<p>This code:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4D12AQGomZ5vs3jcCA\/article-inline_image-shrink_1000_1488\/0\/1520143518644?e=1619654400&amp;v=beta&amp;t=ctbWEJ4b8yj0zjGNSsNPQe0OWyzFL7NO7CwzeVi7uRU\" width=\"1346\" height=\"640\" \/><\/p>\n<p>Can now be written this way:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/media-exp1.licdn.com\/dms\/image\/C4E12AQFpT8ydyu9elg\/article-inline_image-shrink_1000_1488\/0\/1520440454859?e=1619654400&amp;v=beta&amp;t=9zCMLSU224TrfH2gO2_EC7KViFGTwb9VO_bqM0Jly5M\" width=\"1354\" height=\"270\" \/><\/p>\n<p>You don\u2019t have to invoke the close() method on the finally block manually. It will be invoked automatically for you.<\/p>\n<p>What are the requirements for your DAO Implementations to be auto-closed?<\/p>\n<p>They must implement the interface<a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/AutoCloseable.html\" target=\"_blank\" rel=\"noopener\"> java.lang.AutoCloseable<\/a>. Every Type that extends or implements <a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/AutoCloseable.html\" target=\"_blank\" rel=\"noopener\">java.lang.AutoCloseable<\/a> can be used on a try-with-resource statement. This can simplify the use of your DAOs. No more explicit close().<\/p>\n<p>What about the transaction problem we talked about on the one-connection-per-operation topic? Stay tune. I will be writing about it soon. I will also be writing a DI introduction article using CDI API.<\/p>\n<p><strong>It&#8217;s always a pleasure.<\/strong><\/p>\n<p>\ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is about some implications of how you implement the Data Access Objects pattern on your Java applications. This article uses the terms &#8220;connection&#8221; and &#8220;database connection&#8221; to refer to a link to a data source. No matter the way this link is stablished. This is not about JDBC or anything else. This article<\/p>\n","protected":false},"author":3,"featured_media":10701,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_dcms_eufi_img":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[963,1022,974,952,978,991],"tags":[],"class_list":["post-5049","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles-2","category-databases-development-tools","category-development-tools","category-highlights-2","category-java-2","category-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java - Data Access Objects - Considerations (p. 1) - Techmoz<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java - Data Access Objects - Considerations (p. 1) - Techmoz\" \/>\n<meta property=\"og:description\" content=\"This article is about some implications of how you implement the Data Access Objects pattern on your Java applications. This article uses the terms &#8220;connection&#8221; and &#8220;database connection&#8221; to refer to a link to a data source. No matter the way this link is stablished. This is not about JDBC or anything else. This article\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\" \/>\n<meta property=\"og:site_name\" content=\"Techmoz\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/web.facebook.com\/hostmoz\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-01T10:56:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-05T12:26:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"M\u00e1rio J\u00fanior\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hostmoz\" \/>\n<meta name=\"twitter:site\" content=\"@hostmoz\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"M\u00e1rio J\u00fanior\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"NewsArticle\"],\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\"},\"author\":{\"name\":\"M\u00e1rio J\u00fanior\",\"@id\":\"https:\/\/techmoz.net\/#\/schema\/person\/fd20b46d911cc409a8a48646aa2eeafe\"},\"headline\":\"Java &#8211; Data Access Objects &#8211; Considerations (p. 1)\",\"datePublished\":\"2016-09-01T10:56:04+00:00\",\"dateModified\":\"2021-05-05T12:26:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\"},\"wordCount\":1122,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techmoz.net\/#organization\"},\"image\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg\",\"articleSection\":[\"Articles\",\"Databases\",\"Development Tools\",\"Highlights\",\"Java\",\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#respond\"]}],\"copyrightYear\":\"2016\",\"copyrightHolder\":{\"@id\":\"https:\/\/techmoz.net\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\",\"url\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\",\"name\":\"Java - Data Access Objects - Considerations (p. 1) - Techmoz\",\"isPartOf\":{\"@id\":\"https:\/\/techmoz.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg\",\"datePublished\":\"2016-09-01T10:56:04+00:00\",\"dateModified\":\"2021-05-05T12:26:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage\",\"url\":\"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg\",\"contentUrl\":\"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg\",\"width\":1280,\"height\":720,\"caption\":\"When things go wrong, please don\u2019t make em worst - a Java Exceptions must read guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techmoz.net\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java &#8211; Data Access Objects &#8211; Considerations (p. 1)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techmoz.net\/#website\",\"url\":\"https:\/\/techmoz.net\/\",\"name\":\"Techmoz\",\"description\":\"O maior Portal de Tecnologia em Mo\u00e7ambique\",\"publisher\":{\"@id\":\"https:\/\/techmoz.net\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techmoz.net\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techmoz.net\/#organization\",\"name\":\"Hostmoz,Lda\",\"url\":\"https:\/\/techmoz.net\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techmoz.net\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techmoz.test\/wp-content\/uploads\/2023\/01\/techmoz-logo.png?fit=385%2C90&ssl=1\",\"contentUrl\":\"https:\/\/techmoz.test\/wp-content\/uploads\/2023\/01\/techmoz-logo.png?fit=385%2C90&ssl=1\",\"width\":385,\"height\":90,\"caption\":\"Hostmoz,Lda\"},\"image\":{\"@id\":\"https:\/\/techmoz.net\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/web.facebook.com\/hostmoz\",\"https:\/\/x.com\/hostmoz\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/techmoz.net\/#\/schema\/person\/fd20b46d911cc409a8a48646aa2eeafe\",\"name\":\"M\u00e1rio J\u00fanior\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techmoz.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1ba78c78f5737d6907dfb107a42f20c04a903414c196f57b04d376fc82cffd1e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1ba78c78f5737d6907dfb107a42f20c04a903414c196f57b04d376fc82cffd1e?s=96&d=mm&r=g\",\"caption\":\"M\u00e1rio J\u00fanior\"},\"description\":\"M\u00e1rio Francisco J\u00fanior is the Head Of Software Development at Vodacom Mozambique.\",\"url\":\"https:\/\/techmoz.net\/en\/author\/mfjunior\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java - Data Access Objects - Considerations (p. 1) - Techmoz","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/","og_locale":"en_US","og_type":"article","og_title":"Java - Data Access Objects - Considerations (p. 1) - Techmoz","og_description":"This article is about some implications of how you implement the Data Access Objects pattern on your Java applications. This article uses the terms &#8220;connection&#8221; and &#8220;database connection&#8221; to refer to a link to a data source. No matter the way this link is stablished. This is not about JDBC or anything else. This article","og_url":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/","og_site_name":"Techmoz","article_publisher":"https:\/\/web.facebook.com\/hostmoz","article_published_time":"2016-09-01T10:56:04+00:00","article_modified_time":"2021-05-05T12:26:05+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg","type":"image\/jpeg"}],"author":"M\u00e1rio J\u00fanior","twitter_card":"summary_large_image","twitter_creator":"@hostmoz","twitter_site":"@hostmoz","twitter_misc":{"Written by":"M\u00e1rio J\u00fanior","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","NewsArticle"],"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#article","isPartOf":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/"},"author":{"name":"M\u00e1rio J\u00fanior","@id":"https:\/\/techmoz.net\/#\/schema\/person\/fd20b46d911cc409a8a48646aa2eeafe"},"headline":"Java &#8211; Data Access Objects &#8211; Considerations (p. 1)","datePublished":"2016-09-01T10:56:04+00:00","dateModified":"2021-05-05T12:26:05+00:00","mainEntityOfPage":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/"},"wordCount":1122,"commentCount":0,"publisher":{"@id":"https:\/\/techmoz.net\/#organization"},"image":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage"},"thumbnailUrl":"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg","articleSection":["Articles","Databases","Development Tools","Highlights","Java","Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#respond"]}],"copyrightYear":"2016","copyrightHolder":{"@id":"https:\/\/techmoz.net\/#organization"}},{"@type":"WebPage","@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/","url":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/","name":"Java - Data Access Objects - Considerations (p. 1) - Techmoz","isPartOf":{"@id":"https:\/\/techmoz.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage"},"image":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage"},"thumbnailUrl":"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg","datePublished":"2016-09-01T10:56:04+00:00","dateModified":"2021-05-05T12:26:05+00:00","breadcrumb":{"@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#primaryimage","url":"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg","contentUrl":"https:\/\/techmoz.net\/wp-content\/uploads\/2016\/09\/Java-Data-Access-Objects-Considerations-p.-1.jpg","width":1280,"height":720,"caption":"When things go wrong, please don\u2019t make em worst - a Java Exceptions must read guide"},{"@type":"BreadcrumbList","@id":"https:\/\/techmoz.net\/en\/java-data-access-objects-considerations-p-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techmoz.net\/en\/"},{"@type":"ListItem","position":2,"name":"Java &#8211; Data Access Objects &#8211; Considerations (p. 1)"}]},{"@type":"WebSite","@id":"https:\/\/techmoz.net\/#website","url":"https:\/\/techmoz.net\/","name":"Techmoz","description":"O maior Portal de Tecnologia em Mo\u00e7ambique","publisher":{"@id":"https:\/\/techmoz.net\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techmoz.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techmoz.net\/#organization","name":"Hostmoz,Lda","url":"https:\/\/techmoz.net\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techmoz.net\/#\/schema\/logo\/image\/","url":"https:\/\/techmoz.test\/wp-content\/uploads\/2023\/01\/techmoz-logo.png?fit=385%2C90&ssl=1","contentUrl":"https:\/\/techmoz.test\/wp-content\/uploads\/2023\/01\/techmoz-logo.png?fit=385%2C90&ssl=1","width":385,"height":90,"caption":"Hostmoz,Lda"},"image":{"@id":"https:\/\/techmoz.net\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/web.facebook.com\/hostmoz","https:\/\/x.com\/hostmoz"]},{"@type":"Person","@id":"https:\/\/techmoz.net\/#\/schema\/person\/fd20b46d911cc409a8a48646aa2eeafe","name":"M\u00e1rio J\u00fanior","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techmoz.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1ba78c78f5737d6907dfb107a42f20c04a903414c196f57b04d376fc82cffd1e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ba78c78f5737d6907dfb107a42f20c04a903414c196f57b04d376fc82cffd1e?s=96&d=mm&r=g","caption":"M\u00e1rio J\u00fanior"},"description":"M\u00e1rio Francisco J\u00fanior is the Head Of Software Development at Vodacom Mozambique.","url":"https:\/\/techmoz.net\/en\/author\/mfjunior\/"}]}},"_format-video":{"_edit_lock":["1620220703:2"],"_oembed_2de6218c65aba5f9b6c20fb1a0ff7eed":["{{unknown}}"],"_oembed_e07c57531c7c049f11ebf48a1985a90e":["{{unknown}}"],"_oembed_588391aa40858c2cee69e403a55dffbb":["{{unknown}}"],"_oembed_29af1fada91f56e55cdedbd2c393134d":["{{unknown}}"],"_oembed_04500cb7c2c7525c8d31a2851bee5ccc":["{{unknown}}"],"_oembed_0b5f32d8a47a83b610e677615ef8f219":["{{unknown}}"],"_oembed_02379a4f4eef3d0cbc123078e20c1399":["{{unknown}}"],"_oembed_06a1b578507f5ac878facd0a09f9142b":["{{unknown}}"],"_oembed_7551d64e1e5228230b66a72ad04c4957":["{{unknown}}"],"_edit_last":["2"],"views":["1056"],"_yoast_wpseo_content_score":["30"],"naff_exclude":["false"],"_yoast_wpseo_primary_category":["952"],"_publicize_facebook_user":["https:\/\/www.facebook.com\/infomoz\/"],"_publicize_twitter_user":["@backstageel"],"_wpas_done_all":["1"],"_jetpack_related_posts_cache":["s:177:\"a:1:{s:32:\"8f6677c9d6b0f903e98ad32ec61f8deb\";a:2:{s:7:\"expires\";i:1560811769;s:7:\"payload\";a:3:{i:0;a:1:{s:2:\"id\";i:5040;}i:1;a:1:{s:2:\"id\";i:5046;}i:2;a:1:{s:2:\"id\";i:5043;}}}}\";"],"dsq_thread_id":["5328252544"],"_wpml_media_featured":["1"],"_wpml_media_duplicate":["1"],"_qt_imported":["original"],"_qt_links_fixed":["1"],"_last_editor_used_jetpack":["classic-editor"],"_encloseme":["1"],"_yoast_wpseo_estimated-reading-time-minutes":["7"],"_wpas_skip_3670605":["1"],"_wpas_skip_3670600":["1"],"_wpas_skip_13215035":["1"],"_oembed_42053c05ce1324d3888acbc6f9763193":["{{unknown}}"],"_oembed_350eb323cc60fbddfec6c4e8da25c534":["{{unknown}}"],"_oembed_ef18a2370b1520fadb32be9de9d2f156":["{{unknown}}"],"_thumbnail_id":["10701"],"_wp_page_template":["default"],"slide_template":["default"],"rs_page_bg_color":["#ffffff"],"_advads_ad_settings":["a:2:{s:11:\"disable_ads\";i:0;s:19:\"disable_the_content\";i:0;}"],"_yoast_wpseo_newssitemap-exclude":["off"],"_yoast_wpseo_newssitemap-genre":["a:0:{}"],"_yoast_wpseo_focuskeywords":["[]"],"_yoast_wpseo_keywordsynonyms":["[\"\"]"],"post_views_count":["364"],"mashsb_timestamp":["1674418134"],"mashsb_shares":["0"],"mashsb_jsonshares":["{\"total\":0,\"error\":{\"facebook_error\":\"\"},\"facebook_total\":0}"]},"_links":{"self":[{"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/posts\/5049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/comments?post=5049"}],"version-history":[{"count":5,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/posts\/5049\/revisions"}],"predecessor-version":[{"id":10647,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/posts\/5049\/revisions\/10647"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/media\/10701"}],"wp:attachment":[{"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/media?parent=5049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/categories?post=5049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techmoz.net\/en\/wp-json\/wp\/v2\/tags?post=5049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}