Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Store Images on SQL Server

Options
  • 12-08-2013 9:48am
    #1
    Closed Accounts Posts: 2,663 ✭✭✭


    i created a Java Program that connects to a database few months back.

    And i am thinking about doing some updates to the program.

    I want to be able to pull a picture from the Computer and Store it within the Current Record that is being displayed on the Application

    I know i will have to use the JFileChooser plugin, but how do i go about storing that image onto the database.


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    SQL Server has a Blob (Binary Large Object) field type. You can just take the binary data from the file/image they upload and write it into a Blob field.

    It's fairly common practice to store these in a separate table linked to your main table, among other things, this makes it easier to move onto different storage if they start taking up a lot of space. With more recent versions of SQL Server you can also use some functionality called "Remote Blob Storage", this lets you configure it so that the actual Blob is stored as a normal file on the file system which is more efficient, especially for larger files/images.


  • Registered Users Posts: 586 ✭✭✭Aswerty


    I might just extend onto stevenmu' answer. You don't neccessarily have to use the "Remote Blob Storage" functionality, that's if your database provides it. You can manage the reading and writing of the files to disk in your code and just enter meta data including location, name, type, etc about the file in the database (i.e. store a pointer to the file in the database). The problem with this approach is that the database can not guarantee that the meta data is actually correctly pointing to the correct file on the file system. I believe this is a problem "Remote Blob Storage" solves.

    Also for very small images ~256KB, e.g. thumbnail images, storing as a Blob in the database can be more efficient that reading/writing to the file system.

    I asked a similar question here a year and a half ago and went with storing the files to disk and entering pointers to the files in the database. You can see that thread Here.


Advertisement