gpt4 book ai didi

java - 尝试连接到 mysql 数据库,出现异常“必须在 : 之后指定端口号”

转载 作者:行者123 更新时间:2023-11-29 23:29:08 26 4
gpt4 key购买 nike

我正在尝试从 java 连接到我网站上的 MySQL 数据库。

目前我收到一个异常,上面写着

Must specify port number after:”

我谷歌堆栈溢出,发现默认的MySQL端口是3306。但我找不到任何有关如何将其添加到我的网址的信息,现在看起来像

jdbc:mysql://http://www.findmeontheweb.biz/database name"+
“user=findmeon_bitcoin&password=password

代码:

  try {

// this will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
Connection connect = DriverManager.getConnection("jdbc:mysql://http: //www.findmeontheweb.biz//findmeon_bitcoin//"+ "user=findmeon_bitcoin&password=oreo8157");


} catch (Exception e) {
System.out.println("Exception...." );
}

最佳答案

1)希望代码中的空格只是复制/粘贴错误

2)需要删除mysql uri中的http

Connection connect = DriverManager.getConnection("jdbc:mysql://http:                  //www.findmeontheweb.biz//findmeon_bitcoin//"+ "user=findmeon_bitcoin&password=oreo8157");

将会

Connection connect = DriverManager.getConnection("jdbc:mysql://findmeontheweb.biz/findmeon_bitcoin/"+ "user=findmeon_bitcoin&password=oreo8157");

如果您在自定义端口上运行它,您可以通过以下方式指定端口

Connection connect = DriverManager.getConnection("jdbc:mysql://findmeontheweb.biz:3306/findmeon_bitcoin/"+ "user=findmeon_bitcoin&password=oreo8157");

将 3306 替换为您的自定义端口。

另外,我希望这不是您的真实用户名和密码!

关于java - 尝试连接到 mysql 数据库,出现异常“必须在 : 之后指定端口号”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com