The CSV file is having multiple values to insert in perticular columns and rows in mysql database.
Here we have two files so we have to insert in two tables .
*** one is Header part file
*** another is Detail part file
Basically these two are to upload the questions and answers into the examination portal to upload question papers and answer paper in (Merit Tracking System project).
First we have to do the things are Uploaded file has to save in perticular folder and then they have to insert the values into the database table.This is our main task to do.
The required files to this program are
#1. index.jsp
#2. succ.jsp
#3. web.xml
#4. DBConnection.java
#5. SaveFile.java
#6. UploadFile2DB.java
and Some other libraries to add
#1. mysql-connector-java-3.1.11.jar
#2. servlet-api.jar
These are enough to our requirement add this files to your "lib" folder.
#1. index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <form name="fileuploadform" action="http://localhost:8080/UploadCSV/uploadfile">Upload CSV File<br> Select the header file to upload <input type="file" name="filehdr" /><br> Select the detail file to upload <input type="file" name="filedtl" /><br> Please select a folder to which the file has to be uploaded. <input type="file" name="filefolder" /><br> <input type="submit" name="submit" value="submit"> </form> </html>
#2. succ.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <b>The Files has been Uploaded into particular tables.</b> </body> </html>
package com; import java.sql.Connection; import java.sql.DriverManager; public class DBConnection { static Connection con; public static Connection getConnection(){ con=null; try{ System.out.println("----------I am in DBConnection----------"); Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://192.168.1.101:3306/test?user=test&password=test" ); System.out.println("---------end of DBConnection----------"); }catch(Exception e){ e.getMessage(); } return con; } }
#4. SaveFile.java
package com; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SaveFile extends HttpServlet { public void init(ServletConfig config)throws ServletException{ super.init(config); System.out.println("The SaveFile iniated.^^^^^^^^^^^^^^^^^^^################"); } public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{ try{ String pathheader=request.getParameter("filehdr"); System.out.println("The pathheader is : "+pathheader); String pathdetail=request.getParameter("filedtl"); System.out.println("The pathdetail is : "+pathdetail); String folderpath=request.getParameter("filefolder"); String filenamehdr=folderpath+pathheader.substring(pathheader.lastIndexOf('\\')); System.out.println("The file output path is : "+filenamehdr); String filenamedtl=folderpath+pathdetail.substring(pathdetail.lastIndexOf('\\')); System.out.println("The file output path is : "+filenamedtl); FileInputStream fis=new FileInputStream(pathheader); FileOutputStream fos=new FileOutputStream(filenamehdr); byte buf[]=new byte[11024]; fis.read(buf); fos.write(buf,0,buf.length); fis=new FileInputStream(pathdetail); fos=new FileOutputStream(filenamedtl); fis.read(buf); fos.write(buf,0,buf.length); if(fis!=null) fis.close(); if(fos!=null) fos.close(); System.out.println("------------------ Files are Saved in Folder-------------------"); request.getRequestDispatcher("/uploaddata").forward(request, response); }catch(FileNotFoundException e){ System.out.println(e.getMessage()); }catch(IOException e){ System.out.println(e.getMessage()); } } }
#5. UploadFile2DB.java
package com; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.StringTokenizer; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class UploadFile2DB extends HttpServlet { public void init(ServletConfig config) throws ServletException{ super.init(config); System.out.println("The UploadDataServlet2 iniated."); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { String filepathhdr=request.getParameter("filehdr"); String filepathdtl=request.getParameter("filedtl"); Connection con=DBConnection.getConnection(); System.out.println("connection=----------->"+con); PreparedStatement pstmthdr=null; PreparedStatement pstmtdtl=null; int rowshdr=0; BufferedReader brhdr=new BufferedReader(new FileReader(filepathhdr)); BufferedReader brdtl=new BufferedReader(new FileReader(filepathdtl)); System.out.println("reading the file"); String strLineHdr=""; String strLineDtl=""; String hdrstr=""; String dtlstr=""; StringTokenizer sthdr=null; StringTokenizer stdtl=null; // String firstColumnData[]=new String[10]; int lineNumberHdr=0; int lineNumberDtl=0; // int line=1; try{ pstmthdr=con.prepareStatement("insert into omts_onlinehdr values (?,?,?,?,?,?,?)"); System.out.println("statement executed"); while((strLineHdr=brhdr.readLine())!=null){ System.out.println("HEADERLINE"+strLineHdr); int i=1; if(!(lineNumberHdr==0)){ sthdr=new StringTokenizer(strLineHdr,","); while(sthdr.hasMoreTokens()){ hdrstr=sthdr.nextToken(); System.out.println("HeaderString: "+hdrstr); pstmthdr.setString(i++,hdrstr); System.out.println("below insertion"); } rowshdr=pstmthdr.executeUpdate(); System.out.println(rowshdr+" rows updated."); } lineNumberHdr++; } System.out.println("not in detail"); pstmtdtl=con.prepareStatement("insert into omts_onlinedtl values (?,?,?,?,?,?,?)"); System.out.println("ps executed"); while((strLineDtl=brdtl.readLine())!=null){ System.out.println("detailLINE"+strLineDtl); int i=1; if(!(lineNumberDtl==0)){ stdtl=new StringTokenizer(strLineDtl,","); while(stdtl.hasMoreTokens()){ dtlstr=stdtl.nextToken(); System.out.println("detail: "+dtlstr); pstmtdtl.setString(i++,dtlstr); System.out.println("below insertion"); } int rowsdtl=pstmtdtl.executeUpdate(); System.out.println(rowsdtl+" rows are updated."); } lineNumberDtl++; } //con.commit(); } catch(Exception e){ System.out.println(e.getMessage()); } finally { try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } response.sendRedirect("http://localhost:8080/UploadCSV/succ.jsp"); } }
Run your application using Tomcat webserver and it will displays index.jsp as welcome-file-list.
By selecting CSV file using browse button of header part and detail part and set the path of the folder where you want to save the uploaded files and click on submit button.
After completion of accessing two files into folders and databases it will displays as succ.jsp file as "successfully uploaded the two files".
The Console will displays as the all the information what is going inside.
Note: Use the MySql database or Oracle and give the driver name and url of the driver to connect Database in the DBConncetion class.
DOWNLOAD SOURCE
For Reference on Files:
Can yo please tell me web.xml file?
ReplyDeleteI have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Online Training Core Java 8 Training in Chennai java 8 online training JavaEE Training in Chennai Java EE Training in Chennai
Java Training Institutes Java Training Institutes Java EE Training in Chennai Java EE Training in Chennai Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai
ReplyDeleteHibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai
Helpful post.
ReplyDeleteThanks,
Informatica Training Chennai
The CSV format is primarily used to transfer tabular data from a database into a simpler text format. QIF or Quicken Interchange Format is another popular data format.excel reporting dashboard
ReplyDeletea pride for me to be able to discuss on a quality website because I just learned to make an article on
ReplyDeletecara menggugurkan kandungan
Great Article
ReplyDeleteJava Project Ideas for Final Year Students
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
When you change the configuration file, you will always need to restart the MySQL server to allow the changes to reload.DB Designer
ReplyDeletenow present in your city cara menggugurkan hamil
ReplyDelete1. manfaat kurma untuk persalinan
2. manfaat buah nanas
3. aktivitas penyebab keguguran
4. apakah usg berbahaya
5. penyebab telat haid
In any case, on the off chance that you don't have any reinforcement, visit now you should attempt to fix SQLite database physically. In case you're utilizing SQLite database program, you simply need to pursue these straightforward advances:
ReplyDeleteIt's imperative to likewise keep your framework perfect and very much ventilated, since exorbitant warmth can harm the electrical segments on the drive. manchester data recovery
ReplyDeleteThis is an awesome post.Really very informative and creative contents.
ReplyDeleteWordpress Development company in Chennai
It was really an interesting blog, Thank you for providing unknown facts.
ReplyDeleteTwin Cities Web Design
Awesome blog...Thanks for sharing. Waiting for next...
ReplyDeletePhotoshop Classes in Chennai
photoshop classes
Photoshop Classes for Photographers
Photoshop Training
photoshop training in Thiruvanmiyur
Drupal Training in Chennai
Manual Testing Training in Chennai
LoadRunner Training in Chennai
QTP Training in Chennai
C C++ Training in Chennai
Awesome blog...thanks for sharing valuable articles.....
ReplyDeleteStruts Training in Chennai
Struts Training institutes in Chennai
Struts Training Chennai
struts Training in Anna Nagar
struts Training in T Nagar
Wordpress Training in Chennai
SAS Training in Chennai
Spring Training in Chennai
Photoshop Classes in Chennai
DOT NET Training in Chennai
Nice article
ReplyDeleteairtel recharge list
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
artikel yang sangat bagus dan sangat mudah untuk di pahami.
ReplyDeleteCara Menggugurkan Kandungan
Dokter Spesilais Kandungan
klinik aborsi
ReplyDeleteklinik raden saleh
biaya aborsi
tindakan aborsi
cara menggugurkan kandungan
klinik aborsi jakarta
klinik aborsi
klinik raden saleh
Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
ReplyDeleteJava Training Institute in Chennai
Best JAVA Training Institute in Chennai
Java Training Institutes in Bangalore
Best Java Training Institutes in Bangalore
Java Training Institute in Coimbatore
Java Classes in Coimbatore
Java Course in Madurai
Java Training in Madurai
Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDelete360DigiTMG data analytics courses in hyderabad
You need to take part in a contest for one of the highest quality blogs on the web. I'm going to recommend this informative website!
ReplyDeleteHi, I do think this is an excellent site. I stumbledupon it ;) I may come back once again since I saved as a favorite it. Money and freedom is the best way to change, study may you be rich and continue to guide others.
ReplyDeleteI would like to comment on this quality content. I can see you have done a lot of homework and given this topic much thought.
ReplyDeleteBest Data Science training in Mumbai
Data Science training in Mumbai
ReplyDeleteThank you much more giving the Great Post. I appreciate a good job and Keep it up.
Primavera Course in Chennai
Best Primavera Training in Chennai
Tableau Training in Chennai
Spark Training in Chennai
Pega Training in Chennai
Appium Training in Chennai
Linux Training in Chennai
Oracle Training in Chennai
Social Media Marketing Courses in Chennai
Primavera Training in Tambaram
I am genuinely thankful to the holder of this web page who has shared this wonderful paragraph at at this place
ReplyDeleteCourses in Digital Marketing in Pune
Good post.....I appreciate yor way of writing that make the blog attractive and make reader to hold longer to your blog. Thank you for sharing
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
Thanks for sharing the information. It is very useful for my future. keep sharing
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
This is an awesome post.Really very informative and creative contents about AZURE. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteThis is an awesome post.Really very informative and creative contents about Java. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
This is an awesome post.Really very informative and creative contents about Java. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
nice post
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
nice post
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
I thank you for the information and articles you provided cara menggugurkan kandungan dan mempercepat haid
ReplyDeleteNice Great opportunity for career growth.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. data science course in coimbatore
ReplyDeleteAwesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
ReplyDeletedata science course in vizag
This comment has been removed by the author.
ReplyDelete
ReplyDeleteI see some amazingly important and kept up to length of your strength searching for in your on the site.
Data Science Course
I think about it is most required for making more on this get engaged.
ReplyDeleteData Science Training
http://scottish Government Topics
ReplyDeletehttp://digitalweekday.com/
http://digitalweekday.com/
http://digitalweekday.com/
http://digitalweekday.com/
http://yaando.com/
[no anchor text]
[no anchor text]
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
ReplyDeletedata analytics course in hyderabad
https://digitalweekday.com/
ReplyDeletehttps://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
ReplyDeletehttps://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
https://digitalweekday.com/
I am sure that this is going to help a lot of individuals. Keep up the good work. It is highly convincing and I enjoyed going through the entire blog.
ReplyDeleteCyber Security course training in Vizag
Nice and descent post i have come across found to be very impressive while going through this post. Thanks for sharing and keep posting such an informative content.
ReplyDeleteData Science Course in Raipur
Attend The Data Analyst Course From ExcelR. Practical Data Analyst Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analyst Course.
ReplyDeleteData Analyst Course
Tremendous blog quite easy to grasp the subject since the content is very simple to understand. Obviously, this helps the participants to engage themselves in to the subject without much difficulty. Hope you further educate the readers in the same manner and keep sharing the content as always you do.
ReplyDelete360DigiTMG Data Science Course
Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work.
ReplyDeletecyber security course training in Hyderabadi
Oracle Corporation is an American multinational computer technology corporation headquartered in Redwood Shores, California.
ReplyDeletetally training in chennai
hadoop training in chennai
sap training in chennai
oracle training in chennai
angular js training in chennai
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
ReplyDelete360digitmg
It’s really helpful blog. I really appreciate your information which you shared with us. If anyone who want to create his/her carrier in JAVA. Get a free demo call on 9311002620 or visit https://www.htsindia.com/java-training-courses
ReplyDeleteThanks for posting these kinds of post its very helpful and very good content a really appreciable post apart from that if anyone looking for best Advanced Excel training institute in delhi so contact here +91-9311002620 visit https://www.htsindia.com/Courses/business-analytics/adv-excel-training-course
ReplyDeletev
ReplyDeleteThis is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: video upload
ReplyDeletethank you for the information provided, we are waiting for the next info at cara menggugurkan kandungan
ReplyDeleteYour post is really good thanks for sharing these kind of post but if anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in bangalore, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite-https://experiencecertificates.com/experience-certificate-provider-in-bangalore.html
ReplyDeleteYour post is really good thanks for sharing these kind of post but if anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in bangalore, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite-https://experiencecertificates.com/experience-certificate-provider-in-bangalore.html
ReplyDeleteThanks for sharing this post its very informative post by the way If anyone look for Ms Office training institute in Delhi Contact Here-+91-9311002620 Or Visit our website https://www.htsindia.com/Courses/microsoft-courses/ms-office-course
ReplyDeleteImpressive blog to be honest definitely this post will inspire many more upcoming aspirants. Eventually, this makes the participants to experience and innovate themselves through knowledge wise by visiting this kind of a blog. Once again excellent job keep inspiring with your cool stuff.
ReplyDeleteData Science Training in Bhilai
Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such an amazing content for all the curious readers who are very keen of being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in future too.
ReplyDeleteData Science Course in Bhilai
You have worked nicely with your insights that makes our work easy. The information you have provided is really factual and significant for us. Keep sharing these types of article, Thank you.Advance Java Course in Delhi
ReplyDelete
ReplyDeleteThank you for sharing an amazing & wonderful blog. This content is very useful, informative and valuable in order to enhance knowledge. Keep sharing this type of content with us & keep updating us with new blogs. Apart from this, if anyone who wants to join the MIS Training institute in Delhi, can contact 9311002620 or visit our website-
https://htsindia.com/Courses/business-analytics/mis-training-instiute-in-delhi