Thread: Big problem inserting Russian characters into Postgres using JDBC

Big problem inserting Russian characters into Postgres using JDBC

From
"Edd Stanley"
Date:

I have never had a problem that has kept me stumped for so long. All I need to do is to simply use my Java application to insert and select Russian characters into the Postgres database. Every time I try to insert the Unicode characters into the DB, the table seems to only be populated with “??????” question mark characters. I am pretty sure that the database itself is configured correctly because I can insert Russian characters at the SQL command prompt. The database has been “configured” with its encoding as Unicode and it says this when I do “\encoding”

 

Here is what I do and all I come up with is question marks:

 

 

String URL = ("jdbc:postgresql://192.168.0.5:5432/russ?encoding=UNICODE");

try {

      new org.postgresql.Driver();

      db = DriverManager.getConnection(URL, user, pwd);

    }

catch (Exception e) { System.out.println("Couldn't connect to the database: " +e); }

}

 

String rus_word = "\u0424\u042F\u041B\u0414\u0416\u0436\u0434\u043B";

//or

String rus_word = "Ложка";

String insert_stmt = (“INSERT INTO rus (russian) VALUES(‘” + rus_word + “’)”); //Column type for “Russian” is text

    try {

      statement = db.createStatement();

      statement.execute(insert_stmt);

    }

    catch (Exception e) {

            …….

    }

 

Shouldn’t this be a very simple thing to do as to insert multibyte-characters into the database table? What am I forgetting?

 

I am running Postgres version 7.2.1, JDK 1.3 using the Postgres JDBC 2.

 

 

Thanks,

Edd Stanley

eddstanley @ mindspring . com

 

Re: Big problem inserting Russian characters into Postgres

From
Dave Cramer
Date:
Edd,

Check the notes at http://lab.applinet.nl/postgresql-jdbc/#reading

for encoding issues

Dave
On Thu, 2002-05-30 at 12:53, Edd Stanley wrote:
> I have never had a problem that has kept me stumped for so long. All I
> need to do is to simply use my Java application to insert and select
> Russian characters into the Postgres database. Every time I try to
> insert the Unicode characters into the DB, the table seems to only be
> populated with "??????" question mark characters. I am pretty sure that
> the database itself is configured correctly because I can insert Russian
> characters at the SQL command prompt. The database has been "configured"
> with its encoding as Unicode and it says this when I do "\encoding"
>
> Here is what I do and all I come up with is question marks:
>
>
> String URL =
> ("jdbc:postgresql://192.168.0.5:5432/russ?encoding=UNICODE");
> try {
>       new org.postgresql.Driver();
>       db = DriverManager.getConnection(URL, user, pwd);
>     }
> catch (Exception e) { System.out.println("Couldn't connect to the
> database: " +e); }
> }
>
> String rus_word = "\u0424\u042F\u041B\u0414\u0416\u0436\u0434\u043B";
> //or
> String rus_word = "Ложка";
> String insert_stmt = ("INSERT INTO rus (russian) VALUES('" + rus_word +
> "')"); //Column type for "Russian" is text
>     try {
>       statement = db.createStatement();
>       statement.execute(insert_stmt);
>     }
>     catch (Exception e) {
>::.
>     }
>
> Shouldn't this be a very simple thing to do as to insert
> multibyte-characters into the database table? What am I forgetting?
>
> I am running Postgres version 7.2.1, JDK 1.3 using the Postgres JDBC 2.
>
>
> Thanks,
> Edd Stanley
> eddstanley @ mindspring . com
>




Re: Big problem inserting Russian characters into Postgres using JDBC

From
"Thomas De Vos"
Date:
Hi,
 
Had the same problem not so long ago on Linux Debian and Blackdown JVM.
It turned out that the Blackdown JVM and Sun's JVM was the problem, changed to IBM's and problem solved. Nothing changed on the DB and nothing changed on the code.
 
It took me also a week to figure this one out.
 
Thomas De Vos
-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Edd Stanley
Sent: 30 May 2002 17:53
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] Big problem inserting Russian characters into Postgres using JDBC

I have never had a problem that has kept me stumped for so long. All I need to do is to simply use my Java application to insert and select Russian characters into the Postgres database. Every time I try to insert the Unicode characters into the DB, the table seems to only be populated with “??????” question mark characters. I am pretty sure that the database itself is configured correctly because I can insert Russian characters at the SQL command prompt. The database has been “configured” with its encoding as Unicode and it says this when I do “\encoding”

 

Here is what I do and all I come up with is question marks:

 

 

String URL = ("jdbc:postgresql://192.168.0.5:5432/russ?encoding=UNICODE");

try {

      new org.postgresql.Driver();

      db = DriverManager.getConnection(URL, user, pwd);

    }

catch (Exception e) { System.out.println("Couldn't connect to the database: " +e); }

}

 

String rus_word = "\u0424\u042F\u041B\u0414\u0416\u0436\u0434\u043B";

//or

String rus_word = "Ложка";

String insert_stmt = (“INSERT INTO rus (russian) VALUES(‘” + rus_word + “’)”); //Column type for “Russian” is text

    try {

      statement = db.createStatement();

      statement.execute(insert_stmt);

    }

    catch (Exception e) {

            …….

    }

 

Shouldn’t this be a very simple thing to do as to insert multibyte-characters into the database table? What am I forgetting?

 

I am running Postgres version 7.2.1, JDK 1.3 using the Postgres JDBC 2.

 

 

Thanks,

Edd Stanley

eddstanley @ mindspring . com