Retrieving Images from Mysql with PHP

Hi I have been trying to work this out with no success so some help would be really appreciated.
I have two tables  in Mysql,
IMAGES  AND EXHIBITORS
IMAGES
`image_id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `filename` VARCHAR(255) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NOT NULL ,
  `mime_type` VARCHAR(255) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NOT NULL ,
  `file_size` INT(11) NOT NULL ,
  `file_data` LONGBLOB NOT NULL ,
  `user_id` VARCHAR(50) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NOT NULL ,
  `accom_id` INT(5) NOT NULL ,
  `exhibitors_exhib_id1` INT(5) NOT NULL ,
PRIMARY KEY (`image_id`, `exhibitors_exhib_id1`) ,
INDEX `user_id` (`user_id` ASC) ,
INDEX `accom_id` (`accom_id` ASC) ,
INDEX `fk_images_exhibitors2` (`exhibitors_exhib_id1` ASC) ,
CONSTRAINT `fk_images_exhibitors2`
FOREIGN KEY (`exhibitors_exhib_id1` )
REFERENCES `christmas_shopping`.`exhibitors` (`exhib_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 7
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_bin
EXHIBITORS
`exhib_id` INT(5) NOT NULL AUTO_INCREMENT ,
  `exhib_name` VARCHAR(50) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NOT NULL ,
  `exhib_years` SET('2010', '2009') NULL ,
  PRIMARY KEY (`exhib_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 3
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_bin
PACK_KEYS = DEFAULT
I think I am happy with the Mysql,  and I have read the various arguments about storing images in mysql but for my purpose I wanted to store the image in the database.
I have already created the upload and the images have uploaded correctly and I can see the data in the database, however I just have been able to retrieve the images back into a webpage.
I have a .php file which is merging these to tables correctly but the image is displayed as
o¿9®&#143;áŸÇ½G_ŒÁ%×Úoíø&#157;$M©7ûiè Óµ|Mn.˨â=Ž&#127;2Z ¥<º½Hs/¸úfŠÇðïˆ-üE`· &#157;¯üq÷C[ öTªÂ´ Jnéžl¢âÜdµ (¢µ$(¢Š�(¢Š�(¢Š�(¢Š�(¢Š�(¢Š�CÅ Š:šZ�(¢Š�(¢Š�) -!  ¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¢Š(�¯ ý¤Z_ x^óÃ&#144;K2ZJ»¦ò>ô»NJ ûç¥{6½©.‘£ÝÞ &#144;ÆZ¼*-Sûz"$pÌ]&#157;$þ%5ù¿ æ•0˜xa©;9êý O›=¼³ ªÍÔžÈøžþ t·[c*¦À  T?wøQ·/?ίøWÅ×z]Ü  r츌þæLôoâVþð¯jøÍð¶O Y½Îœ¨Œ›–k4OšWþê·mß1÷/ Abž<[Þ¢þþÕŠþ÷ûÛ&#127;&#157;}nCžÏ*š¡]Þ“ü?¯ëÏ‹ …X¨óÇIþgÔÔVf‹¬Ûë¶)snÙVê½Á:ý¶ &#141;H©ÁÝ=&#143;–iÅÙî QEh   ¢Š(�¢Š(�¢Š(�¢Š(�¤4´‚€ Š(  Š(  Š(  Š(   qKHh Ð ÑE �QE �QE �QE �V^½ª¦‡¥^²ï .í¾µ©^kñÿ�Z  Ã]NmÛY“
The code I have in the page is as follows. After many hours of trying to work it out I just cant see what I am missing and would really appreciate some help. I have highlighted where the echo is that relates to my image.
<?php require_once('../Connections/christmas.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  return $theValue;
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_christmas, $christmas);
$query_Recordset1 = "SELECT exhibitors.exhib_name, images.file_size, images.file_data FROM images, exhibitors WHERE images.exhib_id = exhibitors.exhib_id";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $christmas) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php $pagetitle="The Christmas Shopping Fayre"?>
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="; charset=" />
<link href="../public/CSSFiles/oneColElsCtrHdr.css" rel="stylesheet" type="text/css" />
<link href="../public/CSSFiles/whitebackground.css" rel="stylesheet" type="text/css"/>
<link href="../public/CSSFiles/shoppingonline.css" rel="stylesheet" type="text/css"/>
<link rel="icon" type="image/x-icon" href="http://www.gravatar.com/avatar/c4dac336c5be729fc542c12bfbb50099.png" />
<!--[if IE]>
<style type="text/css">
a { zoom: 1;}
</style>
<![endif]-->
<script type="text/javascript">
<!--
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
//-->
</script>
</head>
<body id="shoppingonline" class="oneColElsCtrHdr">
<p> </p>
<?php include("includes/header.php"); ?>
<br />
<br />
<div id="bannersp"> </div>
<h1>Welcome to <?php echo $pagetitle?></h1>
<p>
</p>
<form method="post" name="form1" id="form1">
<p> </p>
<table border="1" cellpadding="5" cellspacing="5">
  <tr>
    <td>exhib_name</td>
    <td>file_size</td>
    <td>file_data</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['exhib_name']; ?></td>
      <td><?php echo $row_Recordset1['file_size']; ?></td>
      <td><?php echo $row_Recordset1['file_data']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<?php include("includes/footer.php"); ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Hi Murray
