gjw80
gjw80

Reputation: 1078

Parentheses in java .properties files?

I am trying to pass a sql query into a java class via a bash shell script, the script gets the query from an external EnvFile.properties. The query in the properties file looks like:

DDAQUERY1=SELECT COUNT(1), marketsectordescription FROM PRODUCT GROUP BY marketsectordescription ORDER BY marketsectordescription

The query fails with this error:

java.sql.SQLSyntaxErrorException: ORA-00936: missing expression

The value being passed into the script looks like this (as seen in console output window in Jenkins):

SELECT 'COUNT(1),' marketsectordescription FROM PRODUCT GROUP BY marketsectordescription ORDER BY marketsectordescription

It definitely seems the parentheses are creating some kind of problem as single quotes (') appear near statements with parentheses in them. Is this in fact what is going on? What can be done to remedy the problem?

The env variables are injected into the build with the following Jenkins plug-in: https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

EDIT:

It appears it's not the parentheses, it's the spaces. Here's what I'm getting passed in from prop file > bash script args:

ddaquery1=SELECT COUNT, marketsectordescription FROM PRODUCT GROUP BY marketsectordescription ORDER BY marketsectordescription

ddaquery2=select count(distinct(smci)) from issuer

Here's whats getting into the java app:

ddaquery1: SELECT ddaquery2 : COUNT,

The spaces are delmiting the string and making each word after a whitespace a seperate arg[]. Does anyone know how I can fix this?

Thank you

Upvotes: 2

Views: 1030

Answers (2)

Smit
Smit

Reputation: 4715

Your query seems fine to me. Considering not an typo, the reason its failing because of , you have after COUNT(1) throwing SQLSyntaxErrorException.

DDAQUERY1 = SELECT COUNT(1),  marketsectordescription FROM PRODUCT 
                           ^   GROUP BY marketsectordescription 
                               ORDER BY marketsectordescription

Upvotes: 2

gjw80
gjw80

Reputation: 1078

The solution involved the fact the argument being passed in the bash script wasn't quoted, therefore passing every word after a whitespace as a new argument and giving the wrong strings to the query vars in the java app.

Upvotes: 1

Related Questions