From: marek at lewczuk.com (Marek Lewczuk) Date: Thu, 18 May 2006 15:31:42 +0200 Subject: [Pljava-dev] ResultSet getString In-Reply-To: <446C69C8.3030908@tada.se> References: <446C5033.2000508@lewczuk.com> <446C55FE.2020902@tada.se> <446C69C8.3030908@tada.se> Message-ID: <446C773E.6000102@lewczuk.com> Thomas Hallgren napisa?(a): > Marek Lewczuk wrote: > I see what you mean. Question is, what string representation should be > used? What is more intuitive? Using the Java 'toString()' representation > of an object or the PostgreSQL String representation of the SQL type? > > A typical Java developer who's not fluent in PostgreSQL type coercion > would expect that ResultSet.getString() on a boolean would return "true" > or "false", i.e. something that can be passed to Boolean.valueOf(String) > and that Array types would follow the format stipulated by > java.util.Arrays.toString([]) family of methods. > > At present, the getString() method will coerce basic types to strings > using Java semantics. Arrays are not coerced though, since that > functionality was introduced in Java 1. Lets see what Java api say about ResultSet.getString(): "Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language." It doesn't say, that getString() will return "a string representation of the object". Now, if I would like to get PostgreSQL String representation of multi-dimensional array, what method should I use ? For me obvious thing to do is to call getString() and I wouldn't expect that this will return same as ResultSet.getBoolean().toString(). Another example: Statement statement = ... statement.execute()... ResultSet result = ... while (result.next()) { // result contains 3 columns: varchar[], boolean, integer[] // we create a duplicated row, without worrying about the SQL type Statement s = connection.createStatement(); s.executeUpdate("INSERT ... (c1, c2, c3) VALUES ('" + result.getString(0) + "', '" + result.getString(1) + "', '" + result.getString(2) + "')"); } My opinion is that you should keep getString() as a method to get PostgreSQL string representation - this will keep compatibility with previous pljava versions. ML