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[4];
	        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[0] = values[0].replace("'", "''");
	        	values[1] = values[1].replace("'", "''");
	        	values[2] = values[2].replace("'", "''");
	        	values[3] = values[3].replace("'", "''");
	        	statement = String.format(queryBasic, "'" + values[0] + "'", "'" +values[1] + "'", "'" + values[2] + "'", "'" + values[3] + "'");
	        	}
	    		outputStream.println(statement);
	        }
		} catch (Exception e) {
			throw e;
		} finally {
			outputStream.close();
	        inputStream.close();
		}
	}

 Execute the SQL script in DB2CMD

 

db2 -tvsf insertScript.sql

你可能感兴趣的:(sql,Excel,db2)