package com.philmcrew.data; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; /** * Created by IntelliJ IDEA. * User: Mitchell * Date: Feb 27, 2005 * Time: 11:37:17 AM * To change this template use Options | File Templates. */ public class LoadDataFile { public int load(Connection conn, DataFile dataFile) throws SQLException, IOException { System.out.println("Loading " + dataFile.getTable() + " from " + dataFile.getDataSource()); int ret = -1; String createQuery = dataFile.getCreateQuery(); PreparedStatement pst = conn.prepareStatement(createQuery); try { pst.executeUpdate(); } catch (SQLException e) { System.out.println("LoadDataFile q=" + createQuery + ";e=" + e); } pst.close(); pst = conn.prepareStatement(dataFile.getDeleteQuery()); pst.executeUpdate(); pst.close(); InputStream inputStream = dataFile.getInputStream(); pst = conn.prepareStatement(dataFile.getInsertQuery()); ret = dataFile.deliminate(inputStream, pst); pst.close(); System.out.println("Inserted " + ret + " rows into " + dataFile.getTable()); return ret; } }