When you need to connect to a MySQL database this component will help you. There are two ways of getting a connection; a direct connection or through a pool. For more info about pools see the Connections Pool section of the help.
Using a direct connection means that you connect to the database server directly using an IP address and a port. This is the easiest way since there is no configuration needed and it only requires a few parameters. However for production code, we strongly recommend you to look at connection pooling.
A connection is direct when the
Connection pool option is not checked.
The first fields are self explanatory, enter the IP address or hostname in the
Server field, the port in
Port and type in the name of the database you want to use in the
User id and
Password are your login credentials.
Properties field allows you to specify any connection properties.
Direct connection example:
MySQLConnection mycon1 = new MySQLConnection("127.0.0.1", 3306, "mydb", "serobkle", "#$E%0xcGFzc3dvcmQ=", "");
The recommended way to use connections is to use a connection pool. When you have a pool setup you check the
Connection Pool option and select your pool from the helper icon. This will give you something like this:
MySQLConnection mycon1 = (MySQLConnection) PoolManager.instance().getIPool("myPool").getConnection();
If the list of pooled connection is empty you need to configure your pools in 360's administration tool. Please see the help section for Pool Connections.