Saving image in ms sql database.

Hi all, i have a problem saving image in the database.i used
request.getParameter("imagename"), to get the content of the textfield in the html file but the problem is that it omits the filepath and gives me just the image name and that gives me an error.. Pls help me

Your actual problem is less or more web browser related. The right way is that the browser should only send the filename, but a certain widely used browser developed by a team in Redmond would send the full file path as it is at the client side, which is completely wrong.
The bigger picture what you're trying to achieve, uploading a file from the client to the server, shouldn't be done that way, simply because this isn't going to work at all if the client runs at a completely different machine on the other side of the network than where the server runs. You need to send the actual file contents to the server. Just set the form's enctype to multipart/form-data and parse the body of the request to get the actual file contents. To ease the work I recommend you to use Apache Commons FileUpload API for parsing the multipart/form-data request. Go to their homepage and check out the 'User guide' and 'Frequently Asked Questions' how to use it and for some tricks.

Similar Messages

  • Display images from a SQL database

    I want to display images from a SQL database. The images are in a table under a specific column and are stored as a link to the image. How would I display the images from the column in LabVIEW?
    I'm using LabVIEW 2013 version 13 and SQL Server 2012
    Paul Power
    I have not lost my mind, it's backed up on a disk somewhere

    Hi PauldePaor,
    I hope you are well.
    Once you have pulled the data from the database into LabVIEW in a string form (or path), you can simply use the Read BMP File (Or jpg, png depending on the file type) VI.
    More information can be found here:
    http://digital.ni.com/public.nsf/allkb/02971A30F5D8FC6986256A0A004F11A0
    Kind Regards,
    Aidan H
    Applications Engineer
    National Instruments UK & Ireland

  • Data Type for saving Base64 image string into SQL database

    Hi Team! I have image base64 string to be save into sql database. I use Varchar(MAX) data type. The problem is there are certain image string that cannot be enter (paste) into the table (due to the size) then i need to resize the image then i can paste
    the string into the table. How to make all image string size be able to be save in the table? Or there is limit on the image size to be save into the table? I'm using mssql 2008. Thanks a lot.

    There is a limit of 2GB. Which means that the actual image size must be less, since you encode the image in Base64 for some reason.
    Now, "pasting" strings is not the normal way to store data in an SQL Server database, so the question is a little funny. Normally data is stored in a database through a program of some sort. One way is to use OPENROWSET(BULK) as HuaMin suggested.
    Here is a link to a simple example of how to do it from .NET:
    http://www.sommarskog.se/blobload.txt
    Erland Sommarskog, SQL Server MVP, [email protected]

  • 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.

  • Adding Images to a SQL Database

    I'm using WAMP (courtesy of a community professional's reference), to build a database for a dynamic website (made in DW CS5).  The database is meant to hold our inventory listings (name, description, price, etc).  I want it to hold the product images too, but so far search engines keep referring me to Microsoft Access, not cool, or telling me to store the image URL in Excel, also not strictly helpful.
    I'm using PHPMyAdmin 3.2.0.1 to create a MySQL database, what's the best way to go about adding an image field?  I don't think I should set the data-type to int or anything weird so I left it at text for now, but there's no image option, and no real reference material that I can make sense of to use an image.  Any suggestions?

    >when they click a fan image or name it will display on the right.
    What will display on the right? Will you be displaying thumbnails in the list and then want details to display when the select the item? This is just a simple master-detail scenario. Clicking the link will embed the product id in the querystring and then open the detail page. If you want the item details to appear on the same page as the master list, then you'll need to use AJAX techniques.
    >Does that involve more stuff in
    >the database, or in the code itself?
    Hard to say what 'more stuff' is when we don't know your database schema. In the context of your original question, no additional details other than the image path need to be included in the database in order to display images. The rest is done with code.
    Please include more details.
    Also, in the future please post these type of questions to the App Dev forum. That's what it's for.

  • Problem in saving the image into SQL database..

    Hello,
    In my application I have to save image file (say jpg) into the database and retrieve back and display it on the applet. I am through with grabbing the pixels of the image & sending the pixel array to the servlet but I am struck in how to store the image into the database and retrieve the same.
    Can anybody please help me in this regard... its really urgent...
    Thanks in advance
    Swarna

    Hello.
    I've been researching this problem (saving images in a MySQL database) in order to accomplish a task I was assigned to. Finally I was able to do it. I'd be glad if it will be of any use.
    First of all: the original question was related to an applet. So, the post from rkippen should be read. It says almost everything, leaving the code job for us. Since I managed to write some code, I'll put it here, but I'm not dealing with the byte transferring issue.
    To obtain a byte array from a file I'd open the file with FileInputStream and use a loop to read bytes from it and save them into a ByteArrayOutputStream object. The ByteArrayOutputStream class has a method named �toByteArray()� which returns an array of bytes (byte [] b = baos.toByteArray()) that can be transferred in a socket connection, as said by rkippen.
    My problem was to save an image captured by a web camera. I had an Image object, which I converted into a byte array and saved into the database. Eventually I had to read the image and show it to the user.
    The table in the MySQL database could be:
    CREATE TABLE  test (
      id int(11) NOT NULL auto_increment,
      img blob NOT NULL,
      PRIMARY KEY  (id)
    )I had problems trying to use the �setBlob� and �getBlob� methods in the Statement object, so I used the �setBytes� and �getBytes� methods . In the end, I liked these methods most because they where more suitable to my application.
    The database operations are:
        public int insertImage(Image image) throws SQLException {
            int id = -1;
            String sql = "insert into test (img) values (?)\n";
            PreparedStatement ps = this.getStatement(sql);  // this method is trivial
            byte [] bytes = this.getBytes(imagem); // * see below
            ps.setBytes(1, bytes);
            ps.executeUpdate();
            id = ps.getGeneratedKeys().getInt(0); //Actually I couldn't make this line work yet.
            return id;
        public Image selectImage(int id) throws SQLException {
            Image img = null;
            String sql = "select img from test where id = ?\n";
            PreparedStatement ps = getStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                byte [] bytes = rs.getBytes(1);
                img = this.getImage(bytes); // * see below
            return img;
        }* If the bytes are read directly from a file, I think it is not necessary to convert it into an Image. Just send the bytes to the database method would work. On the other hand, if the image read form the DB will be written directly into files, the bytes obtained from rs.getBytes(1) would be enough.
    The image operations are:
        public byte [] getBytes(Image image) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ImageIO.write(this.getBufferedImage(image), "JPEG", baos);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return baos.toByteArray();
        public Image getImage(byte [] bytes)  {
            Image image = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
                image = ImageIO.read(bais);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return image;
        public BufferedImage getBufferedImage(Image image) {
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();
            g2d.drawImage(image, 0, 0, null);
            return bi;
        }That's it. I hope it is useful.

  • Load image from SQL database with ASP?

    Hello,
    Does anyone know a tutorial where you can load an image from
    a SQL database ?
    I would like to show this image in Flash, but i don't know
    how to load in from a SQL database using ASP.
    Regards,
    Micheal

    Flash cannot load images from an SQL database.
    Flash can load JPEG, PNG, GIF, SWF, MP3, and FLV files.
    An SQL database can be used to store the file names and their
    location. ASP can retrieve that data from the SQL and return to
    Flash to load the above file formats.
    For Flash to do the communication with ASP you need to
    determine if you are using URL Encoded or XML data structures.
    For URL Encoded data you look at
    LoadVars.sendAndLoad
    For XML Encoded data you look at
    XML.sendAndLoad
    Then in their onLoad methods you use
    MovieClip.loadMovie
    to load JPEG, GIF, PNG and SWF;
    Sound.loadSound
    for MP3,
    NetConnection.connect,
    Video.attachVideo and NetStream.play for FLV.
    For the ASP side the work with the database has nothing to do
    with Flash other than using any search variable sent from Flash
    with LoadVars.sendAndLoad or XML.sendAndLoad. In other words it
    could be an HTML form sending the same variable and calling the
    same ASP script. Same with returning values except with Flash only
    URL Encoded or XML data structures are sent back and not
    HTML.

  • Problem with dimension of an image loaded from a database

    Hi,
    I succeed in saving image in a MSAccess database with this code:
    Image img;
    image = new ImageIcon("d:\\prova\\comore.jpg");
    img=image.getImage();
    try{
    int[] pix = new int[img.getWidth(null) * img.getHeight(null)];
    PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(this), img.getHeight(this), pix, 0, img.getWidth(this));
    pg.grabPixels();
    System.out.println(pix.length);
    byte[] pixels = new byte[img.getWidth(this) * img.getHeight(this)*4];
    for(int j=0;j<pix.length;j++){
    pixels[j] = new Integer(pix[j]).byteValue();
    String sql="insert into Immagini values ('1',?)";
    PreparedStatement ps = con.prepareStatement(sql);
    ps.setBytes(1,pix);
    ps.executeUpdate();
    }catch(Exception except){
    except.printStackTrace();
    then, I've load the image with this code:
    try{
    String query = "select * from Immagini where IDprog = 1";
    Statement s = con.createStatement();
    s.executeQuery(sql);
    ResultSet rs=s.getResultSet();
    rs.next();
    Viaggio vi = new Viaggio(rs.getInt(1),rs.getBytes(2));
    byte[] b=vi.getBytesImage();
    int[] intImage = new int[b.length];
    for(int j=0;j<b.length;j++){
    intImage[j]=(int)b[j];
    Image img = createImage(new MemoryImageSource(124,100,intImage,0,124));
    ImageIcon imgic = new ImageIcon(img);
    jLabel3.setIcon(imgic);
    }catch(Exception tps){
    tps.printStackTrace();
    All works correctly;
    but I've two problems:
    How do I do to take the dimension of the image from the byte array?
    infact in the code up written I've used 124 and 100 as image dimension;
    but I can have images of different dimension.
    The other problem is:
    Why in the image that is loaded are not the same number of colors of the image saved, but only a few, so that the image seems to be out of focus?
    Thank and excuse me for my english.
    I'm Italian.

    Noone can help me?
    Thank

  • Data type for Saving Image in SQL database

    Hi,
        Which is the best way for saving images in the database? Filestream or Varbinary(max)?. Will the Varbinary max comsume much space or it will only take the actual size of the data?

    I've used FILETABLE for storing images in SQL 2012
    You can configure it to have transact and non transact access if you want
    see
    http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Image path not storing in sql database

    Hello,
    I have read here on the forum how to upload an image to server and store path in  your database, the image uploads correctly to the correct folder on my server but the image path does not get stored on my sql database (not local hosting). I receive the error: The file has been uploaded, and your information has been added to the directory. Column 'image' cannot be null.
    My database has the following columns:
    id
    datum
    image
    sectie
    My code is as follows:
    <?php require_once('Connections/dbTroch.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;
    mysql_select_db($database_dbTroch, $dbTroch);
    $query_rs_aanbod = "SELECT * FROM tblSlideshow ORDER BY id ASC";
    $rs_aanbod = mysql_query($query_rs_aanbod, $dbTroch) or die(mysql_error());
    $row_rs_aanbod = mysql_fetch_assoc($rs_aanbod);
    $totalRows_rs_aanbod = mysql_num_rows($rs_aanbod);
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    $target = "images/slides/";  //This is the directory where images will be saved// 
    $target = $target . basename( $_FILES['image']['name']); //change the image and name to whatever your database fields are called//
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add-photos-aanbod")) {
      $insertSQL = sprintf("INSERT INTO tblSlideshow (image, sectie) VALUES (%s, %s)",
                           GetSQLValueString($_POST['file'], "text"),
                           GetSQLValueString($_FILES['image']['name'], "text"));
    //This code writes the photo to the server//
    if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
    //And confirms it has worked//
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
    else {
    //Gives error if not correct//
    echo "Sorry, there was a problem uploading your file.";
      mysql_select_db($database_dbTroch, $dbTroch);
      $Result1 = mysql_query($insertSQL, $dbTroch) or die(mysql_error());
    ?>
    <!doctype html>
    <html>
    <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Troch Project Solutions - Admin - Toevoegen</title>
      <link rel="stylesheet" href="css/foundation.css" />
      <link rel="stylesheet" href="css/layout.css" />
      <!-- Fonts
      ================================================== -->
      <script type="text/javascript" src="//use.typekit.net/vob8gxg.js"></script>
      <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
      <!-- jQuery
      ================================================== -->
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
      <script src="js/vendor/modernizr.js"></script>
    </head>
    <body>
        <div class="row">
          <div class="large-8 medium-8 small-8 large-centered medium-centered small-centered columns intro">
              <h2 class="subheader text-center">Admin</h2>
              <p><a>Log uit</a></p>
              <p><a href="admin.php">Terug naar Admin menu</a>
              <h4>image toevoegen naar aanbod slideshows:</h4>
              <form action="<?php echo $row_rs_aanbod['']; ?>" method="POST" name="add-photos-aanbod" id="add-photos-aanbod" enctype="multipart/form-data">
              <table>
                    <tbody>
                         <tr>
                              <td><label for="image">Kies foto:</label></td>
                              <td><input name="image" type="file" id="image" value="<?php echo $row_rs_aanbod['image']; ?>" /></td>
                        <tr>
                              <td>Sectie:</td>
                              <td><select name="sectie" id="sectie" option value="sectie">
                                <?php
    do { 
    ?>
                                <option value="<?php echo $row_rs_aanbod['sectie']?>"><?php echo $row_rs_aanbod['sectie']?></option>
                                <?php
    } while ($row_rs_aanbod = mysql_fetch_assoc($rs_aanbod));
      $rows = mysql_num_rows($rs_aanbod);
      if($rows > 0) {
          mysql_data_seek($rs_aanbod, 0);
          $row_rs_aanbod = mysql_fetch_assoc($rs_aanbod);
    ?>
                              </select></td> 
                        </tr>
                        <tr>
                            <td><input type="Submit" name="Add" id="add" value="Toevoegen" /></td>
                        </tr>
                </tbody>
            </table>
            <input type="hidden" name="MM_insert" value="add-photos-aanbod" />
        </form>
          </div><!-- end large-8 -->
        </div><!-- end row -->
    <script src="js/vendor/jquery.js"></script>
    <script src="/js/vendor/fastclick.js"></script>
    <script src="js/foundation.min.js"></script>
    <script>
                $(document).foundation();
            </script>
    </body>
    </html>
    <?php
    mysql_free_result($rs_aanbod);
    ?>
    I cannot work out what is wrong and I would appreciate any help on this. Thanks

    Your form field and array variable names do not match
    <td><input name="image" type="file" id="image" value="<?php echo $row_rs_aanbod['image']; ?>" /></td>
    GetSQLValueString($_POST['file'], "text"),

  • How can I map an image (JPEG) from the SQL database image string

    I saved the image into SQL database, see attachment (SaveImage2SQLDB.rar), while I have some trouble to retrieve the image. I also attached the vi which I used to convert the string to image. The string already has a value I obtained from the database. Can anyone tell me the reason why it didn't work.
    Thanks in advance.
    Jane
    LabVIEW 2012, VDM 2012
    Attachments:
    convertstringtoimage.vi ‏78 KB
    SaveImage2SQLDB.zip ‏27 KB

    Hi Jane,
    What exactly isn't happening correctly?  The conversion or the retrieval? 
    This discussion forum may be of some use: http://forums.ni.com/t5/LabVIEW/image-from-compressed-string/m-p/2207894
    Matt S.
    Industrial Communications Product Support Engineer
    National Instruments

  • Inserting an image to Jframe and save it ,  in SQL database

    Hai guys,
    I just wanna know about the inserting image in to a Jframe (in netBeans) it will be a grate help if you tell me the way to call a image to Jframe through a Button click and save the image in MySQl database.
    Is anyone has a idea about this task, please tell me
    Thanks,

    Image class should work to get the data, then add it to a Canvas object, then you can save the bytes from the Image into an SQL statement through JDBC.
    The implementation details will vary based on which approch and database you select.

  • What datatype should i use to store imaq image in sql database?

    Hi there i am thinking of saving the imaq image into database for retrieval in my website so that it's like a stream but i don't like what datatype does labview store the image as.

    You have two options for storing images in a relational database:
    A.  Don't put it in a database.  Store it as a file, and store the pointer int he DB (as mentioned above).
    B.  Store it as a blob datatype.  See here for more info.

  • How do I show multiple rollover images on a page inserted dynamically (pulled out of a sql database

    How do I show multiple rollover images on a page inserted dynamically (pulled out of a sql database table) using Dreamweaver’s Repeat Region. Example: I have different products each one associated (through their productID) with two images (one that’s showing in the page and one for the rollover effect) that are pulled from a database using Dreamweaver’s Recordset. So I want to end up with a page containing row after row of images(one for every product).When moused over each image will reveal the second (rollover) image for the same product which in turn can be a link(the image itself ) that when clicked leads to a detailed page with more information about the product the image is associated with. To show row after row with images for the different products in the database table I am using Dreamweaver’s Insert Rollover Image command and then the  Repeat Region – I have no problem to complete the steps, to insert the image and the rollover one at once and set the paths so they are pulled dynamically depending on the productID they are associated with .I have also no problem to apply the Repeat Region so not only the first image associated with the first product in the table is shown but all of them-a routine and standard procedure when using the Repeat Region to dynamically generate and display multiple rows of data. However, when I preview the page the rollover effect is lost –the images are shown but when moused over the second  image does not  show. The problem is caused when the Repeat Region is applied-once again I am allowed to apply it but the rollover stops working, a kind of interference. ANY SOLLUTION PLEASE, ANY WORK AROUND.

    I gotta tell you, using multiple images for rollover effects is going to be a big challenge in your dynamic scenario. 
    If this were my product page, I would use thumbnails with a bit of CSS opacity or filters to desaturate and make them full opacity/color on mouse over.  Nice effect with much less bandwidth. Easily done globally with CSS code.
    Two examples:
    http://alt-web.com/GALLERY/GalleryTest.php
    http://alt-web.com/TEMPLATES/CSS-Semi-liq-photo-sheet.shtml
    Nancy O.

  • How can I insert an image(JPG) into a SQL database?

    I have written an application to perform some tests in the lab.  After gathering the data I store it into a SQL Server.  I successfully managed to export all my raw numbers and calculations to the DB.  However I have not been able to export a screenshot of the Front panel.  I can write the screenshot to a JPG file just fine.  The problem is putting the image (binary data) into the DB.
    So from what work I've managed to do, two questions come to mind:
    1)  Is there a way to compress the screenshot, using standard JPG compression, without actually writing out to a file.  ie:  Just have a binary stream of the compressed image that I can write to the SQL database.
    2)  Even if I don't use compression, I can't write any kind of data that appears as an image.  What kind of data do I need to be writing from LabView to store it properly in an 'image' or 'binary' type field in a SQL database?  I am not looking for answer "binary data."  Nor do I want the answer that is stated in the Help file for the DB Connectivity Toolkit(type - Data Cluster).  What I need is to know what kind of conversions I need to do on the image data that comes out of the FP.GetScaledImage.
    I am using LabView 8.0 and have the Database connectivity toolkit.  We are running SQL Server 2000 and 2005.

    I also hit this limit.  In the end I just wrote the JPGs to disk, and stored the file path in the DB.  Not the ideal solution, I know.
    I'm trying to remember now, exactly what the problem was.  You're right to say the image data type should handle up to 2GB.  I think in the end, it was an issue of the LabView toolkit not playing well with newer versions of SQL Server, which have the image type.  Re-reading the error though, it sounds like it might be an issue with the ODBC driver.  FYI, 8KB used to be the max size for the largest types in SQL Server (I think binary in 2000).  I suspect this limit was coded into the driver or LabView, and can't handle the newer, larger types.
    That being said, the LabView DB toolkit was either written poorly or written a long time ago.  It has issues with generating SQL queries that have the proper quotes.  For example, if your column names have spaces in them, the toolkit will be unable to generate a valid query, without some modification of the toolkit *.vi's.  Images in a database is not a new concept and not new to me.  I've never used a language where it was more complicated or difficult to get working.  Unless you absolutely have to, I'd work out a way to just store the JPGs to disk, with the path in the DB.  Spending too much time on this defeats the purpose of using LabView.
    If NI decides to update the DB toolkit, then it might be worth giving it a try again.
    In case any NI people are reading this, this is a not so subtle hint that you need to update the DB toolkit to support modern DB features.  Especially, if NI is charging $1000 for it.

Maybe you are looking for

  • Oracle to SQL server connection - not working

    Hi Friends, OS version : R Linux EL5 Oracle version : 10.2.0.4 i had followed http://www.databasejournal.com/features/oracle/article.php/10893_3442661_2/Making-a-Connection-from-Oracle-to-SQL-Server.htm document and modified tnsnames.ora, listener.or

  • Can oovoo be downloaded on ipad 2?

    I was wondering if oovoo can be downloaded to ipad2.

  • No sound on start up

    Hi We have been on holiday recently and while away my youview box updated. Since then when switching the box on from standby and switching on the tv I do not get any sound. If I then change channel the sound comes on. Has anyone else got this problem

  • Account suspended after receive "Skype Manager" in...

    Hi, my account was suspended after recieve 2 emails. I didn't accept any invitation but anyway the account was automatically suspended. Email - 1) You have been invited to join the Skype Manager called Photothema. This is administered by harfstvanden

  • SOX related issue

    Hi, As per the SOx task we are getting users as per the the bleow: Run ABAP RSUSR002 Transaction Code: SE16 Authorization Object: 1) S_TABU_DIS and values 02 2) S_DEVELOP with value 01 02 06 07. I got users list, when I search roles by users (from th