Is there a way to detect changes in MSSQL table in Java. If new record insert into specific table want to detect in Java. Searched in Goolge can't get any solution most of results are like schedule the Job or runnable thread to detect the changes. Is any specific way to detect the changes in Java. Suggest the Best way to detect the changes.
Asked
Active
Viewed 784 times
-1
-
2Not directly, no. There's no best way because it depends entirely on what you're doing, your system design and many many other things. – Kayaman Feb 19 '20 at 11:43
-
In .NET you could use [SqlDependency](https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/detecting-changes-with-sqldependency). I have no idea how to use this feature from Java. See [SQL Server Query Notifications in JAVA](https://stackoverflow.com/questions/23659038/sql-server-query-notifications-in-java) – Vladimir Baranov Feb 19 '20 at 12:53
2 Answers
0
just some ideas
- a trigger, from database
- a code to check before you save,update,delete and then dispatch some event
- maybe can use a listener, interceptor, auditing(jpa/hibernate), Observer Pattern(not sure)

Eve
- 37
- 9
0
Do you have a single client application or a distributed program with multiple users in multiple places?
I think the trigger, as mentioned by everson, is the go for. Create a trigger in your MSSQL System which sets a boolean-value in a new table (presumably with 1 column with 1 entry) to true. Each time you fetch for changes you will need to reset this value to false

Niklas Lyszio
- 55
- 7