how to connect to remote mssql 2005 using java and import csv values in mysql tables at scheduled times?
Background: I have a remote server of mssql 2005(i use remote desktop application to connect to this server),and CSV files at other server.I am creating a utility which take开发者_如何学JAVAs these csv files at pre-defined schedule(3 times a day) and then imports the value of these CSV files in the database.
Problem: I have searched for the code but havent got any help for remote database connection.I want a java code which connects to this remote mssql and inserts the CSV data in this table.Most important thing is this code should run 3 times daily automatically. I guess windows scheduled task will help me achieve this,but i am not sure to what extent. Also note that there are more than 15 CSV files that I want to import,so load infile-provided by sql wont help much.I need everything to be done by java code.
Specification:
coding language:java
database:ms sql 2005
Anyhelp is deeply appriciated.
u can write a batch file in windows or script in linux and use mysqlimport function which uses load-data-infile. it works perfectly. I have been using it..
Create a .bat file
In .Bat file 1. Download all CSV files. 2. run java class (executable)
In Java Class 1. import CSV to MSSQL logic.
You can schedule ur .bat execution using "windows scheduled task" as u said
downloading and running from local system to server is not a good option. If the files are large, it make a bottle-neck on network. And whatz the point on downloading n uploading on same server.
Instead,
String allFile = "file1;file2;file3";
String allTables = "tab1;tab2;tab3";
String[] allFileArr = allFile.split";";
String[] allTablesArr = allTables.split";";
for (int i=0;i<allFileArr.length;i++)
{
String query = "BULK INSERT " + allTablesArr[i] + "FROM '" + allFileArr[i] + "' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) GO";
//fire sql query
}
精彩评论