Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-19-2008, 12:59 PM
Member
 
Join Date: Jan 2008
Posts: 23
abhiN is on a distinguished road
image insertion into database
hi

can anybody send me sample progrm in java for how to insert and retrive image to and from mysql database..

thanks..
byee
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-05-2008, 05:12 PM
Member
 
Join Date: Jun 2008
Posts: 5
JForum4Hari is on a distinguished road
Use BLOB datatype and in Db you can use Image Datatype
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-06-2008, 10:15 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes Binary Large Object is the solution.

Code:
Statement stm; // You have to implement the statement to your connection ResultSet rs = stm.executeQuery(sql_query); if(rs.next()) { Blob blob = rs.getBlob(column); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-06-2008, 03:31 PM
pao pao is offline
Member
 
Join Date: Jun 2008
Posts: 41
pao is on a distinguished road
Hey I have done this before, so I dug this out of one of the classes I wrote.

Apologies if its a little long winded or whatever, I wrote it over 2 years ago, but it is working within a production environment.

You might need to play around with it a little bit but it should be enough:

Code:
//Writes filedata to database and returns the ID of the new Signature record private int writeImageFile(byte[] fileData, String fileName, String imageType, String mode, Integer signatureIDIn, HttpServletRequest request) throws Exception { //If the previous code found a file that can be uploaded then //save it into the database via a pstmt String sql = ""; UtilDBquery udbq = getUser(request).connectToDatabase(); Connection con = null; int signatureID = 0; PreparedStatement pstmt = null; try { udbq.setUsePreparedStatements(true); con = udbq.getPooledConnection(); con.setAutoCommit(false); if((!mode.equals("U")) || (mode.equals("U") && signatureIDIn == 0)) { sql = "SELECT SEQ_SIGNATURE_ID.nextval FROM DUAL"; pstmt = con.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { signatureID = rs.getInt(1); } if (fileName != null && imageType != null) { sql = "INSERT INTO T_SIGNATURE (SIGNATURE_ID, SIGNATURE) values (?,?)"; InputStream is2 = new ByteArrayInputStream(fileData); pstmt = con.prepareStatement(sql); pstmt.setInt(1, signatureID); pstmt.setBinaryStream(2, is2, (int)(fileData.length)); pstmt.executeUpdate(); pstmt.close(); con.commit(); con = null; } } if(mode.equals("U") && signatureIDIn != 0) { signatureID = signatureIDIn.intValue(); if (fileName != null && imageType != null) { sql = "UPDATE T_SIGNATURE SET SIGNATURE = ? WHERE SIGNATURE_ID = ?"; InputStream is2 = new ByteArrayInputStream(fileData); pstmt = con.prepareStatement(sql); pstmt.setBinaryStream(1, is2, (int)(fileData.length)); pstmt.setInt(2, signatureID); pstmt.executeUpdate(); pstmt.close(); con.commit(); con = null; } } } catch (Exception e) { con = null; throw new Exception(e.toString()); } return signatureID; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using PreparedStatement to insert image into database Java Tip Java Tips 0 02-10-2008 01:25 PM
Retriving image from database Java Tip Java Tips 0 02-09-2008 10:41 PM
passing image file to database abhiN Advanced Java 2 01-21-2008 08:30 AM
database insertion abhiN New To Java 0 01-17-2008 09:24 AM
How can I store an image to the database using hibernate cryss_tyna Database 0 08-15-2007 03:48 PM


All times are GMT +3. The time now is 01:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org