Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am new to Android development and I am trying to make a Trivia application.
I need to store the data relating to questions somewhere and I am not entirely sure where to store it.
I plan to have multiple people playing so I need each person to have the same questions.
Basically I planned to have a list of categories and within each category I had question objects.
The question objects contained information regarding the question such as the answers and question itself.
However, if I use a database, I believe none of this would be needed due the questions being stored in tables which would represent categories.
In terms of speed what would be better:
to store it in a database
or to read from a file every time the application is loaded and store the data within a data structure?
You almost certainly want a database. Databases are made for fast search and easy insertion/deletion. There's really no advantage to having a file and doing in memory parsing each time.
Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:
You can query items as you wish -- don't need to load all of them and
select which ones you need.
Record deletion is a much less painful process. No rewriting of whole
files into wherever.
Updating a record is as easy as removing or creating one.
Have you ever tried doing cross-referencing lookups on a flat file?
Just.Not.Worth.It.
To summarize, it's every advantage a Database has over a text file.
Answer by josephus
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm new to using a database, specifically MySQL. I'm creating a web application for class in which you can look up the name of a book and it'll display the summary of the book. My question is should I send a query to the database that collects all of the books' data on initialization and put them into a HashMap inside a manager class for lookup or should I use a query each time to lookup a specific book information?
It depends on the data transport time I would say. If your average query time times the number of request goes faster than a script to put everything into a HashMap, use queries. Otherwise, use a script that collects everything and puts it into a HashMap.
But if you have thousands of rows, you should use queries, because otherwise you will use too much RAM.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to make a dialogue tree (conversation tree) in Java using libGDX. Should I use lots of conditionals (if,else etc...) and move on to the next dialogue or is there a better way to read a file such as XML that already have the dialogues inside? Also, I want the solution that would consume the least possible memory amount because I am going to write it for Android.
Example of the dialogue tree:
(Q: Question, A: Answer , C:Choice ,AC:Action)
Q:Hi is there anyway that i can help you?
A:You own me 5 dollars!
C1:Ask politely to return them to you, C2:Τhreaten her , C3:Draw your gun
A1:No way get out of here , A2:Call the security , A3:Call the cops
AC1-2:Exit the building //end of choices 1-2
C3.1:Draw your gun and shoot the cops , C3.2:Jump from the window
AC3.1:Arrested , AC3.2:Dead
If your game is going to have little dialogue, I would use Strings for it, but if you base it around the dialogues, I would use a SQLite or similar database to store them in it. I don't know whether it will be the most efficient way to do that, but that what's occurred to me while reading your question:
You could use e.g. column 1 for the question, and columns 2, 3, 4, 5 for the possible answers. You can get information about using SQLite in libGDX here
You could make into some method actor, whom he pass an id to access the SQLite for the question and the answers to that question, then assign some variables, and use a switch statement, if you don't want to have much if-elseif etc.
Note: I think that SQLite is mostly used when you want data to be saved and used in the future; if the data for example change every 10 minutes, I think it would be better to use JSON, because in SQLite making connections to the database every 10 minutes may take some time. I think this is not the case; in my opinion the purpose of JSON and SQLite is completely different. I would use for example:
JSON = I would use it to send or/and receive data betwen server & client or configuration files etc.
SQLite = I would use it to store data.
This is only my opinion, and I not say that SQLite is better or worse than JSON.
PS 1: the photo is taken from the Internet
PS 2: I also believe that you should read https://stackoverflow.com/tour
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a three million rows in a database and I need to get all the values in a table as object and operate on those objects ? what is the best possible solution ?
The best solution is to not load all of them.
Why would need to load them all and operate on them?
Maybe you can do a SP (stored procedure) and work on these rows on the DB server.
If you still need to load them all, try to not load all columns of these rows.
Maybe you can use something like paging (if that is applicable to your case).
My answer is maybe too general but so is your question.
As Peter said, don't load them all. Instead, use an iterator, like a database cursor (ResultSet for the rows in a SQL query) to keep track of your place in the data. For any more specific answer, you'll need to give more detail, but you should also consider whether you can use SQL aggregation functions (COUNT, GROUP BY, etc.) to reduce the number of rows your application needs to process.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So, I want it to be very easy to create all the entities of my game and for other people to come in and do the same. I was thinking I could just let the users/myself create an XML sheet the stores all the properties of each block (Like a Terraria or Minecraft voxel) and add Lua scripts that are referenced in the XML for additional functionality of any of the blocks.
I'm starting to think It would just be easier to let the user create a JAR file full of classes for each block. And then that JAR file could easily be used to get all the blocks. It'd just be interesting to reference all the blocks by a block id without storing all the classes by ID. Or I could give each class a static id. But that's not important.
Okay, so my short question is what are the pros and cons of storing all the the different types of blocks as classes versus in an XML sheet with Lua for additional functionality?
UPDATE: It looks like I'll be using pure Lua! Looks like an interesting and effective way to do it!
A limitation of the JAR approach is that your data would need to be compiled before it got used. With XML/Lua the data gets read/interpreted at runtime.
A third option that you did not mention is using straight Lua tables instead of XML. This lets you load the data with a simple "require", "dofile" or similar instead of needing to use a XML library as well.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
So, I'll be looping through a data base and there will be a bunch of campaigns. Each campaign will have some demos and some sites where certain conditions are satisfied. I want to plot some graphs for the data corresponding to all the campaigns, sites and demos. I was thinking of using java, first getting the campaign, site and demo combinations where the conditions are satisfied and then looping through all of them, running individual queries based on their values and plotting the graphs using maybe, GNU plot. My questions are -
Is there a better way to achieve this (with minimal queries).
If I do do it this way, I first have to store the information.
I was thinking of storing the campaign ids in an ArrayList of Integers, the demos for each campaign in
ArrayList<ArrayList<Integer>>
and the sites for each campaign in
ArrayList<ArrayList<Integer>>
Is there a more efficient way of storing this information?
I'd recommend creating a new class to hold your campaign data and storing references to each object within an ArrayList if you need to keep a handle to them in memory (may not be necessary).
From a purist point of view, the class should be backed by a Data Access Object (DAO) and Plain Old Java Object (POJO) to manage database access and storage in memory but if this is a simple prototype then I wouldn't worry too much. I'd also recommend a utility class to convert/write your chart data - all accessible from your Campaign class.
The Campaign class should also be able to work out whether your conditions are satisfied - and if it's worth generating those charts.