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
Good day, guys. I have a web application that is used for monthly inventories. I'm using java and MySQL. I'm able to insert and update a new record to the database. These monthly inventories can be viewed using jsp tables. The records are filtered by classifications and month-year. Every month contains a lot of same records and only differs to the number of inventory items and its price. Because of this, I want to make an automatic insertion of records in the database based from the records of the previous month.
Basically, what I want to do is to automatically fetch the records/items of the previous month and make a new copy to the database with an updated date based from the system date. This will be done every time the system date reaches a new month. Is this possible? If yes, can you suggest solutions on how I can achieve this? If not, can you suggest other alternative solutions? Thank you in advance!
UPDATE
I've made an extra button in my JSP that calls a servlet when clicked. This automatically generates a copy of records of the previous month. I used the INSERT ... SELECT query to do this. Now, I want make it like a scheduled task so that it automatically generates a copy of records without clicking a button. The records will be generated every time the system date changes the month and date. I've read about cron jobs but I don't really know how to apply it in my web application. I'm only using jsps and servlets in windows. Can anyone suggest How I can achieve this? Thank you in advance.
Using a cron job with you php file, assuming all the data will be passed from periodicity you can set your cron job up like so, if your not familiar at all with cron jobs here's a good tutorial to get you going :
01 04 1 1 1 /var/www/somedirectory/somephpfile.php
just change the somedirectory/somephpfile.php to where your file is saved.
there's multiple different Cron codes you can use here
heres a breakdown of the code i wrote above
01 04 1 1 1
this is your timing, starting from the first number:
1.minute (0-59)
2.hour (0-23)
3.day of month (1-31)
4.month (1-12)
5.day of week(0-6) starting from Sunday
Then the last part of the code:
/var/www/somedirectory/somephpfile.php
This is just the location of your file that you want to be executed automatically
if you need any more just ask =)
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 17 days ago.
Improve this question
If I need to perform an automated housekeeping task, and this is my query:
delete from sample_table where id = '1'
And, this scheduled query gets executed from multiple service instances.
Will this have a significant performance impact? What would be an appropriate way of testing this?
Issuing multiple deletes for the same partition can have a significant impact on your cluster.
Remember that all writes in Cassandra (INSERT, UPDATE, DELETE) are inserts under the hood. Since Cassandra does not perform a read-before-write (with the exception of lightweight transactions), issuing a DELETE will insert a tombstone marker regardless of whether the data exists or has already been deleted.
Every single DELETE you issue counts as a write request so depending on how busy your cluster is, it may have a measurable impact on its performance. Cheers!
Erick's answer is pretty solid, but I'd just like to add that the time that you'll likely see performance issues is at read-time. That's because doing a:
SELECT * FROM sample_table WHERE id='1';
...will read ALL of the times that the DELETE was written (tombstones) from the SSTable file. The default settings on a table result in deleted data staying around for 10 days (to ensure proper replication) before they can be picked-up by compaction.
So figure out how many times that DELETE happens per key over a 10 day period, and that's about how many Cassandra will have to reconcile at read-time.
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 13 days ago.
Improve this question
I am trying to retrieve the new inserts from a table in my java client application (Spring JMS), to do some processing and send them to a message broker. I do not have access to any CDC tool like Goldengate. I only need the new inserts and not the updates or deletes. I am having difficulty finding a way to do this. Is there a way to do this? I read that there is an option to do these with triggers, but will it have a high throughput on the db, because this table gets a lot of inserts in a day (approximately around 50K records inserted in a day).
Thanks in advance
50,000 rows per day is actually rather a low volume. Some data warehouse tables get 50 million rows a day. So an insert trigger is unlikely to make any appreciable difference on the loading job. Add a date column (e.g. LOAD_DATE) and have a before insert trigger assign :new.LOAD_DATE := SYSDATE.
That being said, if you wanted to avoid a trigger, you can modify the loading job itself to load such a date a column with SYSDATE.
With either method, your retrieval is then simple: each day as you retrieve records, record the maximum LOAD_DATE value you retrieved. The next day, pull only records with a LOAD_DATE >= that value.
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 need to generate a sequence number which is in ranges of 1000 to 3000. Every day at 12 midnight this sequence should reset to 1000 and for each request this should be incremented. Is there any way we can achieve this. I need to implementation in one of web application which uses Spring Boot and MongoDB.
I know in Java we cant achieve as my application will be run as multiple instance also it will be deployed in Cloud docker container.
1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/
2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with #Scheduled and specify a cron expression to run at the exact time.
Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.
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 6 years ago.
Improve this question
I need to store multiple user details from different country. How can I store the dates in DB (in UTC format) and how can I show the dates to the users accorning to their time zones.
I am using Java and mySQL.
In MySQL, use the TIMESTAMP data type in your tables.
For each user, store a timezone column, VARCHAR(64) is a good data type for that column. When a user registers to use your system, ask for the time zone value. Mine is America/New_York. Yours might or might not be Asia/Kolkata. For a user interface for this user-preference setting, the WordPress.org software has a good example.
Finally, whenever you establish a connection from your Java program to your DBMS in behalf of a user, issue the SQL command
SET SESSION time_zone='(whatever tz string the user gave you)'
before you handle any user data.
This will cause all times going in to your tables to be converted to UTC, and all times coming out to be translated to local. It works properly for NOW() and CURDATE(). Again, you must use TIMESTAMP and not DATETIME or DATE data types for this.
Make sure your server OS and default MySQL time zones are set to UTC. If you don't do this before you start loading information into your database, it will be almost impossible to fix. If you use a vendor to run MySQL, insist they get this right and fire the vendor if they don't have it right.
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'm facing this problem. When I wrap times from websites I'm always getting a 0:00h or 0:30h for example. This is technically at the beginning of the current date. But for humans is at the end of current date.
I need 0:00 to 6:00 get sorted at the end of the day instead of beginning, directly from data-base.
I'm using java, hibernate criteria, mysql datetime.
Thanks all!
You can get your dates and times ordered correctly by using MySql DATETIME data types throughout your application. The Java equivalent class is util.Date.
According to computer and telecommunications industry standards, the first millisecond of each calendar day has the time 00:00.000. So, if you add ten seconds to 23:59:51.000 you get 00:00:01.000 on the next day.
It sounds like your business has a different, non-standard, rule for describing the beginning and ending of each day, to use for this particular display. That's fine. But you need to enumerate this rule very precisely indeed. Midnight matters in many fields of human endeavor!
Let's say your rule is that a day's information runs from [01:00:00 to 01:00:00) the next day.
Then you can select yesterday's records in a MySQL query like this.
WHERE `timestamp` >= CURDATE() - INTERVAL 1 DAY + INTERVAL 1 HOUR
AND `timestamp` < CURDATE() + INTERVAL 1 HOUR
...
ORDER BY `timestamp`
This will display your stuff in the right order. It won't display the time 24:01, but it will place 00:01 after 23:59.