13

In reference to this question, I'm trying to frame the connection string to connect to MySQL database with the following connection parameters, but I'm unable to get it right.

I've referred the documentation that the post is referring to, but I'm unable to resolve even after following the instructions. Can anybody help me in this regard?

Connection Parameters that are being used:

  • useOldAliasMetadataBehavior=true
  • useUnicode=true
  • characterEncoding=UTF-8

Normal connection string: jdbc:mysql://localhost:3307/databaseName

Adding these connection parameters and their corresponding values, how would the connection string be?

1
  • Usecase that I work, adds or drops the connection parameters - Hence I have to change the connection string based on the need! Commented Jul 26, 2016 at 8:09

2 Answers 2

15

According to the reference documentation, it would be:

jdbc:mysql://localhost:3307/databaseName?useOldAliasMetadataBehavior=true&unicode=true&characterEncoding=UTF-8

However, the standard port is 3306 not 3307 like in your question.

Sign up to request clarification or add additional context in comments.

3 Comments

You've got a valid point!, whereas I have two versions of MySQL installed, hence used 2 ports for these!
Just thought it worth mentioning.
Thanks for the info @Arthur Noseda, your comment definitely helps others! Cheers!
13

Just stitch parameters like a url, eg:

jdbc:MySql://localhost:3307/databaseName?characterEncoding=UTF-8&useUnicode=true&useOldAliasMetadataBehavior=true

If your connection string is being held in an XML or properties document, you need to encode & as &, like this:

jdbc:MySql://localhost:3307/databaseName?characterEncoding=UTF-8&useUnicode=true&useOldAliasMetadataBehavior=true

4 Comments

You need to encode this if the connection string is being held in an XML document. Not otherwise. There is nothing about XML in the question.
Also jdbc:MySql: is not the prefix of the MySQL driver, that is jdbc:mysql:
@MarkRotteveel jdbc:mysql: can be written in uppercase. it doesn't matter
@EJP Yes, you're right. But in my work, I always adhere to do that even the connection string is not being held in an XML or properties document, which is still not wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.