Re: COPY support implemented - Mailing list pgsql-jdbc
From | Csaba Nagy |
---|---|
Subject | Re: COPY support implemented |
Date | |
Msg-id | 1073987900.18243.13.camel@coppola.ecircle.de Whole thread Raw |
In response to | Re: COPY support implemented (Per-Olof Noren <pelle@alma.nu>) |
Responses |
Re: COPY support implemented
|
List | pgsql-jdbc |
Hi, Some thoughts on converting files between different encodings (my search for this was long enough to share the results). If you're on Linux, you might use the "iconv" tool to convert the file encoding (for details: man iconv). On all platforms you could use the "native2ascii" tool (it's part of the JDK), in a 2 step process: first convert from iso-8859-1 to the ASCII/unicode encoded format, then convert that to UTF-8 using the "-reverse" option. For all the options of native2ascii, consult the docs for your platform, possibly: http://java.sun.com/j2se/1.3/docs/tooldocs/tools.html#intl HTH, Csaba. On Mon, 2004-01-12 at 19:34, Per-Olof Noren wrote: > Hi Kris, > > On Tue, 2003-12-30 at 09:25, Kris Jurka wrote: > > With the introduction of the V3 protocol in 7.4 it is now possible to > > support the COPY protocol in the JDBC driver. Before it was impossible to > > recover from errors and the Connection had to be abandoned. This patch > > implements support for COPY based on the API proposed by Michael > > Adler's original patch of about a year ago. > > This is great news, as I'm currently working on a project that could > benefit from being able to run copy on a client machine. > I have patched the driver from the 7.4.1 src distro with the patch and > it compiled successfully. > > After giving it a spin (which actually failed due to another reason, > more on that below) I have a little suggestion. > > Consider this simple example (which happen to be my very code) : > > String filename = "myfile.csv"; > String sql = "COPY <<tablename>> FROM STDIN"; > PGConnection pgConnection = > (org.postgresql.PGConnection) connection; > > CopyManager copy = pgConnection.getCopyAPI(); > FileInputStream fis = new FileInputStream(filename); > copy.copyInQuery(sql, fis); > > The reason for using copyInQuery is that I need to be able to specify > the delimiter. I'm reasoning that i'm probably not alone on this. > > My suggestion is one of the following: > > Add CopyManager.copyIn(String tName, InputStream is, String delimiter); > > Or add Javadoc that clearly states that the query > *MUST* be using "FROM STDIN" or the server will start looking locally > for the file, giving an FileNotException. > > > Ok, now to my litte trouble. > The database is encoded in LATIN1 running on pgsql 7.4.1. > I'm running the above code on a different machine running linux using > locale "sv_SE". The file I'm trying to import is encoded in ISO-8859-1. > Then running the above code I get the following error: > org.postgresql.util.PSQLException: ERROR: could not convert UTF-8 > character 0x00f6 to ISO8859-1 > > This must be the JVM's encoding being set to UTF-8, right? > Or do I need to specify the encoding in the jdbc url or something? > > Thanx in advance > > Per-Olof Norén > Curalia AB > > > > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster
pgsql-jdbc by date: