Android database: Direct access to MySQL via JDBC

Source: Internet
Author: User

An article about accessing the local MySQL database through JDBC http://blog.csdn.net/leelit/article/details/41044187, yesterday after learning JDBC to access the local database, I thought, how can I access the database remotely, Really make it a server. The back reminds me of a stand-alone version of the takeout app, if it can be maintained through the database, it is a really meaningful app. Back again. The remote Access database method quickly finds the answer: Http://www.cnblogs.com/xd502djj/archive/2011/04/01/2001826.html, the next is the Android client.

The first article directly using the method, directly in the button inside the JDBC method to access the database, not directly, because no network permissions added! Added network permissions still can not, Lenovo recently learned computer network knowledge, in many cases we are located in the area network, the outer network is unable to directly access the regional network, so simply through the computer to launch WiFi and mobile phone connected to the same network segment, but still not. Later, I think of Android in the main thread is not able to network access, so directly to its thread, and then OK. (later with 2.3 of the mobile phone test without thread is OK, it seems that the main thread can not access the network is a high version of the matter, of course, if the line Cheng can be added, so all add thread is good)

To remotely access the four points of a native database:

1. Set the database to remote access

2. Add Network Permissions

3. Accessing the database in the thread

4, the mobile phone connected to the computer launched out of WiFi so that it is in the same network segment

Key code: Not annotated here, see the first article directly

Button.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubnew Thread (New Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stubjdbcutils ju = new Jdbcutils ( ); String SQL1 = "SELECT * from UserInfo"; try {list<map<string, object>> List = Ju.query (sql1,null); SYSTEM.OUT.PRINTLN (list);} catch (SQLException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}). Start ();}});
Operation Result:

1. Start Database userinfo table data


2, the Android side query


3. Delete a record directly in the NAVICAT database management tool


4. Check Again




At first people say this method is not possible, you must pass a webserver to make a relay, by building a server, on the server to access MySQL, such as can be used Php+mysql server side, PHP data processing in MySQL into JSON, Android then accesses the server via the HTTP protocol to get JSON data. Of course, the direct use of JDBC to access is not good, because the other one anti-compilation, the database account password is not all out, this is not safe, but as a study can drop.

Android database: Direct access to MySQL via JDBC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.