Checking for updating mysql table - java

I need help with my project. I've made some swing java app which allowed to users make some operations with database (deleting, adding, inserting etc). Then this app has 2 roles, for whom who made the change (delete,add,insert into database) and for whom who check it. So for users who check, I have to make smth which alarm them, like "this user added smth to this table now". So I have no idea how to realise it, first of all I think I should write smth for check database changes like every minute? Like ScheduledExecutorService? Maybe. But I don't know how to check it for changes? For example i have table employee, it has columns like: name, surname, tel.number, salary. For example some user change salary from 100 to 200. So how it checks this table for changing? Maybe someone could show me example? Because I couldn't find it, I couldn't do it for 2 days. Please! Any help would be very much appreciated!

Related

android, Everyone should evaluate each day only once

I'm going to build an app. Until now everything runs very well. Now I have a problem. The app gets its content from a mysql database.A column is called item.I have a ratingbar. The user can rate the item there.Every time the user evaluates an item the value is stored on the database in the respective item line.The values ​​are then added. In other words, when a user evaluates 20 times with 5 stars, the value adds up to 100 and so on.
I want to limit this. I will that the user can evaluate each day only once an item. I will it without a registration mask for the user. How can I solve this problem?
I know that i can identifier the WIFI MAC Adreess and other Unique Identifiers, but how can i solve this with them?
I can not use sqlite database, because the items should update with the time from the mysql database.
A registration mask should not be excluded. If this process is quite possible with them, then I supplement it with it.
I am looking forward to every comment
every computer has a machine ID, you will hash that and encrypt that to use as your identifier..most telecomms do not like using MAc addresses as IDs
One option would be to create UUID during every installation and sending this UUID to your server along with every request. In server, you can control very well if user can provide feedback once a day or others based on your requirement. Pls refer this link on how to create UUID.
https://developer.android.com/reference/java/util/UUID.html

how to send an e-mail automatically when a row is inserted in the database?

I have to develop a application with the following scenario:
1--User create a profil (name,lastname,address....)
2--The information are inserted in the database
3--The administrator should receive an e-mail to be notified by the new profil ,if the administrator dont
approve the profil he will delete it.
Is there a way to send automatically an e-mail when a row is inserted in the database?
I'm using java.
If you are doing this through a common interface, then I'd suggest putting a seperate call next to the insert routine (between Java and database).
I heard you can do a whole lot of things with triggers in MS SQL, but I was told to keep my hands away from triggers. Made by the devil to make a day turn bad. People that has succesfully mastered triggers will tell you otherwise.

android listitem from server and stores data to database

i'm trying to do mail program. i've done this using jsonArray, Http protocals and some other functions. But, now i want to implement the program likely unread mails and starred mails. If i'm pressing anyof new mail it'll assign likely 1 to database. Otherwise, keep it 0. And, also if i want to set any mails in important (starred) this will keep 1 to database. Otherwise, keep 0. Now, i want to create a database related to these concepts? Anyone know about this concept Please help me to do this? Thanks in advance.
Use SQLite,
Below tutorial will help you to get started,
http://developer.android.com/guide/topics/data/data-storage.html#db
http://www.vogella.de/articles/AndroidSQLite/article.html#overview_sqlite
Good luck!
Edited :
Create a database with a table "Whatever name"
Than have content such as
|SeqNo|MailFrom|MailTo|Subject|Body|Starred|etc...|
Example
|1|blah#clah.com|blahblah#blah.com|Hi|Hello|0|etc...|
|2|bla1#clah.com|blahbfgv#blah.com|Hi|Hello|1|etc...|
Hope you can match example with given table format, It's like a simple SQL database where you can query while loading inbox and check whether user has selected a mail and starred it! However you can create those star button which will change state of that table's column while being click.

What should be the correct/better approach for locking a record in table?

Actually, the problem is like this:-
i am having a table, say Payments. I have provided few GUI for searching, viewing and editing the record. Now if the user is trying to edit a record perform some particular action, which takes say 1 minute to process. Then another user should not be able to perform that particular operation on the same record.
Traditional approach of doing this is, have a column in the table, say _isLocked_. and whenever user is performing that action it should change the value of said column to, say, true. Once the process is completed it should reset the value of the column. Also, just before someone tries to perform the action, it should check the value of the column and notifies the user if the record is locked.
What other approached are there to do the same?
SELECT FOR UPDATE is the way. We get this kinda behaviour by using this.
As Vinegar said, SELECT FOR UPDATE - accept his answer, not mine :)
Make sure to know when the user really wants to edit a row, and when he/she is done. Depending on your application, you could open a separate window where user does the modification and then confirms/cancels, so you can do your COMMIT/ROLLBACK.
And make sure that another user who attempts to change the same row will not face a frozen application and have to wait for the lock to be released.

Displaying a result of a query from the database in increments

I want to display a list of all the users in my site but I only want to display 10 people per age. I don't know how exactly to do this. I know how to do it by just displaying all the users in one page but that's not very good is it?
If I do it with the code I have now, it will only get the first ten users over and over again.
I want to be able to get all the users for a one time query, store it globally and then move through the list retrieving the next 10 and so on for display.
I am developing on appengine using Java and the Spring Framework some of the solutions I have been thinking about,
Store in the session and go through the list (very bad I guess)
hand it to the JSP, specifically to one of the scopes, page, request etc. But I think request will not work.
Look for a Spring controller that can handle this.
Generally speaking, you would use a form variable on your page (via GET or POST) called 'page', which would be a number. When you receive that in the servlet you would calculate a range based on the page number and configured rows per page.
Take a look at Paging through large datasets (yes it's Python but the same principles apply) and Queries and Indexes from the Google App Engine documentation.
Take a look at http://valuelist.sourceforge.net/
If you keep page size at 10 then you can retrieve your 10 users per age group for each page based on page number:
SELECT TOP 10 users FROM myusers
WHERE AGE = function(page_number)
ORDER BY some_ordering
I hope that JPA + appengine support such type of query.
Some database engines provide handy extensions to SQL for just this purpose. Like, in MySQL you can say something like "select ... whatever ... limit 50,10", where "50" is the row to start with and 10 is the number of rows to retrieve. Then on your display page you simply put next and previous buttons that pass the appropriate starting row number back to the server for the next run at the query.
If the SQL engine you're using has no such handy function, then you have to build an query-specific "where" clause based on the sort order.
To take a simple case, suppose in your example you are displaying the records in order by "user_name". You can use Statement.setMaxRows(10) to limit any queries to 10 rows. Then on your first call you execute, say, "select ... whatever ... from user order by user_name". Save the last user_name found. In your next button, you pass this user_name back to the server, and the query for the next call is "select ... whatever ... from user where user_name>'xxx' order by user_name", where 'xxx' is the last user_name from the previous call. Do the setMaxRows again so you are again limited to 10 rows of output. You can then let the user step through the entire output this way.
Letting the user go backwards is a bit of a pain. I've done it by keeping a table in a session variable with the starting key value for each page.

Categories

Resources