通信链路失败发送到服务器最后的分组是1毫秒以前。 [英] Communications link failure Last packet sent to the server was 1 ms ago.

查看:1243
本文介绍了通信链路失败发送到服务器最后的分组是1毫秒以前。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到 mysql数据库但我失败并显示此错误

发送到服务器

 通讯链路故障最后一个数据包为1毫秒前

这是我的code?任何人都可以帮我请

 包android_programmers_guide.testconnection;
进口java.sql.Connection中;
进口java.sql.DriverManager中;进口android.os.Bundle;
进口android.app.Activity;
进口android.graphics.Color;
进口android.view.Menu;
进口android.widget.EditText;公共类TestConnection延伸活动{    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_test_connection);           康涅狄格州的连接= NULL;
           字符串URL =的jdbc:mysql的://127.0.0.1:3306 /测试;
           串驱动器=com.mysql.jdbc.Driver
           字符串username =根;
           字符串密码=根;
           尝试{
           的Class.forName(驱动程序).newInstance();
           康恩=的DriverManager.getConnection(URL,用户名,密码);
           EDITTEXT的EditText =(EditText上)findViewById(R.id.editText1);
           editText.setBackgroundColor(Color.GREEN);
           editText.setText(连接到数据库);           conn.close();           editText.setBackgroundColor(Color.BLUE);
           editText.setText(从数据库断开连接);
           }赶上(例外五){
           e.printStackTrace();
           }    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.activity_test_connection,菜单);
        返回true;
    }}


解决方案

此问题是因为你传递的网址是行不通的。

检查以下各项:


  1. 请确保您的本地主机MySQL正在运行

  2. 键入 \\ S 检查MySQL的状态。

  3. 检查端口号,并确保您使用的是同一个。

如果上述所有是正确的,也许你没有权限。

使用所有赠款*。* 来的密码标识,然后运行冲水的权限,然后替换 127.0.0.1 本地主机并尝试重新连接。

I tried to connect to mysql database but I failed and this error is shown

Communications link failure Last packet sent to the server was 1 ms ago

and this is my code ? anyone can help me please

package android_programmers_guide.testconnection;


import java.sql.Connection;
import java.sql.DriverManager;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.widget.EditText;

public class TestConnection extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_connection);



           Connection conn = null;
           String url = "jdbc:mysql://127.0.0.1:3306/test";
           String driver = "com.mysql.jdbc.Driver";
           String userName = "root"; 
           String password = "root";


           try {
           Class.forName(driver).newInstance();
           conn = DriverManager.getConnection(url,userName,password);


           EditText editText=(EditText) findViewById(R.id.editText1);


           editText.setBackgroundColor(Color.GREEN);
           editText.setText("Connected to the database");

           conn.close();

           editText.setBackgroundColor(Color.BLUE);
           editText.setText("Disconnected from database");


           } catch (Exception e) {
           e.printStackTrace();
           }



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_test_connection, menu);
        return true;
    }

}

解决方案

This problem is because the URL you are passing is not working.

Check the following things:

  1. Make sure that your localhost MySQL is running
  2. Check the status of MySQL by typing \s.
  3. Check the port number and make sure you are using the same one.

If all of the above is correct, maybe you don't have permissions.

Use grant all on *.* to identified by "password",then run flush privileges, and then replace 127.0.0.1 with localhost and try to reconnect.

这篇关于通信链路失败发送到服务器最后的分组是1毫秒以前。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