[英]Trying to connect to a mysql database, getting exception saying Must specify port number after:
I'm trying to connect to a MySQL database on my website from java. 我正在尝试从Java连接到我网站上的MySQL数据库。
Currently I'm getting a exception that says 目前,我遇到一个例外,说
Must specify port number after:” 必须在以下位置指定端口号:”
I Google stack overflow and found the default MySQL port is 3306. But I can't find any information about how I add it to my url, which now looks like 我Google堆栈溢出,发现默认的MySQL端口是3306。但是我找不到有关如何将其添加到url中的任何信息,现在看起来像
jdbc:mysql://http://www.findmeontheweb.biz/database name"+
“user=findmeon_bitcoin&password=password
code: 码:
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) Hope the space in your code was only a copy/paste error here 1)希望代码中的空间只是此处的复制/粘贴错误
2) You need to remove the http in the mysql uri 2)您需要删除mysql uri中的http
Connection connect = DriverManager.getConnection("jdbc:mysql://http: //www.findmeontheweb.biz//findmeon_bitcoin//"+ "user=findmeon_bitcoin&password=oreo8157");
will be 将会
Connection connect = DriverManager.getConnection("jdbc:mysql://findmeontheweb.biz/findmeon_bitcoin/"+ "user=findmeon_bitcoin&password=oreo8157");
And just in case you are running it on a custom port, you can specify port by 并且以防万一您在自定义端口上运行它,您可以通过以下方式指定端口
Connection connect = DriverManager.getConnection("jdbc:mysql://findmeontheweb.biz:3306/findmeon_bitcoin/"+ "user=findmeon_bitcoin&password=oreo8157");
replace 3306 with your custom port. 用您的自定义端口替换3306。
Also I hope that is not your real username and password! 我也希望这不是您的真实用户名和密码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.