I want to store a little bit of data on my server that can be accessed easily by anyone. It's for a game I am making and I want to store a few things such as:
Game version (String)
Description (Long String)
News (Array of Strings)
Changelog (Array of Strings)
etc...
I figured that making a whole database and table for this would be overkill. I would like to be able to access the information using various types of media but I at least ant it to work with PHP (web) and Java (Desktop and android). Also the data will be updated and inputted manually by only me but readable publicly so that other websites can use it if they choose. What would I use for this kind of thing?
Extra: I might eventually want to input data manually. Things such as "Players Joined" would be managed by my server and would increment it automatically.So if it can do that too that would be great.
I have decided to use a Database and access the data with MySQL. I already have one for my game so it is a good choice because of that (this means I won't be creating a whole database just for this). I will create a table that will store this data and the table will only have 1 row (ID = 0). I will access it by selecting the row with ID = 0. I will have to create other tables with news and changelogs too.
If you have a similar question to mine, check this out:
http://www.dummies.com/how-to/content/storing-data-with-php-flat-file-or-database.html
It provided some useful advice. Also look into JSON or XML and SQLite.
You might want to check out H2 database. It can run as an embedded database (just include a jar, no extra installation, etc.), is very solid and you can get up and running very quickly.
Related
I'm trying to write a java-based movie database program. It recursively searches a given list of folders, retrieves information about the movie files within, and allows you to search for movies using tags/actors/file resolution/etc, and will show a cover thumbnail of the movie and screenshots.
The program as I have it now stores information (atm only filename/size) in arraylists, and generates a html page with the thumbnails. I would like to use a mysql database instead so it will persistently store the movie information and doesn't have to search through all the folders every time.
I can use a "Media" object for each movie to store all this info, but I'm not sure of the best way to store this in a database. I don't want to just serialize the Media objects because then I would have to iterate through the whole db to search, which would be slow. I assume I need to use mysql queries to search.
I have only a less than basic knowledge of database design although I do have an idea how to use jdbc to create/access a mysql database once I have decided on a layout.
Can anyone give me some pointers on what I need to learn and where to learn it in order to decide how to lay out/index and link the tables for my movie database?
Here's my current Media object:
public class Media {
File file_location;
String filename;
Date date;
int hres;
int vres;
boolean has_tbn;
File tbnloc;
boolean has_ss;
File ssloc;
int length;
String[] actors;
String[] tags;
boolean HD;
long filesize;
String md5;
From what you said, I assume you already know how to setup/create a MySQL database, so I won't bother with that.
First, you will need to make a table for your media. Start designing a column that can store each object in your Media class with the appropriate data type, as well as set a primary key, which should be unique. This is preferably a separate id number. Also be sure to specify which columns cannot be null or blank, to avoid accidentally writing incomplete data.
However, I also see you have arrays for actors and tags. As a designer, I would prefer for these to be in separate tables, with another table joining them to the main media table for a many-to-many relationship. You could also make it simpler and just set it as a long string with a separator that you will parse and place into the array.
You may want to reconsider saving a file directly into MySQL as well. I prefer just saving the file location and keeping the actual file as is.
I think you should also take a look at the sample database the current version of MySQL has, called Sakila, which should also be available for install when you install the latest version of MySQL. It's a database for a video store, and thus has well-designed tables for storing film data and all its related factors.
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.
I want to build a fairly simple Android application.
The basic data model of my app consist on several basic elements with relationships between them.
I want the data to be persistant so I'm thinking about using an sqlite DB.
I looked at the Android Developer website, and the closest thing that I could find that is relevant to my question is the "NotePad Tutorial" which make use of an sqlite DB to store notes.
I think by now I got the handle on the basics, but I still have some questions though:
In the tutorial they have only one table in the DB. If my application requires a more complicated scheme - should I still use the same method? that is - putting everything inside a subclass of SQLiteOpenHelper? Or is there a more "structured" way to go?
Should I bother creating classes for all the data elements stored in my DB? I mean this is what I learned that I should do, but in the documentation there is no hint about that.
If I Should create classes - How should I use them correctly? I mean, since the result of the query is a Cursor object, and not a collection of rows, Should/Can I parse that into objects?
Thanks!
Define all the tables in the same subclass, this makes easy to see all the table at one place and possibly write SQL for upgade etc
Yes, that would be easier for manipulation in the java side and makes code clean
Read from the cursor and initialize an arraylist of objects one by one.
My app uses a SQLite database for the information. I have a function that checks to see if the folder and database are already present, if they aren't it will go on the internet ( currently I am using dropbox to store the db file ) and download the database and store it on the sd card, then I it will open the database. The database is writable as it lets the user rate an object. I have two questions.
1.) I would love to provide updates to the database and then have my app update the database if the version number is higher and replace the existing one. I have done some research and from what I have found it is possible to store an xml or json file with the version number of and the just parse the information and if the version number is higher download the new database.
Can someone provide an example of how this is accomplished and whether it is better to use xml or json for this task?
2.) Is there a way to save the rating in the new version of the database when the new is downloaded and accessed?
Thanks
two nights ago I wrote something like that.
pack your database structure as an array in a webservice method by reading field names and field types. the structure of array is arbitrary.
call web service method and you must receive a string that represent a JSONArray object, if you sent it as json with json_encode() method in php.
read structure and make CREATE DB query string with for loops.
execute query, so you must have database.
also you can send alot of information with arrays.
introducing each part is hard, so for each part google it.
don't forget to convert field types to match SQLite types such as VARCHAR=>TEXT, smallint=>INTEGER , ...
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.