Integrate MySQL with Java
This quickstart guide will help you to integrate your Java application with MySQL service on App42 PaaS.
Kontena – Kontena is a lightweight container that will run your apps and services in an isolated and secured manner. You can specify the power of the Kontena while setting up infra or creating services. One Kontena power specifies to 256 MB Memory and 128 MHz CPU.
Service – Services in the App42 PaaS are add-on components which are needed in an App. App42 PaaS supports multiple services like SQL databases, NoSQL databases and more.
Once you have setup the Java environment and created the MySQL service, You need to configure the MySQL credentials in your created Java application.
String host = "service_vm_ip"; String username = "username"; String password = "password"; String dbName = "database_name"; int port = service_port; // eg, 23453 // Using Spring-Jdbc Template DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?autoReconnect=true"); dataSource.setUsername(username); dataSource.setPassword(password); // Using Simple Jdbc Class.forName("com.mysql.jdbc.Driver"); Connection conn = null; conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + dbName,username, password); conn.close();
You can also use our Sample Apps and extend it to suit your needs. Here is the link to Java-MySQL Sample App
$ app42 update Enter App Name: javademo 1: Binary 2: Source Choose Upload Type [Binary]: 2 Updating Application... OK Operation is in progress, Please wait...- App deployed successfully.