File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to upload and retrive a image from mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to upload and retrive a image from mysql database" Watch "how to upload and retrive a image from mysql database" New topic
Author

how to upload and retrive a image from mysql database

sk mehrotra
Ranch Hand

Joined: Oct 27, 2005
Posts: 34
Hi!
I want to upload a image into the mysql database.
And display it using jsp
Plz help me.
Thanks in advance

Regards
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Image display in JSP retrieved from MYSQL
How to store/retrieve image to/from SQLServer


My blood is tested +ve for Java.
sk mehrotra
Ranch Hand

Joined: Oct 27, 2005
Posts: 34
Hi
I am using code that is below and i am getting the result :com.mysql.jdbc.Blob@b87d31 if i am using out.println(rs.getBlob("room_type_image")+"<br>");
and garbage values when i am using :: out.println(rs.getString("room_type_image")+"<br>");

Code :::

<%@ page import="java.sql.*" %>
<%

String connectionURL = "jdbc:mysql://localhost:3306/hotel_reservation";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<html>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root","sachin");
statement = connection.createStatement();

rs = statement.executeQuery("SELECT * FROM room_types_master");
while (rs.next()) {

out.println(rs.getBlob("room_type_image")+"<br>");
}

%>
</body>
</html>

Thanks ,,
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You've got 2 seperate issues here that require 2 seperate threads. So I am going to categorize this under a JDBC issue and I am moving it to the JDBC forum. Once you have this part figured out, then you can worry about displaying it in a JSP, at which time, ask in the JSP forum.


GenRocket - Experts at Building Test Data
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30067
    
149

out.println(rs.getBlob("room_type_image")+"<br>");

A Blob is a Java object. So if you just print it using out.println, it displays the address/default String value. Instead you can loop through it as a binary stream.

Then you have to figure out what you want to do with the image. If you just display it embedded in a web page, it will print a bunch of meaningless binary data.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to upload and retrive a image from mysql database
 
Similar Threads
Uploading an image to a server or to database?
How Upload Image to DataBase
retrieve image from database
Displaying image blob in jsp using image tag
File upload