We are not sure what would be the size of file on upload an image
For now, planning to go with medium blob and using mysql as database.
Assume, if the customer uploads more than 16MB, the DB column should be automatically changed to longblob to accomodate the file. This is to cover the edge scenario, however we may not sure whether it would happen
What is the best way to support or achieve this?
Thanks.
The best way to achieve this is to define your database fields properly. You don't switch fields just because the file is larger than the datatype, that's bad design. Also, there are really no disadvantages from using a LONGBLOB from the start. If you want to limit the amount of data pasted into your database, you should already limit this in the java side, not rely on the database to do so.
Related
I have a requirement in my service, which is such that whenever an update call is made to database I want to compare current value(which I am updating) from previous value(present in database) and based on that need to take a decision(e.g. sending a notification). The only way which I was able to think for this problem was to make a Database call(before update) and compare the events.
Can someone suggest a better approach for this?
If the data volume is small, you can use cache to store data for quicker read.
Other than that, if you have bigger amount of data volume and want higher performance, I would suggest to have more replications to the database and use leader-followers type of config so that you can scale your read by adding more followers to it
I´m developing a Java SE app for vet.
I have a table name pets, each pet have a photo that is a blob Column, the question is, when selecting all pets the photo column affect the perfomance of the app?.
In the app I pass the query result to Pet objects i'm thinking when having many rows, the photos charged in memory will affect perfomance.
In general, it should not affect performance. Much. A blob is ultimately just a pointer to an IO stream. The performance hit comes in when you actually start loading the photos, which will start doing IO operations. The question is, when do you actually need the image data?
As Thorbjorn pointed out, you probably shouldn't put the blobs in the main table. Either the system has to maintain the table of blob pointers, or your object will have to load image data that it may not need yet. Better to have a separate table with an "imageID" column or somesuch. Then add a "Pet.loadImage()" method, or maybe an event trigger, that will load the image as needed.
I have here a bunch of XML-files which I like to store in a Cassandra database. Is there any possiblity out there to manage that or do I have to parse and reform the XML-files?
You can certainly store them as a blob or text but you will not be able to query the individual fields within the XML files. One other thing you'd want to be cautious of is payload size and partition size. Cassandra in general isn't really designed as an object store but depending on payload size and desired query functionality, you may either have to parse/chunk them out or look for an alternative solution.
I am planning on creating an android application sometime in the future in which I'll want it to display a lot of constant data on the screen.
I'm not sure the best way to do this but I see two options:
Storing the data within the code itself such as creating a constants class.
Using an embedded database to hold the data.
I'm guessing option #2 is the best way? But it just seems weird using a database if I'm not going to be doing any updating to the database, I would only be selecting.
The total amount of data that I need the application to display is maybe about 400 lines consisting of a string and two integers...
Is there a different way people use for such a situation that I don't know about?
But it just seems weird using a database if I'm not going to be doing
any updating to the database
I am totally disagree with you. Database is not only for updating. It can be used as a better storage and definitely a best way for searching. So as you want to preserve the data then it is definitely wise to use database.
But if you want to handle data which will not persists , i,e you will use different datas for different run then you can use temporary class or other data structure to store data.
Finally, If you are planning to have portability then File storage is an easier solution.
SO you can see, that it totally depends on what you want.
For a university assignment I have been assigned I have a Prize object which contains either text, image, or video content. I would like to persist this information into a BLOB field within an Apache Derby database (which will be running on a low powered PDA). How can I add this data to the database?
Thanks in advance.
In this article Five Steps to Managing Unstructured Data with Derby
you can read how to do this.
It describes how to insert binary data into a column with the BLOB datatype in Apache Derby using JDBC.
I assume you'll be connecting via JDBC. If so, simply write your SQL and look at the setBlob method of a PreparedStatement. Should be pretty straightforward.
Serialization is the easy way to do it, however if possible you could make it look like a real database table with a structure containing id (bigint), datatype (smallint), creationdate (date) and data (blob) and specifically make the client code to save the object's data there. This way you could do searches like "get all video prizes created between January 1st 2008 and January 15th 2009" and it wouldn't break down old data if your class would change too much for the serialization to stop working.
This sort of solution would be easy to extend in the future too if there would be need for it; I understand this is a school assignment and such need most likely won't ever surface but if your teacher/professor knows his stuff, I bet he's willing to give an extra point or two for doing this excercise in this way since it takes a bit more time and shows that you can take the steps to prepare in advance for coping in the everchanging landscape of software development.
If you are using Netbeans (I assume Eclipse has similar functionality) you can setup your database schema and the create new Java entity classes from the database and it will generate the appropriate JPA classes for you.
http://hendrosteven.wordpress.com/2008/03/06/simple-jpa-application-with-netbeans/
This is nice as it allows you to focus on your code rather than the database glue code.
The best solution , is to use Derby, because it keep being a multi platform app developed via Java.