2024年06月01日 建站教程
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class ConnectToMySQL { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/mydatabase"; String username = "root"; String password = "password"; try { Connection connection = DriverManager.getConnection(url, username, password); System.out.println("数据链接成功!"); } catch (SQLException e) { System.out.println("数据库链接失败原因: " + e.getMessage()); } } }
本文链接:http://so.lmcjl.com/news/5753/