Re: COPY problem in JDBC driver
От | Albe Laurenz |
---|---|
Тема | Re: COPY problem in JDBC driver |
Дата | |
Msg-id | D960CB61B694CF459DCFB4B0128514C20393819B@exadv11.host.magwien.gv.at обсуждение исходный текст |
Ответ на | COPY problem in JDBC driver (Michael Epstein <michael.epstein@mac.com>) |
Список | pgsql-jdbc |
Michael Epstein wrote: > I am using the COPY implementation in the latest > (postgresql-8.4-701.jdbc4) driver with Java VM 1.6.0 (Mac OSX) > > My code is the following (just trying to insert a string from > a file into a single column): > > public static void main(String[] args) { > try { > Class.forName("org.postgresql.Driver"); > Connection connection = > DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/ > xseq_zip","postgres", "postgres"); > PreparedStatement statement = > connection.prepareStatement("DELETE FROM jdbctest"); > statement.execute(); > System.out.println("Erased Db"); > System.out.println(connection.toString()); > > > PGConnection pConn = (PGConnection)connection; > CopyManager copyManager = pConn.getCopyAPI(); > String columns = "(name)"; > copyManager.copyIn("COPY jdbctest " + columns + " FROM '" + > "/Users/foobar/Documents/bulk.txt" + '"); > } > > catch (Exception ex){ > ex.printStackTrace(); > } > } > > The code inserts the value from the file into the db but > throws the following exception: > > > org.postgresql.util.PSQLException: Received CommandComplete 'COPY 1' without an active copy operation > at org.postgresql.core.v3.QueryExecutorImpl.processCopyResults(QueryExecutorImpl.java:918) > at org.postgresql.core.v3.QueryExecutorImpl.startCopy(QueryExecutorImpl.java:713) > at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:52) > at tests.JDBCTest.main(JDBCTest.java:33) > > Has anyone noticed this before? Am I doing something wrong? Your COPY statement is an SQL statement that will not need the CopyManager. It will read the data from a file on the server. Just run it like a normal statement. You'll need superuser privileges though. I didn't look at it, but I guess that CopyManager is only necessary if you want to load from or export to files on the client side, which amounts to a COPY ... TO/FROM STDIN in SQL. Yours, Laurenz Albe
В списке pgsql-jdbc по дате отправления: