[Template] MySQL connection with Java

For simple connection confirmation

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySQLPractice {

	public static void main(String[] args) {
		Connection con = null;
        try {
            //Connect to MySQL
            con = DriverManager.getConnection("jdbc:mysql://localhost:8880/database", "root", "pass");
            System.out.println("I was able to connect to MySQL.");
        } catch (SQLException e) {
            System.out.println("Could not connect to MySQL.");
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    System.out.println("Failed to close MySQL.");
                }
            }
        }
	}
}

Recommended Posts

[Template] MySQL connection with Java
[Docker] Connection with MySQL
Try DB connection with Java
Connect to MySQL 8 with Java
JDBC connection with MySQL 8.x * Notes *
MySql connection error
Hello world with Java template engine Thymeleaf
[Java] Connection with local DB (IntelliJ + SpringBoot)
[Java] .gitignore template
Create a simple bulletin board with Java + MySQL
Install java with Homebrew
JAVA DB connection method
Change seats with java
Install Java with Ansible
[Java] Connect to MySQL
Comfortable download with JAVA
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
Switch java with direnv
Download Java with Ansible
[Rails] Development with MySQL
Let's scrape with Java! !!
Build Java with Wercker
[MySQL + Java] Numbering procedure
Endian conversion with JAVA
HTTPS connection with Java to the self-signed certificate server
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Return partial template (partial) with helper
Streamline Java testing with Spock
Connect to DB with Java
Template Engine Pebble (Java) --Guide
Error when playing with java
Using Mapper with Java (Spring)
Check https connection in Java
Java study memo 2 with Progate
Getting Started with Java Basics
Seasonal display with Java switch
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1