Reading Time: 3 minutes

When developing a Mule Application the normal way to define an SQL statement is by declaring it directly in the connector, as shown in the following snippet.

Could not embed GitHub Gist 1302773: API rate limit exceeded for 34.66.93.163. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

However is possible that you’ll face a situation in which you have to use large and complex queries. For that scenario the previous approach is not adequate since you’ll end up with a configuration difficult to read. So the best thing to do is to externalize these queries in one or more files.

But here’s the catch, using the property placeholder files will not completely solve the problem since you’ll want to have this large queries formatted and indexed in order to make them readable for the human eye, and when using the property files you are limited to a “one-line” property.

So, in order to solve the problem what you can do is to create a separate configuration file in which you defined a Spring Bean of the class java.lang.String.

Could not embed GitHub Gist 1302776: API rate limit exceeded for 34.66.93.163. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

By doing so you will be able to format the query string at your convenience. Then all you have to do is to reference that bean from the JDBC connector definition using the value-ref key

Could not embed GitHub Gist 1302781: API rate limit exceeded for 34.66.93.163. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

And that’s it, by applying this simple steps you can have any number of large and complex SQL statements and at the same time have them easily readable and maintainable.

latest report
Learn why we are the Leaders in API management and iPaaS