2015-04-22 2 views
0

я создал учетную запись с базой данных на этом сайте: byethostНе удается подключиться Java к удаленному серверу базы данных Mysql

и я пытаюсь подключиться к нему с кодом, который работает, когда я пытаюсь подключиться к локальной базе данных на компьютере ,

Main.dataSource.setServerName("sql201.byethost33.com"); 
    Main.dataSource.setDatabaseName("b33_16132071_pizza_service"); 
    Main.dataSource.setUser("myuser"); 
    Main.dataSource.setPassword("mypassword"); 

    try(Connection connection = Main.dataSource.getConnection()){ 
     labStatus.setText("Connection to " + databaseName + " succeed"); 
     labStatus.setStyle("-fx-text-fill: green"); 

     showLoginButtons(); 
    }catch(Exception ex){ 
     labStatus.setText("Connection to " + databaseName + " failed"); 
     labStatus.setStyle("-fx-text-fill: red"); 

     ExceptionDialog exceptionDialog = new ExceptionDialog("Couldn't reach the connection", ex); 
     exceptionDialog.show(); 
    } 

Я получаю эту ошибку:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 
    at sun.reflect.GeneratedConstructorAccessor9.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038) 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338) 
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237) 
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270) 
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069) 
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794) 
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) 
    at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) 
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399) 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325) 
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:422) 
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:134) 
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:105) 
    at controller.MainWindowController.menuItemTestConnectionAction(MainWindowController.java:60) 
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at sun.reflect.misc.Trampoline.invoke(Unknown Source) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at sun.reflect.misc.MethodUtil.invoke(Unknown Source) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
    at javafx.event.Event.fireEvent(Unknown Source) 
    at javafx.scene.control.MenuItem.fire(Unknown Source) 
    at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(Unknown Source) 
    at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$341(Unknown Source) 
    at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$$Lambda$348/1546169402.handle(Unknown Source) 
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
    at javafx.event.Event.fireEvent(Unknown Source) 
    at javafx.scene.Scene$MouseHandler.process(Unknown Source) 
    at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source) 
    at javafx.scene.Scene.impl_processMouseEvent(Unknown Source) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$316/1708139015.get(Unknown Source) 
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source) 
    at com.sun.glass.ui.View.handleMouseEvent(Unknown Source) 
    at com.sun.glass.ui.View.notifyMouse(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.net.ConnectException: Connection timed out: connect 
    at java.net.DualStackPlainSocketImpl.connect0(Native Method) 
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) 
    at java.net.PlainSocketImpl.connect(Unknown Source) 
    at java.net.SocksSocketImpl.connect(Unknown Source) 
    at java.net.Socket.connect(Unknown Source) 
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213) 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297) 
    ... 70 more 

Это второй раз, когда я пытаюсь подключиться к удаленной базе данных. Первый раз, когда я использовал этот сайт db4free

и я просто использовал данные, как это:

server: www.db4free.net 
database: mydatabase 
username: username 
password: mypassword 

Я мог соединить с успешно же Java код, который я написал выше ...

Я вижу вещи разные на этих двух сайтах, поэтому я не знаю, что я делаю неправильно.

Возможно, мне нужно установить какой-либо порт или другую вещь в объект dataSource? Может быть, это будет что-то объяснить: это то, что я вижу в PhpMyAdmin из db4free где я могу подключиться к базе данных без проблем:

Database server 

Server: 127.0.0.1 via TCP/IP 
Server type: MySQL 
Server version: 5.6.24 - MySQL Community Server (GPL) 
Protocol version: 10 
User: [email protected] 
Server charset: UTF-8 Unicode (utf8) 

и это то, что я вижу в PhpMyAdmin OT byethost где я не могу подключить

Database server 

Server: sql201.byethost33.com via TCP/IP 
Software: Percona Server 
Software version: 5.6.22-71.0 - Percona Server (GPL), Release 71.0, Revision 726 
Protocol version: 10 
User: [email protected] 
Server charset: UTF-8 Unicode (utf8) 
+1

Это явно проблема с подключением. Убедитесь, что вы можете подключиться к этому серверу: sql201.byethost33.com и базе данных с вашими учетными данными и что нет третьего агента, который блокирует связь (например, межсетевой экран). –

+0

@LuiggiMendoza Вы имеете в виду подключение к phpMyAdmin? или каким-то другим способом? см. редактирование. – Tomasz

+0

Как проверить, что блокирует соединение? – Tomasz

ответ

0

Я думаю, я нашел ответ на панели управления сайта ...

enter image description here

Смежные вопросы