Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to upload and retrive a image from mysql database

 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
Chetan Parekh
Ranch Hand
Posts: 3640
 
sk mehrotra
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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 ,,
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34401
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic