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?

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46

2 Answers2

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.

Arthur Noseda
  • 2,534
  • 19
  • 28
11

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
TTCC
  • 935
  • 5
  • 12
  • 2
    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. – user207421 Jul 26 '16 at 07:54
  • 1
    Also `jdbc:MySql:` is not the prefix of the MySQL driver, that is `jdbc:mysql:` – Mark Rotteveel Jul 26 '16 at 08:00
  • @MarkRotteveel jdbc:mysql: can be written in uppercase. it doesn't matter – TTCC Jul 26 '16 at 08:15
  • @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. – TTCC Jul 26 '16 at 08:18