public static void copyFromFile(Connection connection, File file, String targetTableName) throws IOException, SQLException {
    """
	Method that uses the PostgreSQL-specific copy from file command to load csv data into a table on the provided
	connection. NOTE: This method does not commit the transaction or close the connection.
    """
        // Allows sending over network. This is only slightly slower than a local file copy.
        final String copySql = String.format("copy %s from stdin", targetTableName);
        // FIXME we should be reading the COPY text from a stream in parallel, not from a temporary text file.
        InputStream stream = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
        // Our connection pool wraps the Connection objects, so we need to unwrap the Postgres connection interface.
        CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
        copyManager.copyIn(copySql, stream, 1024*1024);
        stream.close();
        // It is also possible to load from local file if this code is running on the database server.
        // statement.execute(String.format("copy %s from '%s'", table.name, tempTextFile.getAbsolutePath()));
    }
public static void copyFromFile(Connection connection, File file, String targetTableName) throws IOException, SQLException {
        // Allows sending over network. This is only slightly slower than a local file copy.
        final String copySql = String.format("copy %s from stdin", targetTableName);
        // FIXME we should be reading the COPY text from a stream in parallel, not from a temporary text file.
        InputStream stream = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
        // Our connection pool wraps the Connection objects, so we need to unwrap the Postgres connection interface.
        CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
        copyManager.copyIn(copySql, stream, 1024*1024);
        stream.close();
        // It is also possible to load from local file if this code is running on the database server.
        // statement.execute(String.format("copy %s from '%s'", table.name, tempTextFile.getAbsolutePath()));
    }
public static void copyFromFile ( Connection connection , File file , String targetTableName ) throws IOException , SQLException { // Allows sending over network. This is only slightly slower than a local file copy. final String copySql = String . format ( "copy %s from stdin" , targetTableName ) ; // FIXME we should be reading the COPY text from a stream in parallel, not from a temporary text file. InputStream stream = new BufferedInputStream ( new FileInputStream ( file . getAbsolutePath ( ) ) ) ; // Our connection pool wraps the Connection objects, so we need to unwrap the Postgres connection interface. CopyManager copyManager = new CopyManager ( connection . unwrap ( BaseConnection . class ) ) ; copyManager . copyIn ( copySql , stream , 1024 * 1024 ) ; stream . close ( ) ; // It is also possible to load from local file if this code is running on the database server. // statement.execute(String.format("copy %s from '%s'", table.name, tempTextFile.getAbsolutePath())); }
Method that uses the PostgreSQL-specific copy from file command to load csv data into a table on the provided
connection. NOTE: This method does not commit the transaction or close the connection.
Method that uses the PostgreSQL - specific copy from file command to load csv data into a table on the provided connection . NOTE : This method does not commit the transaction or close the connection .