I'm designing a jsp webpage with postgresql database, I need to upload an excel with 8 fields and I have to store that data into the postgresql database. Can anyone give me links or sample program to do that as I'm new to js??
Asked
Active
Viewed 646 times
0
-
I don't think you'll be using JavaScript for this. Reading uploaded files and storing to the database are usually done on the [server-side](http://en.wikipedia.org/wiki/Server-side). You're using JSP, so that would mean using Java. Find a Java library to read Excel files, and then use whatever database-connection library you're using to put the data in the database. – Rory O'Kane Jul 12 '13 at 14:15
-
If possible, ask your user to export the data from Excel to [CSV](http://en.wikipedia.org/wiki/Comma-separated_values) format first. CSV is much easier for programs to read. – Rory O'Kane Jul 12 '13 at 14:16
-
Are you able to make use of Node.js? – Kuberchaun Jul 12 '13 at 14:29
-
I forgot to add up am using Eclipse IDE to design my pages and also Hibernate and struts to help me on some processes... – Praveen Inbasekaran Aug 07 '13 at 09:35
2 Answers
1
You could use Apache POI on the server side (in your JSP or servlet) to read Excel files.
Then store the data in PostgreSql using JDBC (alternatives are Hibernate or JPA).
As for reading Excel files, there are many examples on SO, for example here
-
I read your links about Apache POI and it seems to be promising. But what can I use to validate the details present in the excel. Will I be able to do the check only after the data gets populated in database or will the upload fail on wrong data input or missing column or overload? – Praveen Inbasekaran Aug 07 '13 at 09:48
-
That's up to you: You can check before the data gets inserted into the database, and the database will always check the constraints defined on a table/column. Of course, checking before will result in a better end user experience, because you define the error messages (and it's not only SQL error messages). But you can't really check before the file has been uploaded completely. – Beryllium Aug 07 '13 at 09:55
-
I need something that can validate if the user is actually uploading the right file. Any ideas? – Praveen Inbasekaran Aug 07 '13 at 10:55
-
That's actually a different question. Consider posting a separate question, and specify, if the validation should happen in the browser before the upload starts or while the upload is in progress or after the upload has been completed. If the files are not huge, I would just check the completely uploaded file using a servlet, before it gets inserted into the database. – Beryllium Aug 07 '13 at 11:17
-1
If you're able to make use of Node.js you can do it from there. Check out https://npmjs.org/package/excel in addition to Postgres connection from Node.js (to connect to postgre from Node.js).

Community
- 1
- 1

Kuberchaun
- 29,160
- 7
- 51
- 59
-
1I'm all for getting down voted, but at least leave a comment so maybe the answer can be updated to be of more value. – Kuberchaun Jul 18 '13 at 05:11