Results 1 to 9 of 9
- 01-28-2014, 11:18 AM #1
Member
- Join Date
- Jan 2014
- Posts
- 4
- Rep Power
- 0
store the image into database in netbeans
I have a image package consisting of images and they are displayed in a jlabel.I used the code below for that
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Image im=new ImageIcon(this.getClass()
.getResource("/images/" + imageNames[index])).getImage();
ImageIcon iconLogo = new ImageIcon(im);
jLabel5.setIcon(iconLogo);
}
Now I want to store the image displayed in the jlabel into the database(oracle).From the above code I dont know how to get the absolute path of the images.can anyone help to store the image as blob datatype in the database.Created a table hard(name varchar2(10),img blob).Thank you.
- 01-28-2014, 01:38 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 762
- Rep Power
- 11
Re: store the image into database in netbeans
Show us some code on what you have tried so far? We might be able to help.
Website: Learn Java by Examples
- 01-28-2014, 01:52 PM #3
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 10
Re: store the image into database in netbeans
There isn't necessarily an absolute path, the image is loaded from the classpath which might just be inside a jar or somewhere else "not directly on disc". You could create a ClassLoader that loads stuff from the internet if you'd want.
But that doesn't matter, you don't need an absolute path. Only an InputStream. And guess what: there is also a getResourceAsStream() method."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 01-28-2014, 02:05 PM #4
Member
- Join Date
- Jan 2014
- Posts
- 4
- Rep Power
- 0
Re: store the image into database in netbeans
Sir,I searched a lot.But I didnt get a solution for this.See in the above code image object 'im' is displayed on the jlabel.By converting this 'im' into bytes I can store it into the database.But I have no idea about how to convert 'im' to bytes?
- 01-28-2014, 02:08 PM #5
Member
- Join Date
- Jan 2014
- Posts
- 4
- Rep Power
- 0
Re: store the image into database in netbeans
@gimbal2:I am taking the images from a image folder within the project.But I dont know how to convert the
Image im=new ImageIcon(this.getClass().getResource("/images/" + imageNames[index])).getImage();
into some other form to store into the db.
- 01-28-2014, 02:15 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 10
Re: store the image into database in netbeans
I can only conclude that you did not in fact write the code that you posted but you just copy/pasted it from somewhere, or else my earlier comment would have made sense to you.
Java Code:this.getClass().getResource("/images/" + imageNames[index])
In this case you're using getResource(), but there is also a getResourceAsStream() which will provide you an InputStream with which you can load the image again so the bytes can be transmitted to the database. If you don't know how to do that, I suggest you get a good book on JDBC and to do some reading on how to use IO streams."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 01-28-2014, 02:22 PM #7
Member
- Join Date
- Jan 2014
- Posts
- 4
- Rep Power
- 0
Re: store the image into database in netbeans
ok sir
Last edited by chikku; 01-28-2014 at 02:49 PM.
- 01-28-2014, 02:27 PM #8
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 10
Re: store the image into database in netbeans
Quite advanced stuff for someone who is very new. I'd start with the basics first if I were you, cutting corners is only going to make you confused and angry.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 01-28-2014, 03:30 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
Re: store the image into database in netbeans
I don't think the OP can manage; at least to me that blob interface works 'the other way around'; you get an OutputStream that is supposed to write content to the blob and an InputStream retrieves a value from an existing blob; I once managed to get the stuff working by using PipedOutputStreams and PipedInputStreams that encapsulated the other streams ... quite tricky and there is no 'command' as the OP might have hoped for, that does the trick ...
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
How do i store an array from database?
By iNko in forum New To JavaReplies: 7Last Post: 12-10-2012, 01:21 PM -
No SVG image preview in netbeans visual midlet screen <SVG image is not specified>
By pomi_jan in forum CLDC and MIDPReplies: 4Last Post: 12-07-2012, 11:44 AM -
How to Store Gujarati Content in database.
By jatinkansagara in forum JDBCReplies: 9Last Post: 07-04-2011, 10:49 AM -
how to store images in access database
By sridarshan in forum JDBCReplies: 11Last Post: 06-26-2010, 02:26 AM -
How can I store an image to the database using hibernate
By cryss_tyna in forum JDBCReplies: 0Last Post: 08-15-2007, 01:48 PM
Bookmarks