问题
I'm building a system which includes JavaFX clients pulling data from a MS SQL server via servlets on a glassfish app server. I also consume some data from a Visual FoxPro database that comes from a legacy system which can't be modified. I'm using the JDataConnect library to create a JDBC connection on the glassfish server against which I can make regular SQL queries to get the data I need.
My javafx clients include many tableviews which are bound to ObservableLists of data retrieved from the databases. There is one table which is a composite of data from the MS SQL data and the FoxPro data. The FoxPro data is updated from a different system. Since there are many ways for the client to slice and dice the data they present to the user, it is prohibitive to try to keep this composite data in sync (not impossible, but difficult). It would be easier (and better for the design of the clients) to update columns in relevant tables in the MS SQL db with the necessary values from the FoxPro database as they change. And since many clients will be accessing the data, it's not wise to have the clients trying to update the database.
So, can I write an application which will run on the glassfish server that will monitor the foxpro database and write the necessary changes/data to the the SQL server database? I just don't know where to start to develop this type of solution, if indeed, this is what the experts would suggest. I'm not even sure what to search for. Totally lost sums it up best.
Thanks for any help or ideas.
回答1:
You may not be able to modify the legacy FoxPro system, but if the tables are stored in a VFP Database container (i.e. DBC file), you may be able to write stored procedure triggers (insert, update and/or delete) within the VFP database container and have them write directly to the SQL server db. You'd need:
- Access to the VFP database container
- Connection string to the SQL server database
- To write VFP stored procedure triggers for the VFP data you want pushed up to the SQL Server tables.
Once you have the connection sorted out, you can write VFP stored procedures using SQLEXEC() command which sends a "SQL statement to the data source, where the statement is processed" (from VFP help). E.g.
m.lnFileHandle = SQLSTRINGCONNECT(m.lcConnectString)
m.lcSQLCommand = "insert into elctablebk.dbo.t_bkcust (custidnum) values ('EdTest')"
m.lnRetVal = SQLEXEC(m.lnFileHandle, m.lcSQLCommand)
The above code gets a filehandle # from connecting to the server, a variable is created with an SQL INSERT command, and the SQL statement is executed on the server using the SQLEXEC() command. If successful, a record is inserted in the example t_bkcust file on the server.
回答2:
So, can I write an application which will run on the glassfish server that will monitor the FoxPro database and write the necessary changes/data to the the SQL server database?
The ideal would be if the FoxPro database could push the changes to your application. You can do this if FoxPro produces a log of the database changes and your application can read this log. I'm not enough of a FoxPro expert to say if this method is feasible.
Another process would be for your application to read the FoxPro database periodically. Say, every 15 minutes. Then it would be up to your application to figure out what's different and update the SQL Server database. The SQL Server database would always be behind the FoxPro database by the polling interval. You would have to determine how often to read the FoxPro database to meet your application's needs.
来源:https://stackoverflow.com/questions/12747982/update-sql-database-from-foxpro-data-on-glassfish-server