• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to insert image more than 4K in Database

 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I am using a Servlet to insert an image into oracle database, its working if the image is less then 4KB.

File file =new File(file1);
InputStream is = new FileInputStream(file);
ps =con.prepareStatement("insert into emp_photo VALUES(?,?,?)");
ps.setString(1,name);
ps.setString(2,type);
ps.setBinaryStream(3,is,Integer.MAX_VALUE);

Please Suggest.
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.

 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the setup of the database table. See what the maximum number of bytes allowed in that column is.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I am using Blob as DataType. Able to insert the large images through PL/SQL, but when trying through servlet, its not. Can you suggest me where i am going wrong.

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Which Oracle version is it ? if PL/SQL works , you can use CallableStatement to call stored procedure and see if that works.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Oracle 9i., DataType is Blob, Problem is that, not able to insert the images having size more then 4KB.

 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. And does Oracle allow you to specify the maximum number of bytes for a Blob column? If so, what is the default value for that maximum number?
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it dont allow us to set the size of the blob.
I tried using this but the result is same :

File f = new File(pathoffile);
byte[] bytes = new byte[(int)f.length()];
FileInputStream fs = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fs);
bis.read();

 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me any idea how to use
BLOB.createTemporary(con, true, BLOB.DURATION_SESSION) to insert an image into database using Java/Servlet.
Thanks.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



You are inserting data without specifying column name. I guess the data is inserted to a wrong column (which has 4K limit). add column names to your insert statement to avoid confusion. this is just a thought..
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but when I am inserting a file less then 4k, then its inserting into the blob column and when the file is more then 4k the blob column is empty.

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how do you check if its empty ? Use SQL Developer to view the BLOB.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the bolb is empty u'll find the (OraBlob) else it will be in upper. i am using Toad to view the rows.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I m not sure TOAD is right tool to view BLOB type. I couldnt view using TOAD , but could view BLOB data in SQLDeveloper.

if there are no errors during JDBC opertation , may be your data is stored , but you are not able to view it ?
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Toad is not an appropriate tool to view Blob, but not able to view the Blob throgh SqlDeveloper too. Its just an empty column. Please provide the code you are using to insert the image to database.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Your code seems fine to insert BLOB type.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Suggest me, what should i do?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cant guess why is it not working for data size above 4 KB. are you able to view if image is less than 4KB data alteast ?
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it can be viewed.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any alternative to do this?
Please suggest.
Thanks
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Like said earlier , if PL/SQL works, call the stored procedure using CallableStatement and store the BLOB data.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which driver are you using? The drivers that came with Oracle 9i didn't do so well with LOBs.

Also, are you aware that a LOB will only be stored inline up to 4k? After that it will be stored outside the row. Have a read of the Oracle docs on LOB data types for both issues.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:...Also, are you aware that a LOB will only be stored inline up to 4k? After that it will be stored outside the row. Have a read of the Oracle docs on LOB data types for both issues.
Maybe the data is stored (Balu Sadhasivam suggested that too), but your viewers can't show it, because, as Paul says, it is stored differently for +4K data.
Write a java application to fetch the data from the database, and validate if what you get is what you uploaded.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using classes12.jar and ojdbc14.jar.
Using thin to connect through the database. Is there any possibility that using thin can create this problem. But when i tried to use Oci it gave the following Error : java.sql.SQLException: Invalid Oracle URL specified.

Secondly I have created a JSp page to read the Blob, but its displaying the images (all images less then 4K).
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Using classes12.jar and ojdbc14.jar.

No, you are using one or the other not both. I'd recommend using the latest driver you can get rather than relying on the de-supported Oracle 9i drivers.


Secondly I have created a JSp page to read the Blob, but its displaying the images (all images less then 4K).

Not sure what you mean by this, are you saying you can successfully view images over 4K or that you tested it with images under 4K and they are OK?
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using one at a time.
while Using OCI driver i am getting the error : java.sql.SQLException: Invalid Oracle URL specified.

Secondly The JSp page is able to show all images that are in the Database and all are less then 4K. There is no Images being saved i.e. greater then 4K.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing , when i am using the same code to insert the image through my Local system (Java Class), I am able to insert images more then 4K, but when i am using the same through a JSP page and calling a servlet, its not inserting the images more then 4K.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there any error thrown? Are you catching up the errors ? What is the difference in logs (SOP , logs) when using 4k and >4K
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sk mehrotra wrote:One more thing , when i am using the same code to insert the image through my Local system (Java Class), I am able to insert images more then 4K, but when i am using the same through a JSP page and calling a servlet, its not inserting the images more then 4K.
Can you post the relevant code part of both your Java ans JSP/servlet attempts?
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java and servlet hav the same code that was posted earlier. Just a JSP page that allows to browse a file.
Java Code :


=============================================================================
Servlet:


===============================================================================

JSP:
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
It is surprising that the standalone code is able to insert but the servlet code isn't. I suggest you first insert the mandatory fields(non blob), then get the blob by querying the record you entered and update it. It *may* work. I did that for a clob.



Jhakda
 
Geneson Subramaniam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm trying to find a GUI tool that connects to Derby in embedded mode. Can Eclipse is capable of this? If so,
where can I start??

TQ
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jhakda Velu wrote:Hi
It is surprising that the standalone code is able to insert but the servlet code isn't. I suggest you first insert the mandatory fields(non blob), then get the blob by querying the record you entered and update it. It *may* work. I did that for a clob.



Jhakda



This shouldn't be needed. My guess as to why the behaviour is different would be that the JSP/Servelt application is using a differernt version of the JDBC driver. There is no difference between using JDBC code from a stand alone applciation and from a web application other than the configuation of the JDBC driver and data source.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geneson Subramaniam wrote:Hi All,

I'm trying to find a GUI tool that connects to Derby in embedded mode. Can Eclipse is capable of this? If so,
where can I start??

TQ


Please don't use someone elses topic to ask you question. Please start your own thread for this discussion.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have compiled the java code in the same environment used for Servlets.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sk mehrotra wrote:Have compiled the java code in the same environment used for Servlets.


OK. The driver jar files are not important at compile time, only runtime. What driver files are on your classpaths?
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sk mehrotra wrote:Have compiled the java code in the same environment used for Servlets.
But have you used the same jdbc jar at runtime?
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You type 10 seconds faster.
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the same JDBC jar at the runtime.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sk mehrotra wrote:Using the same JDBC jar at the runtime.


This seems unlikely. The same code running in a web application or as a stand alone application with the same JDBC driver will behave the same. If it isn't then its not the JDBC code that is the problem. What size are the files you upload?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic