2014-11-02 52 views
0

我试图连接到我的网站上的MySQL数据库从Java。试图连接到一个mysql数据库,得到异常说,必须指定后的端口号:

目前我得到一个例外,说

必须指定端口号后:”

我谷歌堆栈溢出,发现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...."); 
    } 
+2

为什么JDBC URL中有一大堆空格?另外,这是否是您正确的MySQL网址?而你的用户名和密码? – 2014-11-02 15:44:32

+0

删除该空间... – SMA 2014-11-02 15:45:49

+0

我现在拥有您的数据库凭据。我不需要购买一个.. :) – NewUser 2014-11-02 15:45:56

回答

0

1)希望在你的代码空间只有一个复制/粘贴错误这里

2)您需要删除HTTP在mysql URI

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替换为您的自定义端口。

另外我希望这不是你真正的用户名和密码!

相关问题