android studio 连接云服务器上的mysql实现登录注册
我使用的是云服务器上安装的mysql 具体的安装步骤可以百度一下挺简单的,我这里就不写步骤了。当然如果你用的是本地的mysql也行,连接步骤都是一样的。
首先在android studio中导入mysql驱动包
驱动包在官网就可以下载 建议不要用8.0以上的 容易报错。
在main中新建一个libs文件然后把下载的驱动包放在libs文件中

右击选择Add As Library
添加完成后在注册清单中增加网络权限
<uses-permission android:name="android.permission.INTERNET" />
准备工作到这已经结束了 接下来就代码的编写 ,登录注册的界面比较简单 我就只展示注册界面(登录界面只比注册界面多了一个注册按钮)
注册界面布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tt.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="97dp"
android:id="@+id/name"
android:text="账号:"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginStart="97dp"
android:layout_marginTop="114dp" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/phone"
android:hint="输入手机号"
android:textSize="13sp"
android:background="@null"
android:layout_alignBottom="@+id/name"
android:layout_toRightOf="@+id/name"
android:layout_toEndOf="@+id/name"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="97dp"
android:id="@+id/mima"
android:layout_below="@+id/name"
android:text="密码:"
android:layout_marginTop="14dp" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/password"
android:layout_below="@+id/phone"
android:textSize="13sp"
android:hint="输入密码"
android:background="@null"
android:layout_toRightOf="@+id/mima"
android:layout_marginTop="15dp"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp" />
<Button
android:id="@+id/zhuce"
android:layout_width="wrap_content"
android:layout_height="wrap_conten

本文介绍了如何在Android Studio中连接到云服务器上的MySQL数据库,进行登录注册功能的实现。首先需要在Android Studio中导入MySQL驱动,然后创建libs文件夹并添加驱动包。接着,设置必要的网络权限。在代码部分,展示了简洁的注册界面布局和关键的注册功能代码,同时提供了登录功能的核心代码示例。完整代码Demo可在优快云下载。
最低0.47元/天 解锁文章
1万+





