这是我的代码
String url = "jdbc:mysql://sql210.lockernerd.co.uk:3306/";
String dbName = "lnw_18975270_test";
String driver = "com.mysql.jdbc.Driver";
String userName = "username";
String password = "pass";
username = txtUsername.getText().toString();
password1 = txtPassword.getText().toString();
try {
Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url + dbName, userName, password);
String sql = "insert into test_table(id,name)values('" + username + "','" + password1 + "')";
statement = connection.createStatement();
statement.executeUpdate(sql);
当我运行我的项目时,我收到以下错误:
java.net.ConnectException:连接超时:连接 at java.net.DualStackPlainSocketImpl.connect0(Native Method) 在java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) 在java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at 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) 在java.net.Socket.connect(Socket.java:538) 在java.net.Socket。(Socket.java:434) 在java.net.Socket。(Socket.java:244) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256) 在com.mysql.jdbc.MysqlIO。(MysqlIO.java:271) 在com.mysql.jdbc.Connection.createNewIO(Connection.java:2771) 在com.mysql.jdbc.Connection。(Connection.java:1555) 在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 在java.sql.DriverManager.getConnection(DriverManager.java:664) 在java.sql.DriverManager.getConnection(DriverManager.java:247) at Myadmintest.actionPerformed(Myadmintest.java:118) 在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2346) 在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) at java.awt.Component.processMouseEvent(Component.java:6525) 在javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access $ 500(EventQueue.java:97) at java.awt.EventQueue $ 3.run(EventQueue.java:709) at java.awt.EventQueue $ 3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue $ 4.run(EventQueue.java:731) at java.awt.EventQueue $ 4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
**结束了例外**
发送到服务器的最后一个数据包是0毫秒前。 在com.mysql.jdbc.Connection.createNewIO(Connection.java:2847) 在com.mysql.jdbc.Connection。(Connection.java:1555) 在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 在java.sql.DriverManager.getConnection(DriverManager.java:664) 在java.sql.DriverManager.getConnection(DriverManager.java:247) at Myadmintest.actionPerformed(Myadmintest.java:118) 在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2346) 在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) at java.awt.Component.processMouseEvent(Component.java:6525) 在javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access $ 500(EventQueue.java:97) at java.awt.EventQueue $ 3.run(EventQueue.java:709) at java.awt.EventQueue $ 3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue $ 4.run(EventQueue.java:731) at java.awt.EventQueue $ 4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)