Logon module of Android app to access MySQL database note

Source: Internet
Author: User

.. It took about three weeks to finally access the MySQL database through the Android Application login module. Looking back, it's actually quite simple. However, it was indeed difficult to implement this function by my own strength. The road was over, and the time and effort were not in vain. Let me summarize the difficulties. How can I start? It's a bit messy, because I am working on a login module of the ordering system, so I just want to talk about it for my application. Because our team (university team, haha .. If you have time to do it, you can put it on that team.) unlike a team that has a pear at work, everyone is very lazy. If you have time to do it, the teacher hasn't given it to the pear, maybe for various reasons. But I want to learn something, so it takes a lot of time. Taking this login module as an example, at first, our deputy director of the team said that we do not need to log on, or do login as a "standalone, the so-called single machine is to access the android embedded SQLite database. In this case, it is very simple, but in actual application, it is meaningless and difficult. Who won't do it? Who is the requirement for such a login principle? Haha .. Therefore, I planned to access the back-end database and finally chose the MySQL database. I checked a lot of information because I had no knowledge about this. Java Servlet and JSP. JSP read a book, Servlet also read a book, and then checked a lot of online resources. In short, I have mastered a lot of server principles. JSP is essentially servlet, and servlet is essentially a Java program. Servlet is running on the server, while JSP is a dynamic web page, but they work in almost the same way. In the end, it is necessary to compile the compiler into a Java class for running. JSP is actually a combination of JSP tags, Java programs, and HTML files. It uses Java as its built-in scripting language. jsp is Java. Knowledge is a very special Java language. It actually calls the JSP Engine to generate a Java file, and then compiles the Java file into a class file. In this way, a dynamic web page is generated. Servlet runs on the JSP server and is used to generate a Java program on the web page. servlet is developed earlier than JSP. Its functions are more powerful than traditional CGI (public gateway interface. On the server-side Java virtual machine, each request from the client is responded by a small Java thread in the servlet. Servlet is a Java program running on the server, used to process client requests and server responses. Doget () and dopost () are two callback functions in the servlet program, used to process get and post requests. The response and request objects are server-side responses and client requests. It is used to pass some parameters and print the webpage tag. The basic principle is as follows. If you want to know more clearly, go to the relevant documents for details. Process: client (end user) <------> Web Server (servlet, JSP program) <---------> database, legacy application, Java application, Web service, etc. Well, with the above knowledge, you can start to do it .. I am a la carte server (diancai_server) developed on myeclipse ). Create a new project in myeclipse and name it. These are relatively simple. Let's talk about the difficulties I encountered. 1. First, it took a lot of time to load the driver. Class. forname ("org. gjt. mm. mySQL. driver ") or class. forname ("com. mySQL. JDBC. driver ") In fact, these two Drivers (Org. gjt. mm. mySQL. driver and COM. mySQL. JDBC. driver. It's just a different driver package name. I can't tell the specifics, but I can. 2. Connection conn = drivermanager. getconnection ("JDBC: mysql: // localhost: 3306/diancai_db", "root", "andylin"); The 3306 here is also annoying, because I do not remember the steps for installing mysql. One of the steps is to specify the MySQL port, which is 3306 by default. However, I can change 3306 to my own Tomcat port. I do not know the specific principle. 3. Then, it took a lot of time to configure tomcat. Anyway, I think Tomcat is easy to make an error. What classpath. It is very troublesome. What else do you need to build your own web applications. Not difficult but complicated. Just take a look at the book. 4. In eclipse, the URL for writing and querying user names and passwords does not understand either. Http: // 169.254.89.111/diancai_server/loginservlet? Username = *** & Password = ***. This URL does not know how to write it at first .. Pass the parameter through the get method, get the username and password through the request on the server side, and then perform query and comparison. .. These are all records that can be checked continuously. There is no one to take you with. It is hard to learn by yourself, because there is no foundation. 5. Tomcat restarts the Tomcat server every time it modifies the web application. Deploy your own applications and write the web. when reading XML files, you also need to read the books. The servlet, servlet-name, servlet-class, servlet-mapping, and URL-pattern tags both need to understand what they mean. 6. One thing that is more convenient is that after developing a web project on myeclipse, when it is deployed on Tomcat, directly copy the WEB-INF in the project in myeclipse to your application in the webapps file in Tomcat. 7. directly use JDBC to access the database, you need to import the mysql-java.jar driver package in the project. Use build path-> Add External Archives to import data. 8. Develop Android applications in Eclipse IDE, write the login program, run it, and access the database. Because the httpclient class is encapsulated in Android, HTTP can be easily accessed to the database. .. Nothing else. The rest is to work hard.

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.