Created
November 15, 2024 09:18
-
-
Save yoku0825/c9660da7556ea744b5e666f0d07e90e3 to your computer and use it in GitHub Desktop.
Public Key Retrieval is not allowed のテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class MySQLConnectionExample { | |
// Define JDBC URL (database name, host, and port can be modified as needed) | |
private static final String URL_format = "jdbc:mysql://127.0.0.1:64080/d1?useSSL=%s&allowPublicKeyRetrieval=%s"; | |
public static void main(String[] args) { | |
// Ensure that both username and password are provided as arguments | |
if (args.length < 4) { | |
System.out.println("Usage: java MySQLConnectionExample <username> <password> <useSSL> <allowPublicKeyRetrieval>"); | |
return; | |
} | |
String username = args[0]; | |
String password = args[1]; | |
String usessl = args[2]; | |
String publickey = args[3]; | |
String URL = String.format(URL_format, usessl, publickey); | |
Connection conn = null; | |
try { | |
// Connect to MySQL using provided username and password | |
conn = DriverManager.getConnection(URL, username, password); | |
System.out.println("Connected to the database successfully!"); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
if (conn != null) conn.close(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment