Bug #768: Wrong special characters handling in Java

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug #768: Wrong special characters handling in Java
Date: 2002-09-15 15:12:03
Message-ID: 20020915151203.67C1E475843@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Antonio Petrelli (antonio-petrelli(at)libero(dot)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, latest stable 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 characters are 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

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2002-09-15 15:16:09 Re: Referencing a superselect's column by it's declared alias from a subselect fails
Previous Message Rod Taylor 2002-09-15 14:51:34 Re: Postgres storing time in strange manner