I got a problem when I execute some sql queries using UCanAccess 3.0.7.
Here is my code :
publicConnectiongetConnection(){ConnectiondbCon=null;try{Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");dbCon=DriverManager.getConnection("jdbc:ucanaccess://D:/eclipse/eclipse-jee-neon-1-win32-x86_64/workspace/Lending-Hotline/web/Hotline.accdb","","");}catch(ClassNotFoundExceptione){Trace.logStackTrace(e);}catch(SQLExceptione){Trace.logStackTrace(e);}finally{}returndbCon;}publicsynchronizedDataListexecuteQueryCombo(StringaQuery,StringaScope,StringaRefQuery,StringaIPaddress)throwsSQLException{DataListdataList=null;DataHashtabledataHashtable;DataItemdataItem;try{stmt=getConnection().createStatement();System.out.println("query = "+aQuery);rs=stmt.executeQuery(aQuery);/* I put my result in a dataList using some parameters (aScope, aRefQuery, aIPaddress) */.../* The following methods just do Object.close() if Object != null */closeResultSet();closeStatement();closeConnection();}catch(SQLExceptione){Trace.logMessage(aQuery);Trace.logStackTrace(e);closeResultSet();closeStatement();closeConnection();throwe;}returndataList;}
And I want to execute this query :
SELECT IdModule AS ITEM_ID, NomModule AS ITEM_VALUE, ModuleLivrable FROM Module;
The query is executed, but there is a problem : the alias ITEM_ID and ITEM_VALUE are ignored and I have, for example, this result : [IdModule = 1;NomModule = Engine;ModuleLivrable = TRUE;]
instead of : [ITEM_ID = 1;ITEM_VALUE = Engine;ModuleLivrable = TRUE;]
and it's a problem for my next treatment.
I search for a solution by my own and I found my alias are not ignored if the expression before AS is composed and isn't just a column name.
There is an example :
SELECT '' & IdModule AS ITEM_ID, '' & NomModule AS ITEM_VALUE, ModuleLivrable FROM Module;
Indeed, I'm using ResultSetMetaData#getColumnName.
Change to ResultSetMetaData#getColumnLabel seems to work well. It's much better than my ugly hack !
Thanks for the solution ! ;)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
I got a problem when I execute some sql queries using UCanAccess 3.0.7.
Here is my code :
And I want to execute this query :
The query is executed, but there is a problem : the alias
ITEM_ID
andITEM_VALUE
are ignored and I have, for example, this result :[IdModule = 1;NomModule = Engine;ModuleLivrable = TRUE;]
instead of :
[ITEM_ID = 1;ITEM_VALUE = Engine;ModuleLivrable = TRUE;]
and it's a problem for my next treatment.
I search for a solution by my own and I found my alias are not ignored if the expression before AS is composed and isn't just a column name.
There is an example :
return :
[ITEM_ID = 1;ITEM_VALUE = Engine;ModuleLivrable = TRUE;]
If anyone can help me to found a better solution, it would be great !
I notice I use :
- Java 6u45
- MS Access 2013 (.mdb & .accdb)
- UCanAccess 3.0.7
Thanks !
PS : English is not my mothertongue, so sorry if there are mistakes.
If you are using
ResultSetMetaData#getColumnName
then try usingResultSetMetaData#getColumnLabel
instead.Indeed, I'm using
ResultSetMetaData#getColumnName
.Change to
ResultSetMetaData#getColumnLabel
seems to work well. It's much better than my ugly hack !Thanks for the solution ! ;)