Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/04/2010, 05:35
digdig
 
Fecha de Ingreso: marzo-2007
Mensajes: 26
Antigüedad: 17 años, 1 mes
Puntos: 0
Pregunta Problemas con tildes y eñes al hacer consulta a Access desde Java

Hola compañeros, es un gusto volver por aquí.
Tengo un problema con una aplicación Java en la que estoy trabajando.
Resulta que me conecto a una base de datos Access mediante JDBC-ODBC pero no encuentro la manera de que me imprima caracteres como las vocales acentuadas ni las eñes (entre otros). En vez del correspondiente caracter, me aparece un interrogante o un cuadrado.
En las tablas de access todo se ve correctamente, las tildes, las eñes, etc.
He probado varias cosas, a nivel de código he tratado de especificar el charset de la conección.:

Properties props = new Properties();
props.put ("charSet", "iso-8859-1");
[...]
Connection con = DriverManager.getConnection(database, props);

A nivel de máquina virtual, he usado el siguiente parámetro de configuración:-Dfile.encoding=ISO-8859-1

Hasta el momento sólo he logrado que en vez de un interrogante aparezca un cuadrado donde debería estar el caracter conflictivo.

¿Hay alguna manera de atacar este problema que de resultado?

Espero que podais ayudarme, muchas gracias amigos.



Código:
package accesstest;

import java.sql.*;
import java.util.Properties;

class Test {

    public static void main(String[] args) {

        try {
            Properties props = new Properties();
            props.put ("charSet", "iso-8859-1");

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            // set this to a MS Access DB you have on your machine
            //C:/Users/Jorge/AccessTest/Test2003.mdb
//            String filename = "C:/Users/Jorge/AccessTest/Test2003.mdb";
            String filename = "J:/PROYECTOS JAVA/AccessTest/Test2003.mdb";
            String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
            database += filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
            // now we can get the connection from the DriverManager
            Connection con = DriverManager.getConnection(database, props);


            Statement s = con.createStatement();
//            s.execute("create table TEST12345 ( column_name integer )"); // create a table
            
//            s.execute("insert into Personas values(6,'Mercedes','Fiestas',78512313)"); // insert some data into the table
            
            s.execute("select * from Personas"); // select the data from the table
            ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
            if (rs != null) // if rs == null, then there is no ResultSet to view
            {
                while (rs.next()) // this will step through our data row-by-row
                {
                    /* the next line will get the first column in our current row's ResultSet
                    as a String ( getString( columnNumber) ) and output it to the screen */
                    System.out.println("Persona... Id: " + rs.getString(1)+"  Nombre: "+ rs.getString(2)
                            +"  Apeliido: "+ rs.getString(3)+" DNI: "+rs.getString(4));
                }
            }
//            s.execute("drop table TEST12345");
            s.close(); // close the Statement to let the database know we're done with it
            con.close(); // close the Connection to let the database know we're done with it

        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }
}