java - Connection to MySQL with JDBC -
i have been trying connect external mysql server location @ http://mysql10.000webhost.com using jdbc in eclipse, keep getting error. here code:
import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import com.mysql.jdbc.preparedstatement; //import com.mysql.jdbc.driver; public class main { public static void main(string[] args) throws sqlexception { try{ class.forname("com.mysql.jdbc.driver").newinstance(); connection conn=drivermanager.getconnection("jdbc:mysql://mysql10.000webhost.com/database","username","password"); java.sql.preparedstatement statement = conn.preparestatement("select * promoid"); resultset result=statement.executequery(); while(result.next()) { system.out.println(result.getstring(1)); } } catch (exception e) { e.printstacktrace(); } } }
here error getting:
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(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.sqlerror.createcommunicationsexception(sqlerror.java:1121) @ com.mysql.jdbc.mysqlio.<init>(mysqlio.java:355) @ com.mysql.jdbc.connectionimpl.coreconnect(connectionimpl.java:2479) @ com.mysql.jdbc.connectionimpl.connectonetryonly(connectionimpl.java:2516) @ com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2301) @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:834) @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:47) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:416) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:317) @ java.sql.drivermanager.getconnection(unknown source) @ java.sql.drivermanager.getconnection(unknown source) @ main.main(main.java:15) caused by: java.net.connectexception: connection timed out: connect @ java.net.plainsocketimpl.socketconnect(native method) @ java.net.plainsocketimpl.doconnect(unknown source) @ java.net.plainsocketimpl.connecttoaddress(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.<init>(unknown source) @ java.net.socket.<init>(unknown source) @ com.mysql.jdbc.standardsocketfactory.connect(standardsocketfactory.java:259) @ com.mysql.jdbc.mysqlio.<init>(mysqlio.java:305) ... 15 more
can jdbc not connect databases outside of localhost?
caused by: java.net.connectexception: connection timed out: connect.
have tried telnetting port 3306
(the mysql default) on host mysql10.000webhost.com
?
i bet blocking on firewall.
Comments
Post a Comment