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 7 years ago.
Improve this question
I think I have to ask my question in another way.
At transactional database which of the following case has been recommended:
writing multi or 2 insert query for saving log of program on DB that has more pressure on server .
writing trigger after inserting for saving log of program on DB that has more pressure on DB.
Thanks for attention.
If you are sure that the insert to the DB will happen only from your application end then I would go for the first option by creating a procedure and include both the INSERT statement in a TRANSACTION block. which will make sure atomic operation.
But, in case there are possibilities that insert to the DB may happen through adhoc query or through third party ETL tool then you have no other option than having a trigger AFTER INSERT TRIGGER to perform the log insert operation (2nd option) since there is no way to call the other INSERT statement automatically or explicitly.
Related
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 1 year ago.
Improve this question
I am trying to learn multi-threading in java.
Suppose I have a very big application with 100 running threads trying to execute a synchronized method which inserts a row in database.
As, the method is synchronized so only one thread will get the lock for that method and rest 99 will wait.
Only 1 thread is able to edit the Database and rest will be waiting. It seems a slow process. As all the threads will be editing the DB one by one. Is there any other way or concept to safely edit the database in a faster way?
i will recommend u to read about isolation level in transaction to handle some cases in concurrent application https://en.wikipedia.org/wiki/Isolation_(database_systems), sometimes is handles by default.
if for isntance u only adding new rows in table u shouldn't care about it and remove synchronized
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 4 years ago.
Improve this question
I want to monitor changes that occur in the database. Say, for instance when an item is removed from the database. I want to be able to use an interface to monitor such changes and create an alert of how many no of items are left in the database . Every 5 min or so. Is there any plugin for java, or some kind of interface or something else? I will be grateful for the help.
Best Option Use DDL TRIGGER as it is DB change event meaning
CREATE DDL TRIGGER
ON DB AFTER DELETE AS
"YOUR ACTION STATEMENT" ;
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 4 years ago.
Improve this question
I am working on a batch application where I have to retreive millions of records and need toprocess it individually. We are using hibernate to connect to DB.
I have tried using HQL and Criteria API to fetch the records(using the query Select * from table_name).
But it is taking more than 5 min .Sometimes it is getting hanged.
Can anyone suggest me the best approach for the data retrieving.
You may want to employ cursors, and if your queries are as simple as you indicated, pure JDBC may be sufficient - like here: https://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
Also, consider adding the WHERE clause to eliminate rows that can be recognized as irrelevant for your purposes.
And depending on your table and queries, adding an index may also help.
If you need to use hibernate, you can use ScrollableResults as mentioned here: https://stackoverflow.com/a/9891008/455449
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 am making an online test with predefined questions and it's correct answer I let student enter their answer to each question and I took them and check them against correct form DB. is it better to call DB to for each answer to check or get all question right answer and make loop o(n)^2.I am using hibernate
A bulk operation is the best. It requires a single database roundtrip and you can do all the processing in the database so that you don't have to move one million records back and forth the DB.
For more details about Bulk Updates, check out this article.
In your example, it does not matter if the user had a test with 1000 questions. If they have a predefined right answer, you can match that in the DB automatically.
If you need to manually validate answers, do it with batch processing and process only N answers at a time and send all answers in a single batch to the DB.
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 have an Oracle Database and I want to monitor a particular table/column in the DB . If the column value crosses threshold value I want to call my java application code to perform some operation LIKE EXAMPLE SCALE UP OR SHUTDOWN. How can I achieve this? Any pointers or help needed.
Set Serverout On
Declare
comm Varchar2(2000);
Begin
comm := OSCommand_Run('/home/jguy/runJavaApp.sh')--for calling commands
DBMS_OUTPUT.Put_Line(comm);
End;
I suggest you to use triggers, they are designed to do stuff like this and I really wouldn't mess up it with Java in this case.
You can use triggers (i this case an update trigger) that will execute a particular function/stored procedure on certain conditions.
There are multiple ways you can do this:
Trigger on the table, which will check column value upon each DML statement and if value crosses threshold.
As trigger may have some performance impact on table, you can create a scheduler job calling a stored procedure which will invoke on periodic basis (every min or anything you like) and then check the column value and call java app if it crosses threshold.
I prefer trigger but check the performance impact on the table.