## @ [Android studio pit connecting step is performed by substantially mysql jdbc encountered and "The last packet sent successfully to the server was 0 m

@ [Android studio mysql substantially connected by the step of pit and jdbc "The last packet sent successfully to the server was 0 milliseconds ago" encountered ha]

The first white hair blog ha ha, look at this record for three nights to me and my tragic experience of successful resolution extremely happy after the bug.
The first night, a little irritable, but can also feel a little bug to resolve it tomorrow.
The second night, do not worry, just a little bug, 20 Fenzhong tune okay. . . . . 1:00 until midnight, I began to hammer the wall, too hard! Garbage Garbage computer software! Really I want a cigarette, but I will not. Three o'clock, hammer wall! You can not hammer the computer! Off to sleep, I was stupid and I'm not gnaw.
The third night, I knew I was a genius, I have not solve the bug Well ha ha!
In fact, do not bother, but I am not a computer professional and white, plus even more irritable mood, so efficiency is very low, we patiently follow my next post will certainly be helpful!
Here enters the body. First, by default your android studio are configured Kazakhstan
first step: Import jar package, write code , please refer to this post:
link: https://blog.csdn.net/huangzhiyu2004/article/details/82622177
This post is my read countless posts on the white paste is the most appropriate test mysql connection after summed friends. Add that to create a new java file, paste it on a bunch of code, code mainactivity second stack stick inside. If you are importing a previous mysql8.0 jar package, String DRIVER = "com.mysql.jdbc.Driver", if you are importing a jar package after mysql8.0, String DRIVER = "com.mysql.cj.jdbc .Driver ",
Step two: modify the bug . This is what puzzled me for a long time garbage bug. Briefly given the information as follows:
The last packet sent successfully to the server was 0 milliseconds ago translate: that you send a package to the mysql server, it does not respond, that is, the connection fails.
This is my main line of code error: conn = DriverManager.getConnection (jdbcUrl, username, password);
Note: The problem I encountered was run immediately after being given some posts mentioned changes wait_timeout, do not quite apply in this case . I try to post some of the great God, unfortunately did not solve my problem, I might have is a case of it, where I list what,
link: https://blog.csdn.net/qq_27471405/article/details/80921846
link : https://blog.csdn.net/zouxucong/article/details/53924414
we can try it in accordance with the following method Should I not resolved.
Then the solution is as follows:
First, the simple and crude directly off the firewall
and I'm due to the firewall disabled mysql service. Of course, you can also open ports in the firewall msql advanced settings, usually 3306.
Second, change the IP address url
If you are to build a local mysql database on your computer, then the url address to which the IP address of the computer in the LAN (local area network address, type ipconfig command to view directly in the command-line interface). Because you are using the simulator or a real machine simulation, you want to achieve is a mobile phone to access the mysql database on the computer, but mobile access localhost or 127.0.0.1 represents itself, and can not access the computer. I believe many people like me, the same code with eclipse can successfully access mysql, but can not be accessed in android studio, precisely because the eclipse itself is computer access, you can use localhost or 127.0.0.1, but the phone must use to access the computer the actual ip address of the computer.
Third, the upgrade permissions
you need permission to access your phone IP address of the computer database, enter the following statement at the command-line interface (dos Interface):
(note that the first sentence of no semicolon after the command, a command following each other have a semicolon ; all of the following command in quotation marks are in English, some small reaction partners pasted quotes dos interface is Chinese, we all change Kazakhstan)
1. mysql-uroot--p (landing mysql database you look at your own database of user names and passwords. followed by the user name u, the password p is behind, then there is no need no input)
2. SELECT Host, user from the mysql.user; (see user database)
3. the CREATE the uSER 'root'@'192.168.%' the IDENTIFIED bY ''; (called the root user to create, IP address 192.168%, representing any you can access within the LAN, you can of course be directly%, so everyone can access .identified by followed by a password, I set. empty, ie no password)
4. Grant privileges ON ** All to 'root'@'192.168.%' IDENTIFIED by '' with the Option Grant; (to the user you just created upgrade access to the mysql database Note: The sentence of two asterisks. inter had an English point, due to the editor I can not hit it, your reference picture)
Here Insert Picture Description
5. flush privileges; (refresh permission)
6. quit;
finally, you go about your Android studio debug the code, even found him a success Haha. So far, a satisfactory solution to the ha ha.
To sum up, this post is written of me to waste effort, and I do not just want you dead, like so many brain cells, I pro-test feasible Kazakhstan. Really hope can help to you, if you help to you, or give me a praise? Satisfy my sense of accomplishment ha ha.
Of course, the procedure is not clear what message will certainly give me a reply. If it is another error, I will get back to you in my capacity of, if I did not reply, that I would not just embarrassed to say it.

Published an original article · won praise 1 · views 50

Guess you like

Origin blog.csdn.net/l_l_ll_lll/article/details/104942023
Recommended