1

My Access database has a table with a column that contains text in Punjabi. I am trying to work with that database from Java (NetBeans) using JDBC.

My code is :

private void b1ActionPerformed(java.awt.event.ActionEvent evt)
{                                   
  try
  {                     
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "D:\\PP.accdb";
    Connection conn = DriverManager.getConnection(url);
        System.out.println("Connection Successful");
        Statement stmt = conn.createStatement();
        stmt.execute("select * from Emp");
    ResultSet rs = stmt.getResultSet(); 
    if (rs != null)
        {  
                String s1,s2;
            s1=" ";
            s2=" ";
                while ( rs.next() )
                 {
                JOptionPane.showMessageDialog(null ,rs.getString(2), "Output" ,JOptionPane.INFORMATION_MESSAGE );
                 }
    }
            stmt.close();
            conn.close();
    }
    catch (Exception err) {         System.out.println("ERROR: " + err);         }

}                                  
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
pretty
  • 11
  • 1
  • possible duplicate of [Java ODBC MS-Access Unicode character problems](http://stackoverflow.com/questions/21944861/java-odbc-ms-access-unicode-character-problems) – Gord Thompson Feb 27 '15 at 14:07
  • Is this possible?? ..When we use ms access with java... and query is Select * from ["MS Access table name written in Hindi language"]; – pretty Feb 28 '15 at 08:47

1 Answers1

1

UCanAccess version 3.x, released in August 2015, now supports Unicode characters in table and column names. Note that such names need to be enclosed in square brackets, at least for UCanAccess v3.0.0, for example:

sql = "SELECT [रंग], inEnglish FROM hindi";

 


(Original Answer)

If, as stated in your comment to the question, you have an Access database with table and column names in Hindi or Punjabi then the two most common "direct" approaches for working with an Access database from Java won't work for you:

(1) The JDBC-ODBC Bridge

This is what you have been trying to use. Unfortunately, the JDBC-ODBC Bridge has never worked properly with the Access ODBC driver when the database contains Unicode text that includes characters above code point U+007F. This is true for both text data and table/column names. Also, the JDBC-ODBC Bridge is obsolete: it has been removed from Java 8 and is not supported. So, this option is a dead-end.

(2) UCanAccess

UCanAccess can successfully read/write Unicode text data, but the current (2.x) version cannot work with metadata (table/column names) containing Unicode characters above code point U+007F. Support for those characters in table/column names is planned for the next major release of UCanAccess (3.x), but no timeframe for such a release has been announced.

Other options:

Depending on the constraints under which you need to operate, you might consider one or more of the following workarounds.

  • You could move the data from the Access database into another database whose JDBC driver supports metadata in the Hindi and Punjabi languages.

  • You could build your application in C# instead of Java. (Visual Studio 2013 Community Edition is available for free.)

  • If you really must stick with Java and your data really must stay in an Access database then you could install Microsoft SQL Server Express Edition, create a "Linked Server" in SQL Server that points to the Access database (details here), then use the JDBC Driver for SQL Server to run queries against the Access database.

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418