db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark D. Johnson" <markdjon...@att.net>
Subject Problem Inserting Swedish Characters in Derby Database
Date Sat, 24 Jul 2010 03:35:51 GMT
  Hi -

I have run into a problem trying to insert the Swedish vowels Å, Ä and Ö 
into Varchar fields in a Derby database.  I first noticed a problem with 
the capital Å using ij to do the insert.  When I did a select on the 
field, the character Å was shown as a question mark.  This is the only 
problem when I use ij - the small å and the other characters are shown 
correctly.  I wrote a little program (listing below) to test this 
outside of ij, and none of the characters appear correct.  It seems that 
the characters are being stored incorrectly, since the output from ij 
shows the same characters from a record inserted with the program as the 
program shows, and the program shows the correct vowels (with the Å 
replaced by a ?) for records inserted using ij.  Can anyone help track 
down what is going wrong?

Thanks for any assistance -

Mark Johnson

import java.sql.*;
  * @author Mark
public class TestClass {

     public static void main (String[] args) {
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         PreparedStatement ps = null;

         try {
         } catch(java.lang.ClassNotFoundException e) {
             System.err.println("Class not found");
         } catch (java.lang.InstantiationException ie) {
             System.err.println("could not create driver instance");
         } catch (java.lang.IllegalAccessException iae) {
             System.err.println("not allowed access to driver");
         try {
             conn = DriverManager.getConnection 
         } catch (Throwable e) {
             System.err.println("Failed to connect to database");
         try {
             stmt = conn.createStatement ();
             stmt.execute ("CREATE TABLE testtbl (str VARCHAR(10))");
         } catch (Throwable e) {
             System.err.println("create table failed");
         try { ps = conn.prepareStatement("INSERT INTO testtbl VALUES (?)");
             ps.setString(1, "ÅåÄäÖö");
             ps.executeUpdate ();
         } catch (Throwable e) {
             System.err.println("insert failed");
         try { stmt = conn.createStatement();
             rs = stmt.executeQuery("SELECT * FROM testtbl");
             while ( rs.next()) {
                 System.out.println (rs.getString(1));
          } catch (Throwable e) {
             System.err.println("query failed");
         try { rs.close();
         } catch (SQLException se) {
             if (se.getSQLState().equals("XJ015")) {
                 System.out.println("Database shut down normally");
             } else {
                 System.err.println("Abnormal shutdown");

View raw message