
您需要在 URL 中使用端口号 3306。语法如下 -
jdbc:mysql://localhost:3306
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnectionToJava {
public static void main(String[] args) {
String JDBCURL="jdbc:mysql://localhost:3306/sample?useSSL=false";
Connection con=null;
try {
con = DriverManager.getConnection(JDBCURL,"root","123456");
if(con!=null) {
System.out.println("MySQL connection is successful with port 3306.");
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}MySQL connection is successful with port 3306.
以上就是如何在JAVA中建立MySQL连接?在本地主机上要设置的端口号是多少?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号