Otra duda con java
Esta vez mi duda es realacionado con la base de datos, veras yo cree un base de datos en un hosting (para ser mas especificas en 000webhost)
Ahora mi incoveniente es saber como conectar este servidor con una aplicacion de java (de escritorio, normal y corriente)
Este es el codigo q puse en java, para intentarlos conectar, en el hosting ya esta hecha la base de datos, y tiene hecha una tabla con 3 campos, nick, verificador y score
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("a8112281_base");
dataSource.setPassword("prueba");
dataSource.setDatabaseName("a8112281_probando");
dataSource.setServerName("mysql2.000webhost.com");
System.out.println("Nombre-->"+nick);
System.out.println("Apellido-->"+verificador);
System.out.println("cedula-->"+score);
Connection conexion = (Connection) dataSource.getConnection();
Statement instruccion = (Statement) conexion.createStatement();
int executeUpdate = instruccion.executeUpdate("INSERT INTO scores(nick,verificador,score) VALUES('" + nick + "','" + verificador + "','" + score +"')");
Pero al intentar correr la aplicacion, con este codigo me arroja un poco de errores, estos
Run:
Nombre-->carlos
Apellido-->castillo
Cedula-->23
Mar 11, 2011 7:01:47 PM probando2. Probando3 jButton1ActionPerformed
SEVERE: null
com. Mysql. Jdbc. CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection timed out: connect
Stacktrace:
java.net.ConnectException: Connection timed out: connect
At java.net.PlainSocketImpl.socketConnect(Native Method)
At java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
At java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
At java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
At java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
At java.net.Socket.connect(Socket.java:529)
At java.net.Socket.connect(Socket.java:478)
At java.net.Socket.<init>(Socket.java:375)
At java.net.Socket.<init>(Socket.java:218)
At com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
At com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
At com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
At com.mysql.jdbc.Connection.<init>(Connection.java:1555)
At com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:425)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:140)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:110)
At probando2.comunicar.insertarEnBaseDatos(comunicar.java:78)
At probando2. Probando3. JButton1ActionPerformed(probando3.java:73)
At probando2. Probando3.access$000(probando3.java:24)
At probando2.probando3$1. ActionPerformed(probando3.java:47)
At javax. Swing. AbstractButton. FireActionPerformed(AbstractButton.java:1995)
At javax. Swing.AbstractButton$Handler. ActionPerformed(AbstractButton.java:2318)
At javax. Swing. DefaultButtonModel. FireActionPerformed(DefaultButtonModel.java:387)
At javax. Swing. DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
At javax. Swing. Plaf. Basic. BasicButtonListener. MouseReleased(BasicButtonListener.java:236)
At java. Awt. Component.processMouseEvent(Component.java:6267)
At javax. Swing. JComponent.processMouseEvent(JComponent.java:3267)
At java. Awt. Component.processEvent(Component.java:6032)
At java. Awt. Container.processEvent(Container.java:2041)
At java. Awt. Component.dispatchEventImpl(Component.java:4630)
At java. Awt. Container.dispatchEventImpl(Container.java:2099)
At java. Awt. Component.dispatchEvent(Component.java:4460)
At java. Awt. LightweightDispatcher.retargetMouseEvent(Container.java:4577)
At java. Awt. LightweightDispatcher.processMouseEvent(Container.java:4238)
At java. Awt. LightweightDispatcher.dispatchEvent(Container.java:4168)
At java. Awt. Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
At java. Awt. Component.dispatchEvent(Component.java:4460)
At java. Awt. EventQueue.dispatchEvent(EventQueue.java:599)
At java. Awt. EventDispatchThread. PumpOneEventForFilters(EventDispatchThread.java:269)
At java. Awt. EventDispatchThread. PumpEventsForFilter(EventDispatchThread.java:184)
At java. Awt. EventDispatchThread. PumpEventsForHierarchy(EventDispatchThread.java:174)
At java. Awt. EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
At java. Awt. EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
At java. Awt. EventDispatchThread.run(EventDispatchThread.java:122)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
At...
Ahora mi incoveniente es saber como conectar este servidor con una aplicacion de java (de escritorio, normal y corriente)
Este es el codigo q puse en java, para intentarlos conectar, en el hosting ya esta hecha la base de datos, y tiene hecha una tabla con 3 campos, nick, verificador y score
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("a8112281_base");
dataSource.setPassword("prueba");
dataSource.setDatabaseName("a8112281_probando");
dataSource.setServerName("mysql2.000webhost.com");
System.out.println("Nombre-->"+nick);
System.out.println("Apellido-->"+verificador);
System.out.println("cedula-->"+score);
Connection conexion = (Connection) dataSource.getConnection();
Statement instruccion = (Statement) conexion.createStatement();
int executeUpdate = instruccion.executeUpdate("INSERT INTO scores(nick,verificador,score) VALUES('" + nick + "','" + verificador + "','" + score +"')");
Pero al intentar correr la aplicacion, con este codigo me arroja un poco de errores, estos
Run:
Nombre-->carlos
Apellido-->castillo
Cedula-->23
Mar 11, 2011 7:01:47 PM probando2. Probando3 jButton1ActionPerformed
SEVERE: null
com. Mysql. Jdbc. CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection timed out: connect
Stacktrace:
java.net.ConnectException: Connection timed out: connect
At java.net.PlainSocketImpl.socketConnect(Native Method)
At java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
At java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
At java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
At java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
At java.net.Socket.connect(Socket.java:529)
At java.net.Socket.connect(Socket.java:478)
At java.net.Socket.<init>(Socket.java:375)
At java.net.Socket.<init>(Socket.java:218)
At com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
At com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
At com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
At com.mysql.jdbc.Connection.<init>(Connection.java:1555)
At com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:425)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:140)
At com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:110)
At probando2.comunicar.insertarEnBaseDatos(comunicar.java:78)
At probando2. Probando3. JButton1ActionPerformed(probando3.java:73)
At probando2. Probando3.access$000(probando3.java:24)
At probando2.probando3$1. ActionPerformed(probando3.java:47)
At javax. Swing. AbstractButton. FireActionPerformed(AbstractButton.java:1995)
At javax. Swing.AbstractButton$Handler. ActionPerformed(AbstractButton.java:2318)
At javax. Swing. DefaultButtonModel. FireActionPerformed(DefaultButtonModel.java:387)
At javax. Swing. DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
At javax. Swing. Plaf. Basic. BasicButtonListener. MouseReleased(BasicButtonListener.java:236)
At java. Awt. Component.processMouseEvent(Component.java:6267)
At javax. Swing. JComponent.processMouseEvent(JComponent.java:3267)
At java. Awt. Component.processEvent(Component.java:6032)
At java. Awt. Container.processEvent(Container.java:2041)
At java. Awt. Component.dispatchEventImpl(Component.java:4630)
At java. Awt. Container.dispatchEventImpl(Container.java:2099)
At java. Awt. Component.dispatchEvent(Component.java:4460)
At java. Awt. LightweightDispatcher.retargetMouseEvent(Container.java:4577)
At java. Awt. LightweightDispatcher.processMouseEvent(Container.java:4238)
At java. Awt. LightweightDispatcher.dispatchEvent(Container.java:4168)
At java. Awt. Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
At java. Awt. Component.dispatchEvent(Component.java:4460)
At java. Awt. EventQueue.dispatchEvent(EventQueue.java:599)
At java. Awt. EventDispatchThread. PumpOneEventForFilters(EventDispatchThread.java:269)
At java. Awt. EventDispatchThread. PumpEventsForFilter(EventDispatchThread.java:184)
At java. Awt. EventDispatchThread. PumpEventsForHierarchy(EventDispatchThread.java:174)
At java. Awt. EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
At java. Awt. EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
At java. Awt. EventDispatchThread.run(EventDispatchThread.java:122)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
At...
1 Respuesta
Respuesta de krlosnow
1