• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to upload and retrive a image from mysql database

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I want to upload a image into the mysql database.
And display it using jsp
Plz help me.
Thanks in advance

Regards
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Image display in JSP retrieved from MYSQL
How to store/retrieve image to/from SQLServer
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ,,
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic