0

i'm trying to grab data from an access database but i can't because of the columns names containing utf-8 characters such as "°" and "é" for example when i try this query :

SELECT Code_UE, Moy_UE, credit_obtenu FROM Resultats_UE WHERE N°Ins=10025

it doesnt work because of the ° in N°Ins

this is the java code :

    private static final String USER = "admin";
    private static final String PASSWORD = "password";
    private static final String DRIVER = "net.ucanaccess.jdbc.UcanaccessDriver";
    private static final String URL = "jdbc:ucanaccess://[path to file];}";
    Connection connection = null;
    Statement statement = null;
    ResultSet Student_tb = null;

    //Called via UI
    public void OpenBActionPerformed(java.awt.event.ActionEvent evt){
        try {
            connection = DriverManager.getConnection(URL, USER, PASSWORD);
            statement = connection.createStatement();

            Student_tb = statement.executeQuery("select Code_UE, Moy_UE, credit_obtenu FROM Resultats_UE from Resultats_UE WHERE N°Ins='2'");
            while(Student_tb.next()){
                 System.out.println(Student_tb.getString(1));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String args[]) {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }

    }

my db is secured with a password that why i used the user nad password variable this code works well if i just type

    SELECT Code_UE, Moy_UE, credit_obtenu FROM Resultats_UE

and then compair the N°Ins with the result but it takes a lot more time

this is the error message :

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 unknown token: 
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:218)
    at annexe.MainUI.OpenBActionPerformed(MainUI.java:95)
    at annexe.MainUI.access$000(MainUI.java:16)
    at annexe.MainUI$1.actionPerformed(MainUI.java:60)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.sql.SQLSyntaxErrorException: unknown token: 
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:216)
    ... 41 more
Caused by: org.hsqldb.HsqlException: unknown token: 
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.ParserBase.read(Unknown Source)
    at org.hsqldb.ParserDQL.readColumnOrFunctionExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanPrimaryOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanTestOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanFactorOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanTermOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.readWhereGroupHaving(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 44 more
  • [Your problem already solved there bro](https://stackoverflow.com/questions/3275524/java-mysql-utf8-problem) check it – Dostonbek Oripjonov Sep 17 '19 at 16:48
  • he is not using "ucanaccess" .. i tried it and didn't work – Mohammed Amine Sep 17 '19 at 17:00
  • 1
    Your stacktrace mentions HSQL, so it looks like you are not connected to an Access database, but an HSQL database instead. The HSQL driver appears to throw a parse exception. It probably does not support international and special characters in column names. You could try to escape the column names. Quick Google search reveals that HSQL uses double quotes for escaping identifiers: `"N°Ins"`. Does that work for you? – tiguchi Sep 17 '19 at 17:02
  • @tiguchi By adding the double quotes i no longer get the error but the query returns a null object – Mohammed Amine Sep 17 '19 at 17:16
  • Can you update your question with the Java code that creates and executes that query? – tiguchi Sep 17 '19 at 17:18
  • @tiguchi i hope this helps – Mohammed Amine Sep 17 '19 at 17:42
  • 1
    In your sample code the FROM clause is repeated (`... FROM Resultats_UE from Resultats_UE ...`). That is not valid syntax. – Gord Thompson Sep 18 '19 at 00:39
  • Please remember to close database connections in actual code. – M. Prokhorov Sep 20 '19 at 14:17

0 Answers0