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 Re: Problem Inserting Swedish Characters in Derby Database
Date Sat, 24 Jul 2010 18:47:39 GMT
  Sorry, I forgot to mention this is with Derby 10.6.1.0 and JDK 1.6.0 
update 20 on Windows 7 Professional 64-bit.

Mark Johnson

On 7/23/2010 10:35 PM, Mark D. Johnson wrote:
>  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 {
>             
> Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
>         } 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 
> ("jdbc:derby:testSvenskaDb;create=true;territory=sv_SE;collation=TERRITORY_BASED:PRIMARY;");
>         } 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();
>             stmt.close();
>             conn.close();
>             DriverManager.getConnection("jdbc:derby:;shutdown=true");
>         } catch (SQLException se) {
>             if (se.getSQLState().equals("XJ015")) {
>                 System.out.println("Database shut down normally");
>             } else {
>                 System.err.println("Abnormal shutdown");
>             }
>         }
>     }
> }
>

Mime
View raw message