assume having a table of people information and want to add their children as well. so you have two options:
1- you can put child's info in JSON array and store it as a JSON string in people table
2- you can create children table and link it to people table.
which one is better to modify and is faster?
note: the order of children is important
if there's a better way please let me know
Surely option 2.
Going with the first option will make you parse/process the JSON everytime you need to retrieve some value or want to add some data.
While Option 2 will not only make the transactions easy but will also add maintainability and scalability.
Happy Coding :)
Related
When update an existing field in the table, what is the best practice to consider? Like I do write a lot of PUT method which overwrite the existing data when update ( I consider with large objects using a lot of logic and also calculation, it'd be better).
But what about sometimes I just need to update one field? I saw a pattern of using same or similar put method when people update data, in those function, they will check to delete the old one and put the new data into table.
Should it be better if we using an update set JPA query to change exactly what we need?
Like there's an existing function when user create or update the record they have, should I create then add one update set query inside that function so it would update or create into those new set table I create?
Thanks for reading this load of text, I hope to have a clear point of view to become a better programmer.
I did try to google to understand the definition but not so clear. I hope I can get a clearer point of view here.
So I've found questions similar to this one, but none that have helped me with my problem. So I have an ArrayList< ArrayList < String > >. This basically creates a table of user inputs, so you can add columns and each column can have different amounts within them. I need to cycle through the combinations that can be created without comparing objects in the same column. Ideally I could send it through a nested for loop and access each element using an if statement to separate as needed, but since it is a dynamic size I haven't been able to find a way to do this that doesn't compare within the same column as well. Thank you in advance for your help.
If I'm understanding your problem correctly, it sounds like you have a List of Lists, where the first List is kind of like a key, where each slot is a list of the data you need. I ran into a very similar problem, and I was able to use a Map to hold the values. If order matters, then you'll want to use a TreeMap.
I mention the Maps, because you mention you want to manipulate (what sounds like the rows in a table), rather than the columns. If you use a TreeMap, then the keys stay in the same order, and the value for each key will be like the rows in the table. Then, the index in each List would be the column.
Without a solid example of your data, I'm not able to really go into how to compare the "combinations", which I assume can be handled by the Lists in the values of the Map, in this situation.
I have three tables:
Department :
Designation :
Department Designations :
DesignationID and ReportTo are foreign keys of table designation, which shows that a specific designation report to a specific designation. i.e. Manager(Which is designation) Report to CEO(Which is also a designation )
Now I want to generate a tree, like...
I manually enter the entries to shows above tree . i.e
Now My Problem is that, I am not able to write a function in a way that generate this tree, automatically.
In short, After fetching records from database, I want to generate tree as shown above.
Any Solution ?
NOTE: LEVEL OF TREE IS NOT FIX, THERE MAY BE UNLIMITED LEVEL OF TREE
It's Java, so you can make that tree as deep as it needs to be.
Separate the query from the population of the tree from the UI rendering and you'll have no problem. Query the database, populate the tree and give it to the UI to render.
You'll have issues if you try to mingle one part with another.
You can use a Tree structure like this, and then populate it from the query.
Then, you will have different choices, for example:
1) You convert your tree to JSON and iterate it recursively with jQuery;
2) You iterate it directly in Java (recursively), building the output server-side (let's say a big String containing your HTML). Then you simply inject the result in the page (not that good because of coupling between server and client side)
etc...
Here's an hint.
It's a tree you need to iterate recursively over the tree items till
you reach the leaf level in order to populate it and as mentioned in
answer give by #duffymo you should separate logic of tree population
from your query.
Link if you still are unable to solve
Best luck :-)
i think you could use php for drawing this tree.
example.
write the join query for selecting data to row
<li>
while(!empty($row))
{
echo'<li><ul>$row[designation name]';
while(!empty($next))
{echo'<li><ul>$next[designation name]';
//next sentence must be a select query
}
echo'</ul></li>'
}
echo'</ul><li>'
}
this is not ur answer but a hint that can tell the logic.
I would assume that I should use a jTable. I tried this, but I can't for the life of me figure out how to append, insert and delete rows without a ton of overrides and complicated code. I find it hard to believe that Oracle doesn't have an easier way to do it.
Here's the premise. I have a few arrayLists. Each contain n amount of items and I want to be able to add these items' properties in the form of strings to the jtable and once i surpass a certain number of rows, I want the jTable to scroll.
So that's the reason I need to be able to add and remove rows.
As discussed in How to Use Tables: Creating a Table Model, DefaultTableModel has convenient methods to add, insert and remove rows. Simply update your model using any of these methods and your view will be updated accordingly.
Addendum: There's an example here.
Take a look at GlazedLists. It makes working with dynamically changing data and sowing it in JTables/JLists/JTrees, etc, very simple.
I have retrived some datas from DB and I have stored it in an ArrayList. The ArrayList contains some 50 rows returned each row containin 4 columns. How do I access a particular column of a particular object in ArrayList? Can someone help me with this?
Not sure what is the exact issue here. List is based on the index and hence you can access any data based on index. Another option is to convert use Map which allows you to refer to the data based on a key you desire.
Due to new data posted in comments on the question, this is now know to not be what OP wants. I'd delete it but, given what I've read from him/her so far, I'm afraid he/she may be forever flummoxed by the disappearance of an answer.
ORIGINAL ANSWER
If you really have an ArrayList and not a ResultSet then do this
myList.get( desiredRow*column_width /*4*/ + desiredCol);
This assumes row-major ordering.