Question

I have a teradata database name that contains a dash character -.

Searched the web but in vain. Does somebody know how can you escape the special characters in jdbc connection string? The string looks as follows:

jdbc:teradata://HostName/DATABASE=Database-Name

When I create a connection with this url I get syntax error. Also tried to put database parameter in single or double quotes, and to surround the special charachers with { }.

Thanks for help!

Was it helpful?

Solution 2

Answering my own question:

My problem was that I didn't realise that my database name had some trailing whitespaces in the end.

TeraDriver uses single quotes to escape spaces and commas. This means that the database name should be in single quotes. If there are no single quotes, spaces and commas are considered to be the end of parameter value. If there are single quotes in database name, they should be presented as two single quote characters.

'Database-Name   '

Whatever is within single quotes will be used with sql query: "database Database-Name". To escape '-' we need double quotes. So both single and double quotes in correct order should be used:

"jdbc:teradata://HostName/DATABASE='\"Database-Name\"'"

OTHER TIPS

Finally found the answer here: https://jira.talendforge.org/browse/TDI-18863. The correct way is to enclose both parameter name and value in single quotes:

jdbc:teradata://HostName/'DATABASE=Database-Name'

Update: No, this does not work, see comment below.

Have you tried a \ character which is supposed to be an escape character in Java?

jdbc:teradata://HostName/DATABASE=Database\-Name
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top