on host computer have installed wamp , can connect using php example, or browser. client virtual machine linux , trying connect database on host add entries there.
here code:
connection conn = null; try { string url = "jdbc:mysql://192.168.1.236:8080/fps"; class.forname("com.mysql.jdbc.driver").newinstance(); conn = drivermanager.getconnection(url, "username", "password"); system.out.println("database connection established"); } catch (exception e) { e.printstacktrace(); } { if (conn != null) { try { conn.close(); system.out.println("database connection terminated"); } catch (exception e) {} } } i must mention i'm trying connect on local network, , setup wamp work on port 8080 (it can seen above). thing that, on virtual machine, can access database using browser.
the code above generates error:
com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure
the last packet sent server 0 milliseconds ago. driver has not received packets server. @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:526) @ com.mysql.jdbc.util.handlenewinstance(util.java:400) @ com.mysql.jdbc.sqlerror.createcommunicationsexception(sqlerror.java:1038) @ com.mysql.jdbc.mysqlio.readpacket(mysqlio.java:628) @ com.mysql.jdbc.mysqlio.dohandshake(mysqlio.java:1014) @ com.mysql.jdbc.connectionimpl.coreconnect(connectionimpl.java:2249) @ com.mysql.jdbc.connectionimpl.connectonetryonly(connectionimpl.java:2280) @ com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2079) @ com.mysql.jdbc.connectionimpl.(connectionimpl.java:794) @ com.mysql.jdbc.jdbc4connection.(jdbc4connection.java:44) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:526) @ com.mysql.jdbc.util.handlenewinstance(util.java:400) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:399) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:325) @ java.sql.drivermanager.getconnection(drivermanager.java:571) @ java.sql.drivermanager.getconnection(drivermanager.java:215) @ databaseconnection.main(databaseconnection.java:12) caused by: java.io.eofexception: can not read response server. expected read 4 bytes, read 0 bytes before connection unexpectedly lost. @ com.mysql.jdbc.mysqlio.readfully(mysqlio.java:2926) @ com.mysql.jdbc.mysqlio.readpacket(mysqlio.java:560) ... 16 more
i believe problem settings of mysql on client, in file /etc/mysql/my.cnf don't know how change them since didn't find example particular situation. thought fact changed port 8080, when mysql uses 3306, causing problems.
so, question is, how make work? thanks.
edit: want add port change (to 8080) made in conf file of apache on server. default 80. maybe shouldn't affect 3306 of mysql.
another thing that, on virtual machine, can access database using browser.
by mean can run web site lives on host browser on vm. thats not quite same thing connecting remote pc. in case code running i.e. php assume, running on host , connecting php mysql of on host.
by default root account, if thats using allowed connect if being run same pc mysql running on.
try creating new mysql user account, make sure new account allowed login mysql ip of vm.
for example:
create user 'florina'@'192.168.1.%' identified 'a-password'; grant privileges on your_database 'florina'@'192.168.1.%'; this should allow account florina connect mysql server address on subnet, wont matter if vm gets different ip addresses after each reboot.
it idea check firewall allowing remote connections port 8080! , 3306 if confused port change.
in fact are sure changed mysql listen on port 8080 or did change apache listen on port 8080. if changed apache entering url in browser :8080. this not mean mysql listening on port 8080 in case remove :8080
string url = "jdbc:mysql://192.168.1.236/fps";
Comments
Post a Comment