java - Remote Database -
i tried creating app in java works remote database. apps works fine on local database. have included the port number well. scared may ip address using.
i thought myself there may hundreds if not thousands of pc's around world same ip mine... , how internet see 1 am, or stay secure it. sure don't give remote access ip of computer of home network, may wrong... don't know.
this function.
public void db() { try { class.forname("com.mysql.jdbc.driver"); connection mycon = drivermanager.getconnection("jdbc:mysql://ipofwebsite:3306/databasename", "username", "password"); system.out.println("connected"); mycon.close(); } catch (exception ex) { ex.printstacktrace(); } }
on remote db have added public ip address, still received error
"c:\program files\java\jdk1.8.0_25\bin\java" -didea.launcher.port=7532 "-didea.launcher.bin.path=c:\program files (x86)\jetbrains\intellij idea community edition 14.1.3\bin" -dfile.encoding=windows-1252 -classpath "c:\program files\java\jdk1.8.0_25\jre\lib\charsets.jar;c:\program files\java\jdk1.8.0_25\jre\lib\deploy.jar;c:\program files\java\jdk1.8.0_25\jre\lib\javaws.jar;c:\program files\java\jdk1.8.0_25\jre\lib\jce.jar;c:\program files\java\jdk1.8.0_25\jre\lib\jfr.jar;c:\program files\java\jdk1.8.0_25\jre\lib\jfxswt.jar;c:\program files\java\jdk1.8.0_25\jre\lib\jsse.jar;c:\program files\java\jdk1.8.0_25\jre\lib\management-agent.jar;c:\program files\java\jdk1.8.0_25\jre\lib\plugin.jar;c:\program files\java\jdk1.8.0_25\jre\lib\resources.jar;c:\program files\java\jdk1.8.0_25\jre\lib\rt.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\localedata.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\sunec.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;c:\program files\java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;h:\java dev\simple_java_db\out\production\simple_java_db;h:\java dev\simple_java_db\mysql-connector-java-5.1.35\mysql-connector-java-5.1.35\mysql-connector-java-5.1.35-bin.jar;c:\program files (x86)\jetbrains\intellij idea community edition 14.1.3\lib\idea_rt.jar" com.intellij.rt.execution.application.appmain main com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure 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:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:408) @ 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.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:408) @ com.mysql.jdbc.util.handlenewinstance(util.java:389) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:399) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:325) @ java.sql.drivermanager.getconnection(drivermanager.java:664) @ java.sql.drivermanager.getconnection(drivermanager.java:247) @ main.db(main.java:24) @ main.main(main.java:15) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140) caused by: java.net.connectexception: connection refused: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(dualstackplainsocketimpl.java:79) @ java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:345) @ java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:206) @ java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:188) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:172) @ java.net.sockssocketimpl.connect(sockssocketimpl.java:392) @ java.net.socket.connect(socket.java:589) @ com.mysql.jdbc.standardsocketfactory.connect(standardsocketfactory.java:213) @ com.mysql.jdbc.mysqlio.<init>(mysqlio.java:297) ... 21 more
any great. way did check firewall... should allow port receive , sent.
mysql default listen local interface (loopback). can reach local machine.
to change this, adapt mysql conf:
[mysqld] bind-address=your-server-ip
also, make sure skip-networking
configuration commented out or not present.
more details here.
Comments
Post a Comment