This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

how to upload pdf files to My sql with java

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need to save file to mysql database.

I tried through java, compilation no error, while running time iam getting errors please help me to solve the problem.

My inserting file code is:

My Sql Database is:

Compilation: javac SaveImageToDatabase.java
No error
Run : java SaveImageToDatabase
Error
In thread "main: java.lang.NoClassDefFoundError: SaveImageToDatabase
caused by: java.lang.ClassNotFoundException:SaveImageToDatabase
at java.net.URLClassLoader$1.run(URLCLassLoader.java:202)
at java.security.AccessController.doPrivileges(Native Method)
at java.net.URLClassLoader.findClass(URLCLassLoader.java:190)
at java.lang.ClassLoader.LoadClass(CLassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class:SaveImageToDatabase.
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Don't forget to keep your indentation. I've added both for you this time.

You have a class path issue. You've probably set the class path and forgot to include the current directory (.).

I also see two quick improvements:
1) You don't need to cast fis to InputStream. It's a FileInputStream and therefore already an InputStream.
2) You should close the connection after closing the statement. Once the connection is closed its statements are already invalid.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for guide i have solved the class path issue, i run the program its showing Uploaded successfully !. but if i went and saw in MySQL Workbench in image column its blank and its showing blob only the datatype.

I tried to retrieve the fie its showing java.Lang.NullPointerException.



Please help to solve my problem.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first point, don't always trust mysql workbench, I spent about 2 hours pulling my hair out because my update wasn't working. I closed the workbench, opened it again, and WOW my update HAD worked.

second point, which line had the null pointer exception
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
This is my full code:


After running this code its shows:


what are the data i have given its uploaded, i need to check that my file is uploaded sucessfully or not. and i need to see my file as output.

i need to see my image as output after uploading.

Iam new to developing field, if i did any mistakes please guide me.

Thanks in advance.


 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry to be a pain, but is this in a .jsp file, as your first post was in a class?

at least for this stage I would put it back in a class, you will get much better errors out whilst testing it (like you did in the first post.)

Then once it is in a class read this thread https://coderanch.com/t/565873/JSP/java/connect-database-display-query-vqlus
it is about seperating your jsp from your pretty stuff on screen
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and read this page, examples of your exact question:
http://www.mkyong.com/java/how-to-download-file-from-website-java-jsp/
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have find out how to upload and download a file through java. now i need to get the upload path from jsp page and then the path want to store in variable, by using variable the file wants to save in MySQL database. iam using Eclipse and i created one jsp page and one class file for java, by using request.getParameter()
Iam getting the values from jsp page. but iam getting error. My java program separately running successfully, but i need to connect with jsp.

Please Help Me, iam new to developing field, please Guide me.

My MySql Creation:


My JSP Code :



My Java Code :


I have coded perfectly or not i don't know please check my code and help me.


Thanks in advance
 
Rob Spoor
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please PostRealCode. That's not your real code, as HTML pages cannot call Java applications through form actions. You need a servlet instead, with the right URL mapping and all.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your Guide

I have change my code into servlet please help me iam getting error. iam using Eclipse for development.


My jsp page:



My servlet Code



My code is for i need to upload one file its wants to save in MySQL and and the copy of the file wants to download as C:\\ filename it is working in java perfect if i gave the path as manually,but i need to upload a file path by using jsp page

My web.xml code :


MySQL Database:



I have copy and pasted the class file in class folder and the jar files are commons-fileupload-1.2.2.jar,commons-io-1.3.2.jar, mysql-connector-java-3.0.17-ga-bin.jar,servlet-api.jar in lib folder.

while iam running the program iam getting error as


Please help me to solve the problem.

Thanks in advance.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is handy you are using eclipse, then you can debug the server, the line that must be going wrong is:



I always found it handy to get all of the parameters and loop through printing them out, as looking at the variables in the debug/variables tab is horrible.
but from experience it is usually the passing form, isn't doing what you expect.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't understand what your are coming to tell me. please tell clearly and give any guide to solve this.
 
Rob Spoor
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Files are not treated the same as other parameters. See https://coderanch.com/how-to/java/FileUpload for more information.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved my problem it will store the the file into mysql

jpage.jsp:



upload.jsp:



web.xml


then we need servlet-api jar file, mysql-connector-java-3.0.17-ga-bin jar file, commons-fileupload-1.2.2 jar file, commons-io-1.3.2 jar file.


My program is running sucessfully and the file is loading to the server with file name and current date and time.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved my problem it will store the the file into mysql

jpage.jsp:



upload.jsp:



web.xml


then we need servlet-api jar file, mysql-connector-java-3.0.17-ga-bin jar file, commons-fileupload-1.2.2 jar file, commons-io-1.3.2 jar file.


My program is running sucessfully and the file is loading to the server with file name and current date and time.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!