当我尝试插入数据库中的数据时遇到问题。打开活动时,连接正常,SELECT正常,我收到数据并在屏幕上显示数据,这不是问题。
我确信连接没有接近,因为我没有编程,但我不知道为什么我不能插入数据库中的数据。
在屏幕上没有错误,有警告,我将在下面复制。有人为什么我不允许在同一个数据库的表中插入数据?
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://XXX.XXX.X.X:3306/BBDD,user,password);
Statement st = conn.createStatement();
rs = st.executeQuery(ConsultSQL);
INSERT CODE
Statement statement = conn.createStatement();
statement.executeUpdate("INSERT INTO data(name, number) VALUES ('" + "hi" + "', " + 3 + ")");
错误/警告:
01-30 04:21:02.739:W / System.err(2232):com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障 01-30 04:21:02.739:W / System.err(2232):从服务器成功收到的最后一个数据包是10.447毫秒前。成功发送到服务器的最后一个数据包是0毫秒前。 01-30 04:21:02.739:W / System.err(2232):at java.lang.reflect.Constructor.constructNative(Native Method) 01-30 04:21:02.739:W / System.err(2232):at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 01-30 04:21:02.739:W / System.err(2232):at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 01-30 04:21:02.739:W / System.err(2232):at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) 01-30 04:21:02.739:W / System.err(2232):at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4165) 01-30 04:21:02.739:W / System.err(2232):at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617) 01-30 04:21:02.739:W / System.err(2232):at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778) 01-30 04:21:02.749:W / System.err(2232):at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819) 01-30 04:21:02.749:W / System.err(2232):at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811) 01-30 04:21:02.749:W / System.err(2232):at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725) 01-30 04:21:02.749:D / audio_hw_primary(86):start_output_stream:card:0,port:0,rate:44100 01-30 04:21:02.749:W / System.err(2232):at com.android.internal.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:166) 01-30 04:21:02.759:W / System.err(2232):在android.os.Handler.dispatchMessage(Handler.java:99) 01-30 04:21:02.759:W / System.err(2232):在android.os.Looper.loop(Looper.java:137) 01-30 04:21:02.759:W / System.err(2232):在android.app.ActivityThread.main(ActivityThread.java:4424) 01-30 04:21:02.759:W / System.err(2232):at java.lang.reflect.Method.invokeNative(Native Method) 01-30 04:21:02.759:W / System.err(2232):at java.lang.reflect.Method.invoke(Method.java:511) 01-30 04:21:02.769:W / System.err(2232):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) 01-30 04:21:02.769:W / System.err(2232):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-30 04:21:02.769:W / System.err(2232):at dalvik.system.NativeStart.main(Native Method) 01-30 04:21:02.769:W / System.err(2232):引起:android.os.NetworkOnMainThreadException 01-30 04:21:02.769:W / System.err(2232):在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 01-30 04:21:02.769:W / System.err(2232):at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:163) 01-30 04:21:02.769:W / System.err(2232):at libcore.io.IoBridge.recvfrom(IoBridge.java:503) 01-30 04:21:02.769:W / System.err(2232):at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) 01-30 04:21:02.769:W / System.err(2232):at java.net.PlainSocketImpl.access $ 000(PlainSocketImpl.java:46) 01-30 04:21:02.769:W / System.err(2232):at java.net.PlainSocketImpl $ PlainSocketInputStream.read(PlainSocketImpl.java:240) 01-30 04:21:02.769:W / System.err(2232):at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114) 01-30 04:21:02.769:W / System.err(2232):at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161) 01-30 04:21:02.779:W / System.err(2232):at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189) 01-30 04:21:02.779:W / System.err(2232):at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3163) 01-30 04:21:02.779:W / System.err(2232):at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3620) 01-30 04:21:02.779:W / System.err(2232):at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3609) 01-30 04:21:02.779:W / System.err(2232):at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4160) 01-30 04:21:02.779:W / System.err(2232):... 16 more