Cannot connect java to remote Mysql database server -


i created account database on site: byethost

and i'm trying connect code works when try connect local database on computer.

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 " + databasename + " succeed");         labstatus.setstyle("-fx-text-fill: green");          showloginbuttons();     }catch(exception ex){         labstatus.settext("connection " + databasename + " failed");         labstatus.setstyle("-fx-text-fill: red");          exceptiondialog exceptiondialog = new exceptiondialog("couldn't reach connection", ex);         exceptiondialog.show();     } 

i error:

com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure  last packet sent server 0 milliseconds ago. driver has not received packets server.     @ sun.reflect.generatedconstructoraccessor9.newinstance(unknown source)     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source)     @ java.lang.reflect.constructor.newinstance(unknown source)     @ com.mysql.jdbc.util.handlenewinstance(util.java:389)     @ com.mysql.jdbc.sqlerror.createcommunicationsexception(sqlerror.java:1038)     @ com.mysql.jdbc.mysqlio.<init>(mysqlio.java:338)     @ com.mysql.jdbc.connectionimpl.coreconnect(connectionimpl.java:2237)     @ com.mysql.jdbc.connectionimpl.connectonetryonly(connectionimpl.java:2270)     @ com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2069)     @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:794)     @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:44)     @ sun.reflect.generatedconstructoraccessor6.newinstance(unknown source)     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source)     @ java.lang.reflect.constructor.newinstance(unknown source)     @ com.mysql.jdbc.util.handlenewinstance(util.java:389)     @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:399)     @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:325)     @ com.mysql.jdbc.jdbc2.optional.mysqldatasource.getconnection(mysqldatasource.java:422)     @ com.mysql.jdbc.jdbc2.optional.mysqldatasource.getconnection(mysqldatasource.java:134)     @ com.mysql.jdbc.jdbc2.optional.mysqldatasource.getconnection(mysqldatasource.java:105)     @ controller.mainwindowcontroller.menuitemtestconnectionaction(mainwindowcontroller.java:60)     @ sun.reflect.generatedmethodaccessor11.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ sun.reflect.misc.trampoline.invoke(unknown source)     @ sun.reflect.generatedmethodaccessor1.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ sun.reflect.misc.methodutil.invoke(unknown source)     @ javafx.fxml.fxmlloader$methodhandler.invoke(unknown source)     @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(unknown source)     @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source)     @ com.sun.javafx.event.eventutil.fireeventimpl(unknown source)     @ com.sun.javafx.event.eventutil.fireevent(unknown source)     @ javafx.event.event.fireevent(unknown source)     @ javafx.scene.control.menuitem.fire(unknown source)     @ com.sun.javafx.scene.control.skin.contextmenucontent$menuitemcontainer.doselect(unknown source)     @ com.sun.javafx.scene.control.skin.contextmenucontent$menuitemcontainer.lambda$createchildren$341(unknown source)     @ com.sun.javafx.scene.control.skin.contextmenucontent$menuitemcontainer$$lambda$348/1546169402.handle(unknown source)     @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(unknown source)     @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(unknown source)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source)     @ com.sun.javafx.event.eventutil.fireeventimpl(unknown source)     @ com.sun.javafx.event.eventutil.fireevent(unknown source)     @ javafx.event.event.fireevent(unknown source)     @ javafx.scene.scene$mousehandler.process(unknown source)     @ javafx.scene.scene$mousehandler.access$1500(unknown source)     @ javafx.scene.scene.impl_processmouseevent(unknown source)     @ javafx.scene.scene$scenepeerlistener.mouseevent(unknown source)     @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(unknown source)     @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$350(unknown source)     @ com.sun.javafx.tk.quantum.glassvieweventhandler$$lambda$316/1708139015.get(unknown source)     @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(unknown source)     @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(unknown source)     @ com.sun.glass.ui.view.handlemouseevent(unknown source)     @ com.sun.glass.ui.view.notifymouse(unknown source)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$145(unknown source)     @ com.sun.glass.ui.win.winapplication$$lambda$36/2117255219.run(unknown source)     @ java.lang.thread.run(unknown source) caused by: java.net.connectexception: connection timed out: connect     @ java.net.dualstackplainsocketimpl.connect0(native method)     @ java.net.dualstackplainsocketimpl.socketconnect(unknown source)     @ java.net.abstractplainsocketimpl.doconnect(unknown source)     @ java.net.abstractplainsocketimpl.connecttoaddress(unknown source)     @ java.net.abstractplainsocketimpl.connect(unknown source)     @ java.net.plainsocketimpl.connect(unknown source)     @ java.net.sockssocketimpl.connect(unknown source)     @ java.net.socket.connect(unknown source)     @ com.mysql.jdbc.standardsocketfactory.connect(standardsocketfactory.java:213)     @ com.mysql.jdbc.mysqlio.<init>(mysqlio.java:297)     ... 70 more 

it's second time i'm trying connect remote database. first time used site db4free

and used data this:

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

i connect succesfully same java code posted above...

i see things different on these 2 site dont know i'm doing wrong.

maybe should set port or other thing datasource object? maybe explain something: see in phpmyadmin of db4free can connect database no problem:

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: pizzaadm4@localhost server charset: utf-8 unicode (utf8) 

and see in phpmyadmin ot byethost cant connect

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: b33_1613071@192.168.0.6 server charset: utf-8 unicode (utf8) 

i think found answer in control panel of site...

enter image description here


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -