{"id":65914,"date":"2021-07-17T04:10:04","date_gmt":"2021-07-17T08:10:04","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/how-to-upload-data-from-an-excel-file-to-database-using-servlets-java-short-notes\/"},"modified":"2021-07-17T04:10:04","modified_gmt":"2021-07-17T08:10:04","slug":"how-to-upload-data-from-an-excel-file-to-database-using-servlets-java-short-notes","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=65914","title":{"rendered":"How to upload data from an excel file to database using servlets? #Java Short Notes"},"content":{"rendered":"<p>Use third party API bundles like jexcelApi. <br \/>http:\/\/jexcelapi.sourceforge.net\/.<\/p>\n<p>&#8212;<br \/>create an XML file to define the structure of your excel file like how many columns, column names, corresponding database table\/class column\/variable name, <\/p>\n<p>Create a Java class that can retrieve information from that xml file. You can use XPATH and DOM for the purpose. check http:\/\/www.ibm.com\/developerworks\/library\/x-javaxpathapi.html for ideas<\/p>\n<p>&#8212;<br \/>write an html form that use input type=&#8217;file&#8217;, the form action should point to the servlet that will collect data from the excel file and store it in the database. servlet will collect data from the input stream<\/p>\n<p>&#8212;&#8212;&#8212;&#8211;<br \/>in the servlet use the class that represents the xml file. to get information about the file that will help mapping the excel file data to the corresponding table column. You can also create a class representing the database table. From servlet extract data, create an object of table class type, and create a function that takes the object and inserts into the table.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>How servlet will process the excel file:<\/p>\n<p>jexcelAPI Workbook class represents the total workbook<br \/>use getsheet method of workbook class to get the sheet number 0,1,2&#8230;.<\/p>\n<p>use getCell method of worksheet to get a particular cell object in the excel file<br \/>use getContents on the cell object to get data in string type.<\/p>\n<p>from the XML file having excel file structure, you can get number of columns in the file. So you can write a look that will read data row,column wise from the excel file<\/p>\n<p>&#8212;-<br \/>code to process excel file [in servlet]<\/p>\n<p> Workbook workbook = Workbook.getWorkbook(new File(&#8220;myfile.xls&#8221;));<\/p>\n<p> Sheet sheet = workbook.getSheet(0);<\/p>\n<p> Cell a1 = sheet.getCell(0,0);<\/p>\n<p>Cell b2 = sheet.getCell(1,1);<\/p>\n<p>Cell c2 = sheet.getCell(2,1);<\/p>\n<p>String stringa1 = a1.getContents();<\/p>\n<p>String stringb2 = b2.getContents();<\/p>\n<p>String stringc2 = c2.getContents();<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>check the following webpage, it provides file upload and extract data from input stream in servlet applications<\/p>\n<p>http:\/\/jexcelapi.sourceforge.net\/resources\/faq\/<\/p>\n<p> From: http:\/\/sitestree.com\/?p=4801<br \/> Categories:Java Short Notes<br \/>Tags:<br \/> Post Data:2011-07-14 06:40:06<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use third party API bundles like jexcelApi. http:\/\/jexcelapi.sourceforge.net\/. &#8212;create an XML file to define the structure of your excel file like how many columns, column names, corresponding database table\/class column\/variable name, Create a Java class that can retrieve information from that xml file. You can use XPATH and DOM for the purpose. check http:\/\/www.ibm.com\/developerworks\/library\/x-javaxpathapi.html for &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=65914\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-65914","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":65910,"url":"http:\/\/bangla.sitestree.com\/?p=65910","url_meta":{"origin":65914,"position":0},"title":"MVC : Struts : Java : Industry Web Application #Java Short Notes","author":"Sayed","date":"July 17, 2021","format":false,"excerpt":"Industries use frameworks for application development quite often. For example: Java concepts like JSP, Servlet, Swing, Bean, JDBC can be used directly to create web-applications but when such applications become big, it becomes difficult to maintain and develop them further. Hence, frameworks like struts are used to develop large web-based\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78335,"url":"http:\/\/bangla.sitestree.com\/?p=78335","url_meta":{"origin":65914,"position":1},"title":"Java: ServletConfig vs ServletContext","author":"Sayed","date":"July 27, 2025","format":false,"excerpt":"Here\u2019s a clear and copyright-free comparison of ServletConfig vs ServletContext \u2014 perfect for learning or blogging. \ud83d\udd04 ServletConfig vs ServletContext in Java Both ServletConfig and ServletContext are part of the Java Servlet API and provide access to configuration data, but they serve different scopes and purposes. \ud83d\udccb Comparison Table FeatureServletConfigServletContextScopePer\u2026","rel":"","context":"In &quot;Anything JAVA&quot;","block_context":{"text":"Anything JAVA","link":"http:\/\/bangla.sitestree.com\/?cat=1975"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":74781,"url":"http:\/\/bangla.sitestree.com\/?p=74781","url_meta":{"origin":65914,"position":2},"title":"Playlist: Anything Java","author":"Sayed","date":"May 31, 2022","format":false,"excerpt":"Playlist: Anything Java: https:\/\/www.youtube.com\/playlist... #SaLearningSchoolShopForSoulSitesTree, #SaLearningSchool, #ShopForSoul, #SitesTree Starting Java training basic file operations in java basic java language concepts bengali javascript debugging data conversion in jsf applications debugging javascript code Docker and Vagrant Optional Java and\/or PHP Platform ejb application with bea weblogic eclipse experiment eclipse ant how to\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":66302,"url":"http:\/\/bangla.sitestree.com\/?p=66302","url_meta":{"origin":65914,"position":3},"title":"Essential Knowledge on Web Component Development #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"doGet() processes HEAD requests in the absence of a doHead() method Not the service() method but the methods that are called by the service method are better candidates for overriding HttpServlet supports GET, POST, DELETE, OPTIONS, and TRACE requests Retrieve a single value for a form parameter named \"username\": String\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":74548,"url":"http:\/\/bangla.sitestree.com\/?p=74548","url_meta":{"origin":65914,"position":4},"title":"Web Component and Web Application Development #servlet #java #JSP","author":"Sayed","date":"May 10, 2022","format":false,"excerpt":"Trial Videos: Introduce Servlet Concepts Trial: Intro to Topics in Servlet-based Web Application Development. \u09b8\u09be\u09b0\u09ad\u09cd\u09b2\u09c7\u099f \u098f\u09b0 \u099f\u09aa\u09bf\u0995 \u0997\u09c1\u09b2\u09cb - \u099c\u09beURL Trial: Servlet InterfaceURL Trial: Generic ServletURL Trial: HttpServlet: Java Based Web Application DevelopmentURL Trial Video: Life Cycle of Servlet (In Bengali)URL Trial Video: How to Create Servlets (In Bengali)URL Trial:\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":23216,"url":"http:\/\/bangla.sitestree.com\/?p=23216","url_meta":{"origin":65914,"position":5},"title":"Essential Knowledge on Web Component Development #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 27, 2021","format":false,"excerpt":"doGet() processes HEAD requests in the absence of a doHead() method Not the service() method but the methods that are called by the service method are better candidates for overriding HttpServlet supports GET, POST, DELETE, OPTIONS, and TRACE requests Retrieve a single value for a form parameter named \"username\": String\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65914"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65914\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65914"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}