sm702 发表于 2016-11-15 10:35:24

Import data from word into db2

  Copy data from word into Excel.

  Edit data in Excel, and Save as CSV.

  Directly Import the data from csv in Control Center
.
  Generate the SQL script from the csv file in Java.


public static void generateInsertScript() throws Exception {
// input/output file names
String inputFileName= "insert.csv";
String outputFileName = "insertScript.sql";
// Create FileReader Object
FileReader inputFileReader   = new FileReader(inputFileName);
FileWriter outputFileReader= new FileWriter(outputFileName);
// Create Buffered/PrintWriter Objects
BufferedReader inputStream   = new BufferedReader(inputFileReader);
PrintWriter    outputStream= new PrintWriter(outputFileReader);
String deleteStatement = "DELETE FROM ESHLOG.MAP_IDD_MSGFLOW;";
outputStream.println(deleteStatement);
try {
String inLine = null;
String[] values = new String;
while ((inLine = inputStream.readLine()) != null) {
values = inLine.split(",");
String queryBasic = "INSERT INTO TABLENAME (COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) VALUES (%s, %s, %s, %s, '0');";
String statement = "";
values = values.replace("'", "''");
values = values.replace("'", "''");
values = values.replace("'", "''");
values = values.replace("'", "''");
statement = String.format(queryBasic, "'" + values + "'", "'" +values + "'", "'" + values + "'", "'" + values + "'");
}
outputStream.println(statement);
}
} catch (Exception e) {
throw e;
} finally {
outputStream.close();
inputStream.close();
}
}
  Execute the SQL script in DB2CMD

  db2 -tvsf insertScript.sql
页: [1]
查看完整版本: Import data from word into db2