How can i store and retrieve images from a database? - java

I am creating a website as a mini project which will be used to sell various products. In the website i intend to give detailed info about the products which will be retrieved from the database. I am using Servlets and JSP as the serverside and pointbase DB. So i'll be using JDBC to connect to the DB. Please tell me how insert images into the DB and give sample code for the same. Also give details how to retrieve them.
Thanks you all in advance..

Wouldn't it be easier to store images on a file system and store the paths in the database?

You can insert binary data into databases that support binary fields (usually called BLOB).
But that isn't such a great idea - store them in your server and store the path to them on the database instead.

You should convert the file to a BLOB and then store it in the database as such, this will then make easy retrieval details below...
http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/help.html

I still think that it is better to store images in a database. It is more efficient.
Here is a good tutorial of how to do it:
http://tutslink.blogspot.com/2012/04/jsf-displaying-images-from-database-in.html

Related

Way to store images, text notes and audio files in offline database. Android, Java

I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.

How to store images in ArangoDB?

I want to store images in ArangoDb as image file. I want to know if there is any API or Java API for the same. Thanking You in advance.
Storing binary data inside ArangoDB has been a long standing feature request.
Currently its not possible out of the box.
One can however do this by creating a foxx service that handles the data.
The recommended way is to create a file and reference that file name inside the database.
A detailed description and an example foxx app can be found in the cookbook

How to save files on android storage, write to them, and access them later on?

I am working on an android app to take float values from 3 different arrays, transform them into strings and then store them into a text file on the internal storage of the phone. I want to be able to access these values later and put them on a computer so I can do some statistical analysis on them. Can someone please show me how to do this?
Create a File object, and store your values in a flat-file database. For more info on how to create a flat-file database, go here. To learn more about the File API, go here. To learn about more data storage options that Android provides, go here.

Need to send email on database insert

This question might look similar to existing one's but is really different.
I have a scenario where I have to send emails to different users while inserting data into MySQL DB. The logical part has been completed using Java. This is reading very huge data from via CSV files on file server and after processing those data, inserting into DB.
Now my need is to send email to different users on each insert operation.
The data is quite very heavy so I think using triggers would not be a good idea.
Can you please help me to get a better solution?
I do also have php app connectivity with this database.
In my opinion you should try php library like PHPMailer, PEAR Mail, SwiftMailer, etc as you should note that php's mail function is inherently not optimized at all.

Putting media into an Access Database using Java

I'm making an email system in Java using an Access database as connectivity. What would be the best way to get and upload media/files (.gif, .au, .mpeg and .txt) attachments to the access database? What datatype would the field in the database have to have? I think that i have to convert the file to binaries to be able to store them, i have no idea how i would retrieve them so i can open them in the Java GUI. Could any body explain how to do this so i can add it into my program, or explain any alternatives?
OLE OBJECT is really the only option you have if you want the actual binaries to be stored in an Access Database.
You'll probably be able to use setBlob and getBlob to work with it.

Categories

Resources