You must despair with beginers like me,  attachments showed as having been
sent so lets try again.
I have been able to find a tutorial  that works well all the way through, I
can even see the images in the browser!!  but only shows images individually
on a page.
http://www.phpriot.com/articles/storing-images-in-mysql/7
However, what I want to do is to have a page that links my images table and
another table,  all of which I have set up and is working other then showing
the images.  All was very straight forward until sorting out the image.  If
I can work out what to take from the above tutorial that works into my page,
I am sure all will be fab.
Storing them in the mysql was my preferred method as there are not alot and
they can be low resolution and I thought it would be fairly straight
forward!!  however finding out that I am having to adapt code as dreamweaver
doesn't support the blob attribute is getting me out of my knowledge.
All the best
Gilly
Attachments inserted
show_image.php
<?php require_once('../Connections/getImage.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  return $theValue;
$colname_Recordset1 = "-1";
if (isset($_GET['image_id'])) {
  $colname_Recordset1 = $_GET['image_id'];
mysql_select_db($database_getImage, $getImage);
$query_Recordset1 = sprintf("SELECT image_id, mime_type, file_data FROM images WHERE image_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $getImage) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
header('Content-type: ' . $row_getImage['mime_type']);
echo $row_getImage['file_data'];
mysql_free_result($Recordset1);
?>
view.php
<?php require_once('../Connections/getImage.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  return $theValue;
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_getImage, $getImage);
$query_Recordset1 = "SELECT * FROM images";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $getImage) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="5">
  <tr>
    <td>image_id</td>
    <td>filename</td>
    <td>mime_type</td>
    <td>file_size</td>
    <td>file_data</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['image_id']; ?></td>
      <td><?php echo $row_Recordset1['filename']; ?></td>
      <td><?php echo $row_Recordset1['mime_type']; ?></td>
      <td><?php echo $row_Recordset1['file_size']; ?></td>
      <td><?php echo $row_Recordset1['file_data']; ?></td>
      <td><img src="show_image.php?image_id=<?php echo
$row_getdetails['image_id']; ?>" alt="Image from DB" />
</td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Similar Messages

  • Question on retrieve image from mysql

    i want to retrieve image from mysql database and display on GUI
    can anyone tell me how to do
    Thank you

    You can use the JDBC API for Java Database Connectivity. With this you can obtain data from the database using Java. There is an excellent tutorial here at Sun.com: http://www.google.com/search?q=jdbc+tutorial+site:sun.com You can get the MySQL JDBC driver at their own site: http://www.google.com/search?q=download+jdbc+driver+site:mysql.com Get the most recent version which suits your environment. There is also good documentation available over there.
    For displaying in the UI, the approach differs per UI. As you didn't mention which UI you are using, I can't help you further in detail.

  • Displaying image from Database with php

    Hello everybody,
    I'm working on a website that displays videos courses and tutorials as my final project
    and I'm working with "Flash builder 4" the database with mySQL and the application server with php
    Basically, the goal is to display a datagrid that shows the manager of the website in column all the information stored on the "Course" table
    the structure of the table is :
    Course (id,img,src,title,description)
    -id : primary key
    -img : path to a photo of course {for example picture of JAVA}
    -src : path to the playlist file {xml file}
    -title : String
    -description : String too
    I already succeeded to display all these contents on a DataGrid, but not with the image, I couldn't display an imageon its column using the path stored on the database, I used a DataRenderer to do that, and here is my code for Renderer and the DataGrid.mxml
    CourseGrid.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:courseservice="services.courseservice.*">
    <fx:Script>
    <![CDATA[
    import Renderers.CourseDeleteRenderer;
    import Renderers.CourseImageRenderer;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
    getAllCourseResult.token = courseService.getAllCourse();
    ]]>
    </fx:Script>
    <fx:Declarations>
    <s:CallResponder id="getAllCourseResult"/>
    <courseservice:CourseService id="courseService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:DataGrid x="10" y="10" id="dataGrid"
    creationComplete="dataGrid_creationCompleteHandler(event)"
    dataProvider="{getAllCourseResult.lastResult}"
    width="100%">
    <mx:columns>
    <mx:DataGridColumn headerText="" dataField="img" sortable="false" itemRenderer="Renderers.CourseImageRenderer"/>
    <mx:DataGridColumn headerText="id" dataField="id"/>
    <mx:DataGridColumn headerText="src" dataField="src"/>
    <mx:DataGridColumn headerText="title" dataField="title"/>
    <mx:DataGridColumn headerText="description" dataField="description"/>
    <mx:DataGridColumn headerText="Delete" itemRenderer="Renderers.CourseDeleteRenderer"/>
    <mx:DataGridColumn headerText="Update" itemRenderer="Renderers.CourseUpdateRenderer"/>
    </mx:columns>
    </mx:DataGrid>
    </s:Application>
    CourseImageRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      focusEnabled="true">
    <mx:Image source="{data}" width="60" height="60"/>
    </s:MXDataGridItemRenderer>
    Result :
    Problem :
    How can I access to the path of the image, I tried to write "data.img" instead of "data" as img is the name of the column in the database that stores the path but it wasn't successful.
    I know that it not complete statement "data" because "data" is a reference to what the DataGrid provides of information that gets from the (CreationComplete) event.
    Question :
    - Can you please help me with this so I can complete displaying images by accessing to what is on the column in tha DB so I can manipulate my datas that is stored there ?
    ==> I still have some questions about the buttons to update and delete datas fomr the DataGrid, but, until now I need to access successfully to the photo and display it
    Thank you,

    Anyone that can help me with this ?
    Please, try this with me, I'm asking Flex developpers this might be easy for you !
    It's just question of how to access the string stored in the variable "data", when I used XML I just type the path to the repeated element like this :
    XML file :
    XML File
    <parent>
    <child>
    <repeated_child></repeated_child>
    <repeated_child></repeated_child>
    <repeated_child></repeated_child>
    </child>
    </parent>
    I used a Model as a reference to the xml file
    and an arrayList as a container of the repeated child
    I just write in the code "data.parent.repeated_child" to access the text in the "repeated_child"
    and here is the code, that I implemented to generate videos from xml file to display a video play list
    Video Playlist code(extract from XML file "data.xml")
    <fx:Declarations>
    <fx:Model id="model" source="assets/data.xml"/>
    <s:ArrayList id="products" source="{model.video}"/>
    </fx:Declarations>
    <mx:List  dataProvider="{products}" labelField="title"
      change="list1_changeHandler(event,List(event.currentTarget).selectedItem)" x="103" y="77" height="350" width="198"/>
    That was my goal to do that with the database.
    Please help me
    If you have other solution I still need it.
    Thank you,

  • How to use html Tags from MySQL with PHP

    I like HTML tags like <b>bold</b> or <BR>
    and others placed in the MySQL database and used by PHP to show up
    in my pages but I don't succeed. I tryied HTML encode
    (htmlentities) from the bindings POP-up menu but nothing happened.
    What is the way this should be acomplished and where is HTML
    encode (and the others in the pop-up menu) being used for?
    Any help will be appreciated,
    Jos

    arnhemcs wrote:
    > I like HTML tags like
    bold or <BR> and others placed in the MySQL
    > database and used by PHP to show up in my pages but I
    don't succeed. I tryied
    > HTML encode (htmlentities) from the bindings POP-up menu
    but nothing happened.
    Just store the HTML as plain text in your database. Using
    htmlentities()
    turns < into &lt; and so on. Using it is what's
    preventing your HTML
    from displaying correctly.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • How to Retrieve Images from mysql on JSF page

    Hi,
    I want to retrieve all the images which are in my database(mysql) using Netbeans 6.9.1 on a JSF 2.0 page.
    How can i do so? I am using backing bean, i use backing bean methods in JSF.
    Pls help me...
    thanx...

    Hi
    Please first read this
    http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-mysql-windows-server-2008r2/
    You can remote control your MySQl and get data by connection string
    My Blog
    Please use Make as Answer if my post solved your problem and use
    Vote As Helpful if a post was useful.

  • Unable retrieve image from database

    Hi,
    I'm using Mysql-database with blob column. I'm trying to show one image on the page. Now I only get red cross, not image.
    I followed advices by jprazak:http://swforum.sun.com/jive/thread.jspa?threadID=47085&tstart=0
    I changed code for my purpose.
    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    * DisplayPicture.java
    public class DisplayPicture extends HttpServlet {
    private final String dbUrl="jdbc:mysql://localhost/pictures";
    private final String dbUser="read";
    private final String dbPassword="public";
    /** Creates a new instance of DisplayPicture */
    public DisplayPicture() {
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    public void destroy() {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String id = request.getParameter("imageid");
    String ct = request.getParameter("contenttype");
    if((ct==null)||(ct.equals(""))) {
    ct = "image/x-jpg";
    System.out.println(("Now displaying image with ID: "+id);
    try {
    ServletOutputStream out = response.getOutputStream();
    response.setContentType(ct);
    out.write(this.getImage(id));
    }catch(Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request, response);
    public String getServletInfo() {
    return "Displays a picture from the database identified by a parameter IMAGEID";;
    private byte[] getImage(String id) {
    Statement sta = null;
    Connection con = null;
    ResultSet rs = null;
    byte[] result = null;
    try {
    java.lang.Class.forName("org.gjt.mm.mysql.Driver");
    con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPassword);
    sta = con.createStatement();
    rs = sta.executeQuery("SELECT IMAGE FROM IMAGES WHERE IMAGEID="+id);
    if(rs.next()) {
    result = rs.getBytes("IMAGE");
    }else {
    System.out.println("Could find image with the ID specified or there is a problem with the database connection"););
    rs.close();
    sta.close();
    con.close();
    }catch(Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    return result;
    Then I add to file web.xml
    <servlet>
    <servlet-name>DisplayPicture</servlet-name>
    <servlet-class>DisplayPicture</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>DisplayPicture</servlet-name>
    <url-pattern>/servlets/DisplayPicture</url-pattern>
    </servlet-mapping>
    And image-component to the page, url-value:
    http://localhost:18080/application_name/servlets/DisplayPicture?imageid=1
    I get no errors. What is wrong with this code?
    Thanks

    If I select DEMO_BLOB and BLOBCOL from servers window, I can see in properties window:
    SQL Type BLOB
    Type Name BLOB
    If I select IMAGE column from mysql-table and I can see in properties window this:
    SQL Type LONGVARBINARY
    Type Name longblob
    Could this SQL Type difference be the reason why I can't get images from mysql to the page?

  • How to fetch data from Mysql with SSL.

    I am using jdk1.5 and mysql 5.0.
    How to fetch data from Mysql with SSL
    I am using url = jdbc:mysql://localhost/database?useSSL=true&requireSSL=true.
    It shows error. how to fetch

    I have created certificate in mysql and checked in mysql.
    mysql>\s
    SSL: Cipher in use is DHE-RSA-AES256-SHA
    but through ssl how to fetch data in java.

  • Retrieve image from my sql database using jsp

    I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
    please give me some sample codes.

    PreparedStatement pst = null;
      ResultSet rs=null;
    pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
    rs=pst.executeQuery();
    while(rs.next())
                                byte[] b=rs.getBytes("image");
                                FileOutputStream fos=new FileOutputStream("c://image.jpg");
                                fos.write(b);
                            } hi this the code to retrieve the image from DB and write to a file.

  • Problems with retrieving data from tables with 240 and more records

    Hi,
    I've been connecting to Oracle 11g Server (not sure exact version) using Oracle 10.1.0 Client and O10 Oracle 10g driver. Everything was ok.
    I installed Oracle 11.2.0 Client and I started to have problems with retrieving data from tables.
    First I used the same connection string, driver and so on (O10 Oracle 10g) then I tried ORA Oracle but with no luck. The result is like this:
    I'm able to connect to database. I'm able to retrieve data but from small tables (e.g. with 110 records it works perfectly using both O10 and ORA drivers). When I try to retrieve data from tables with like 240 and more records retrieval simply hangs (nothing happens at all - no error, no timeout). Application seems to hang forever.
    I'm using Powerbuilder to connect to Database (either PB10.5 using O10 driver or PB12 using ORA driver). I used DBTrace, so I see that query hangs on the first FETCH.
    So for the retrievals that hang I have something like:
    (3260008): BIND SELECT OUTPUT BUFFER (DataWindow):(DBI_SELBIND) (0.186 MS / 18978.709 MS)
    (3260008): ,len=160,type=DECIMAL,pbt=4,dbt=0,ct=0,prec=0,scale=0
    (3260008): ,len=160,type=DECIMAL,pbt=4,dbt=0,ct=0,prec=0,scale=1
    (3260008): ,len=160,type=DECIMAL,pbt=4,dbt=0,ct=0,prec=0,scale=0
    (3260008): EXECUTE:(DBI_DW_EXECUTE) (192.982 MS / 19171.691 MS)
    (3260008): FETCH NEXT:(DBI_FETCHNEXT)
    and this is the last line,
    while for retrievals that end, I have FETCH producing time, data in buffer and moving to the next Fetch until all data is retrieved
    On the side note, I have no problems with retrieving data either by SQL Developer or DbVisualizer.
    Problems started when I installed 11.2.0 Client. Even if I want to use 10.0.1 Client, the same problem occurs. So I guess something from 11.2.0 overrides 10.0.1 settings.
    I will appreciate any comments/hints/help.
    Thank you very much.

    pgoel wrote:
    I've been connecting to Oracle 11g Server (not sure exact version) using Oracle 10.1.0 Client and O10 Oracle 10g driver. Everything was ok.Earlier (before installing new stuff) did you ever try retrieving data from big tables (like 240 and more records), if yes, was it working?Yes, with Oracle 10g client (before installing 11g) I was able to retrieve any data, either it was 10k+ records or 100 records. Installing 11g client changed something that even using old 10g client (which I still have installed) fails to work. The same problem occur no matter I'm using 10g or 11g client now. Powerbuilder hangs on retrieving tables with more than like 240 records.
    Thanks.

  • Retrieve data from BW with an XML interface

    Hello all,
    Is it possible to retrieve data from BW with an XML interface ? And if so, how can we do this ?
    Kind regards,
    Marc

    Thanks Edan,
      Can you please example as how to access the ODS object in the BW using ABAP?  Please note that we would initiate the call from another XAPP system and update the data into the CRM system.
      Also please provide an example as how the BAPI can acces the cube data in BW.
      I assume that we will be writing both the BAPI and the ABAP code( as an RFC)  in the BW sysyem and call those from the XAPPS to get data out of BW Cube and ODS respectively.
      Thanks
    Arunava

  • Using Java to Retrieve Images from Oracle

    OracleResultSet.getCustomDatum method is deprecated. I was using this method to retrieve an ORDImage from an Oracle 9i database. What are developers using instead of getCustomDatum to retrieve images from the database. Thanks for all help in this matter.

    Hi use getBinaryStream(java.lang.String) or getBinaryStream(int) of java.sql.ResultSet for retrieving images from database
    Hope it will be useful
    regards
    chandru

  • How can I download images from website with Automator?

    Hi!
    I want to ask how can I download images from website with Automator like here http://www.youtube.com/watch?v=hQm7Xr9jY0w&t=85m15s (in 1:25:15).
    I want to download these images to my downloads folder. Some things have changed and I can't find exact options as then. When I am trying to make it it shows "The action "Download URLs" was not supplied with the required data."
    I am using 2012 late iMac with Mac OSX 9.2 (Mavericks).

    There are two apps that I know of - and I would also swear that they come from the same developer, although they've different names. Both have free trials and both cost $40 (but both do 'other' video conversion as well).
    One is WonderShare - I bought this one and it works very well for downloading YouTube videos as well as converting just about any file format you can think of.
    The other is iSkysoft Video Converter (just noticed that it's now $36).
    I tried them both and finally decided on WonderShare. Give them both a trial run and decide if you like either one enough to buy it. I don't know of any 'free' software that will allow you to download and convert YouTube videos, but perhaps someone else will come along and know of something...
    Good luck,
    Clinton

  • Problem when displaying images when working  with PHP, mysql and dreamweaver in a brower

    Hey Guys
    I am new to dynamic development but I already did some
    research and tutorials about how to get a dynamic web site working
    with PHP and Mysql in Dreamweaver. I set up a test page to view
    some content on it directly from the mysql database and it worked
    just fine in dreamweaver only when I pressed the
    live data view.
    When I tried to view the same page using the browser preview
    with firefox and internet explorer, plain text from the database
    was correctly displayed on the brower but the images were absent.
    In the mysql database I used the varchar as my picture data
    type field so that I will refer in dreamweaver in the data binding
    panel in the img.src to the picture column of my database.
    I anyone can tell me what am I doing wrong so that my
    pictures are not displayed in the browser when i click the browser
    preview facility in dreamweaver I would be very very and very
    pleased ! :)

    The odds are that it is the way that you have referenced the
    images rather
    than an issue with the database. If you have the images root
    relative like
    this "/images" then they will work in preview, and on the
    webserver, but
    will not view when looking at the file via localhost.
    If possible make the links page relative and then they should
    work fine.
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "mariosal026" <[email protected]> wrote in
    message
    news:ea3nq2$9ol$[email protected]..
    > Hey Guys
    >
    > I am new to dynamic development but I already did some
    research and
    > tutorials
    > about how to get a dynamic web site working with PHP and
    Mysql in
    > Dreamweaver.
    > I set up a test page to view some content on it directly
    from the mysql
    > database and it worked just fine in dreamweaver only
    when I pressed the
    >
    live
    > data view.
    >
    > When I tried to view the same page using the browser
    preview with firefox
    > and
    > internet explorer, plain text from the database was
    correctly displayed on
    > the
    > brower but the images were absent.
    >
    > In the mysql database I used the varchar as my picture
    data type field so
    > that
    > I will refer in dreamweaver in the data binding panel in
    the img.src to
    > the
    > picture column of my database.
    >
    > I anyone can tell me what am I doing wrong so that my
    pictures are not
    > displayed in the browser when i click the browser
    preview facility in
    > dreamweaver I would be very very and very pleased ! :)
    >

  • A Fluid Gallery from MySQL using PHP and various column widths

    I have decided to try the new Fluid Layout option in Dreamweaver. I pull information from a database (MySQL) and use php to present it.
    To show a gallery, I would pull the info and use the repeater code, and something like Tom Muck's horizontal repeater script to create a gallery. The images need to be shown with other text-based information (not just a caption). However, the HR script is a set amount of columns - and I want the number of columns to change depending on the width of the browser.
    So it's more than just a gallery - pulling images from a database with Title = "x" these would be a repeated stylised DIV with multiple texts fields and styles within.
    Let's take the example of a car dealership website it must show the car image, year, prices, description etc all in different style fonts so it can just be a caption to the image.
    So the options are:
    A fixed number of columns for each width: Monitor 5, Tablet 3, Mobile 1. Can this be achieved by having a "IF" statement in the actual code, if width = x use this version of the Horizontal Repeater?
    A fluid version that has 6 columns and as you slide the browser's width you can see the gallery's width has less columns until it reaches 1 for mobile.
    The fluid version would be better.
    Any links to a tutorial or example would be most appreciated.
    Many thanks
    HVR

    The only issue with using <divs> instead of a table to create your grid columns is that you will have to set a minimum height on the <divs> to keep them all at the same depth,much like a table cell construction looks and behaves. If you don't set a minimum height the grid will look all ragged PLUS the very big drawback is the <divs> won't clear if another <div> has more content in it which is going to happen if you include a 'description' of the car as this will never be the same length unless you are prepeared to edit the text.
    See fluid sample below: You can just populate the <divs> from your database and loop through them
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    body {
        font-family: verdana;
        font-size: 13px;
    #pageWrapper {
        width: 98%;
        max-width: 980px;
        margin: 0 auto;
        overflow: hidden;
    .imageDetails {
        width: 22.5%;
        float: left;
        margin: 0 0 15px 2%;
        background-color: #CCC;
        padding: 8px 0;
        min-height: 200px;
    dl {
        margin: 0 8px;
        padding: 0;
    dt {
    float: left;
    width: 50%;
    padding: 0 0 5px 0;
    dd {
    text-align: right;
    padding: 0 0 5px 0;
    h3 {
        font-size: 13px;
        margin: 0;
        padding: 8px 8px 5px 8px;
    p {
        margin: 0;
        padding: 0 8px;
    @media screen and (max-width: 760px) {
    .imageDetails {
    width: 30%;
    float: left;
    margin: 0 0 15px 2%;
    background-color: #9F3;
    @media screen and (max-width: 480px) {
    .imageDetails {
    width: 45%;
    float: left;
    margin: 0 0 15px 2%;
    background-color: #FC9;
    @media screen and (max-width: 320px) {
    .imageDetails {
    width: 100%;
    float: none;
    margin: 0 0 15px 0;
    background-color: #9CC;
    </style>
    </head>
    <body>
    <div id="pageWrapper">
    <div class="imageDetails">
    <img src="cars/car_1jpg" alt="">
    <dl>
    <dt>Price</dt>
    <dd>&pound;8500</dd>
    <dt>Year</dt>
    <dd>2009</dd>
    </dl>
    <h3>Description</h3>
    <p>This is a description about the car</p> 
    </div>
    <!-- end imageDetails -->
    <div class="imageDetails">
    <img src="cars/car_1jpg" alt="">
    <dl>
    <dt>Price</dt>
    <dd>&pound;8500</dd>
    <dt>Year</dt>
    <dd>2009</dd>
    </dl>
    <h3>Description</h3>
    <p>This is a description about the car</p>
    </div>
    <!-- end imageDetails -->
    <div class="imageDetails">
    <img src="cars/car_1jpg" alt="">
    <dl>
    <dt>Price</dt>
    <dd>&pound;8500</dd>
    <dt>Year</dt>
    <dd>2009</dd>
    </dl>
    <h3>Description</h3>
    <p>This is a description about the car. This is a description about the car. This is a description about the car.</p> 
    </div>
    <!-- end imageDetails -->
    <div class="imageDetails">
    <img src="cars/car_1jpg" alt="">
    <dl>
    <dt>Price</dt>
    <dd>&pound;8500</dd>
    <dt>Year</dt>
    <dd>2009</dd>
    </dl>
    <h3>Description</h3>
    <p>This is a description about the car</p>
    </div>
    <!-- end imageDetails -->
    <div class="imageDetails">
    <img src="cars/car_1jpg" alt="">
    <dl>
    <dt>Price</dt>
    <dd>&pound;8500</dd>
    <dt>Year</dt>
    <dd>2009</dd>
    </dl>
    <h3>Description</h3>
    <p>This is a description about the car</p> 
    </div>
    <!-- end imageDetails -->
    </div>
    </body>
    </html>

  • Retrieve images from DB and attach them to email through javamail

    Hi,
    I'm trying to use javamail to send emails containing text and images (HTML mail), if I use a physical file in my computer as the image source and use FileDataSource everything works just fine. The problem is that the images in my app are stored into a DB (I'm using MySQL, java struts & DAO), so in order to retrieve & display them I use a jsp that returns a byte array as shown in the example bellow
    <img  src='getImage.jsp?itemId=<bean:write name="item" property="itemId"/>&heigth=180&width=140&imageIndex=1'/>getImage.jsp reads the image from the DB for the specified item and returns an image of size "heigth*witdh", this works fine when invoked from any jsp or java action class, but I can't get it to work to insert an image into an email as attachment
    I've tried to use ByteArrayDataSource and the mail is sent correctly and can be read but the image won't show
    bds = new ByteArrayDataSource("/getImage.jsp?itemId="+itemId+"&heigth=180&width=140&imageIndex=1", "image/jpeg");
    imageMime.setDataHandler(new DataHandler(bds));
    imageMime.setHeader("Content-ID", "<\" + itemId + \">"); // backslashes aren't there in the real code, but if I remove them '+ itemId +' won't show
    mailParts.addBodyPart(imageMime);I've also tried with URLDataSource but can't get it to work either, can somebody plz point me in the right direction?
    thanks in advance
    Edited by: informacionCubica on Jun 8, 2009 3:46 PM

    Hello bshannon,
    Thanks for your answer, I tried your suggestion but when I use URLDataSource I get the error message http 500 (in my original post I said that using URLDataSource the mail was sent but without the image... my mistake, I was getting this same error). I traced the error and I found that it is caused by a null pointer exception... let me explain
    This is the code for the jsp that returns the image:
    4        <jsp:useBean id="coverImage" class="com.mqm.struts.getImageAction" scope="session" />
    5       <%
    6           // Desired size of the image to return
    7           int heigth = Integer.parseInt(request.getParameter("heigth"));
    8          int width = Integer.parseInt(request.getParameter("width"));
    9          
    10          // Each item can have up to 6 images (ordered by id), this indicates wich of one we have to return
    11            int imageIndex = Integer.parseInt(request.getParameter("imageIndex"));
    12        byte[] imgData = coverImage.getItemImageAction(request.getParameter("itemId"), request,heigth, width, imageIndex );
    13        response.setContentType("image/jpeg");
    14        OutputStream o = response.getOutputStream();
    15         o.write(imgData);
    16         o.flush();
    17         out.clearBuffer();
    18         o.close();
            %> getImageAction is my DAO class that actually reads the image data from the DB, when I use this 'getImage.jsp' inside any other jsp in the app it works, but when used as described in the first post the request parameter in the line 12 doesn't have the session info, apparently creates a new session or something and since I use information in the session to create the DAO factory I can't connect to the DB and get this error..
    pls tell me if I explained my self or I'm just talking non sense
    regards

Maybe you are looking for