Java – How to i solve PostgreSQL JDBC org.postgresql.util.PSQLException Error:

javajdbcpostgresqlsql

I've got problem with PostgreSQL JDBC

I use postgresql-9 and Glassfish if i execute the query with pgAdmin I don't have any error but in my application i have this error:

SEVERE: org.postgresql.util.PSQLException: ERREUR: erreur de syntaxe sur ou près de « d »
Position : 293
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)

This is my java code

PreparedStatement st = con.prepareStatement("SELECT d.refdossier, d.status, d.date_validation, d.date_last_update,"
                        + "d.id_dossier,d.contrat_signe, d.etat_avancement,c.nom_pre_cont, c.num_piece_id,  c.date_piece_id,"
                        + "c.lieu_piece_id,  c.dat_nai_con, c.tel_con, fax_con,  c.email_con,g.libellegouvernoratar ,del.libelledelegationar"
                        + "FROM dossier d JOIN contact c on c.id_contact=d.id_dossier JOIN gouvernorat "
                        + " g on g.codegouvernorat=c.gouv JOIN delegation del on del.codedelegation=c.delegation"
                        + " WHERE d.id_dossier="+84);

res = st.executeQuery();

Best Answer

You are missing a space between del.libelledelegationar and FROM. This is causing the query to be parsed as:

SELECT ...., del.libelledelegationarFROM dossier d ....

In other words it sees a column del.libelledelegationarFROM with alias dossier and when the parser then sees d it trips, because it either expects a , or FROM, so it returns an error that there is a syntax error near d.

Related Topic