Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection string for MySQL with multiple connection parameters?

Tags:

java

mysql

jdbc

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?

like image 914
N00b Pr0grammer Avatar asked Jul 26 '16 07:07

N00b Pr0grammer


People also ask

Can MySQL handle multiple connections?

By default 151 is the maximum permitted number of simultaneous client connections in MySQL 5.5. If you reach the limit of max_connections you will get the “Too many connections” error when you to try to connect to your MySQL server. This means all available connections are in use by other clients.

How do I create a connection string in MySQL?

Driver={mySQL};Server=myServerAddress;Port=3306;Option=131072;Stmt=;Database=myDataBase;User=myUsername;Password=myPassword; The driver defaults to port value 3306, if not specified in the connection string, as 3306 is the default port for MySQL.

Which are the 2 types of connection in MySQL?

Connect and Disconnect. Connections correspond to Sessions in SQL standard terminology. A client connects to the MySQL Server and stays connected until it does a disconnect.


2 Answers

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.

like image 192
Arthur Noseda Avatar answered Sep 27 '22 16:09

Arthur Noseda


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
like image 36
TTCC Avatar answered Sep 27 '22 18:09

TTCC