Bug #768: Wrong special characters handling in Java
От | pgsql-bugs@postgresql.org |
---|---|
Тема | Bug #768: Wrong special characters handling in Java |
Дата | |
Msg-id | 20020915151203.67C1E475843@postgresql.org обсуждение исходный текст |
Список | pgsql-bugs |
Antonio Petrelli (antonio-petrelli@libero.it) reports a bug with a severity of 2 The lower the number the more severe it is. Short Description Wrong special characters handling in Java Long Description Platform info: PostgreSQL 7.2.2 (installed with RPM), Linux Red Hat 7.1 with compiled kernel 2.4.18, j2sdk 1.4.0_1, lateststable JDBC driver for version 7.2. In a Java program, when trying to insert/update a row with special characters (such as stressed vocals), these charactersare replaced with interrogation marks (?). Sample Code /* * PostgresTest.java * * Created on 15 settembre 2002, 11.11 * * This test program need the creation of a database named "postgrestest" with * a table named "Foo", with a single column. * */ package bug; import java.sql.*; /** * * @author Antonio Petrelli */ public class PostgresTest { /** Creates a new instance of PostgresTest */ public PostgresTest() { } public static void main(String[] args) throws ClassNotFoundException, SQLException { Connection db; PreparedStatement st; Statement sst; ResultSet rs; String testString; Class.forName("org.postgresql.Driver"); db = DriverManager.getConnection("jdbc:postgresql://localhost/postgrestest", "antonio", "cippalippa"); st = db.prepareStatement("INSERT INTO FOO VALUES(?)"); sst = db.createStatement(); sst.executeUpdate("DELETE FROM FOO"); testString = "Libertè Libertà"; System.out.println("What we expect to put: " + testString); st.setString(1, testString); st.executeUpdate(); st = db.prepareStatement("SELECT * FROM FOO WHERE Name LIKE ?"); st.setString(1, "%Lib%"); rs = st.executeQuery(); while (rs.next()) System.out.println("Inserted value with a prepared statement: " + rs.getString(1)); sst = db.createStatement(); sst.executeUpdate("DELETE FROM FOO"); sst.executeUpdate("INSERT INTO FOO VALUES('"+testString+"')"); st = db.prepareStatement("SELECT * FROM FOO WHERE Name LIKE ?"); st.setString(1, "%Lib%"); rs = st.executeQuery(); while (rs.next()) System.out.println("Inserted value with a normal statement: " + rs.getString(1)); sst = db.createStatement(); sst.executeUpdate("DELETE FROM FOO"); } } No file was uploaded with this report
В списке pgsql-bugs по дате отправления: