diff --git a/1.txt b/1.txt new file mode 100644 index 0000000..e69de29 diff --git a/AndroidStudio_projects/app/libs/mysql-connector-java-5.1.49.jar b/AndroidStudio_projects/app/libs/mysql-connector-java-5.1.49.jar new file mode 100644 index 0000000..d3c8b41 Binary files /dev/null and b/AndroidStudio_projects/app/libs/mysql-connector-java-5.1.49.jar differ diff --git a/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/ExampleInstrumentedTest.java b/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/ExampleInstrumentedTest.java new file mode 100644 index 0000000..95943b8 --- /dev/null +++ b/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.hamburger; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.hamburger", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/Mtest.java b/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/Mtest.java new file mode 100644 index 0000000..649b061 --- /dev/null +++ b/AndroidStudio_projects/app/src/androidTest/java/com/example/hamburger/Mtest.java @@ -0,0 +1,84 @@ +package com.example.hamburger; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +import com.example.hamburger.dao.UserDao; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.EditText; +import android.view.View; +import android.widget.Toast; +import android.widget.Button; +import android.os.Handler; +import android.os.Message; +import android.annotation.SuppressLint; +import com.example.hamburger.dao.UserDao; +import com.example.hamburger.entity.User; + +@RunWith(AndroidJUnit4.class) +public class Mtest { + + @Test + public void text_1() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.hamburger", appContext.getPackageName()); + + new Thread(){ + @Override + public void run() { + UserDao userDao = new UserDao(); + int msg = userDao.login("1","1"); + } + }.start(); + } + + @Test + public void text_2() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.hamburger", appContext.getPackageName()); + + User user = new User(); + + user.setUserAccount("11"); + user.setUserPassword("11"); + user.setUserName("11"); + user.setUserType(1); + user.setUserState(0); + user.setUserDel(0); + + new Thread(){ + @Override + public void run() { + + int msg = 0; + + UserDao userDao = new UserDao(); + + User uu = userDao.findUser(user.getUserAccount()); + if(uu != null){ + msg = 1; + } + else{ + boolean flag = userDao.register(user); + if(flag){ + msg = 2; + } + } + + } + }.start(); + + } +} diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity.java new file mode 100644 index 0000000..3810e48 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity.java @@ -0,0 +1,70 @@ +package com.example.hamburger; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.EditText; +import android.view.View; +import android.widget.Toast; +import android.widget.Button; +import android.os.Handler; +import android.os.Message; +import android.annotation.SuppressLint; +import com.example.hamburger.dao.UserDao; + +public class MainActivity extends AppCompatActivity { + + //这个类主要用来进行,账号密码的验证,以及监听事件的编写。 + // 所以首先需要将一开始设计的输入文本框id name 和passwd获取。 + EditText name;//创建账号 + EditText passwd;//创建密码 + + private static final String TAG="mysql-party-MainActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + } + + public void login(View view){ + + EditText EditTextAccount = findViewById(R.id.name); + EditText EditTextPassword = findViewById(R.id.passwd); + + Button button = (Button) findViewById(R.id.button); + + new Thread(){ + @Override + public void run() { + UserDao userDao = new UserDao(); + int msg = userDao.login(EditTextAccount.getText().toString(),EditTextPassword.getText().toString()); + hand1.sendEmptyMessage(msg); + } + }.start(); + } + + public void reg(View view){ + startActivity(new Intent(getApplicationContext(),register.class)); + } + + @SuppressLint("HandlerLeak") + final Handler hand1 = new Handler() { + @Override + public void handleMessage(Message msg) { + if (msg.what == 0){ + Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_LONG).show(); + } else if (msg.what == 1) { + Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_LONG).show(); + startActivity(new Intent(getApplicationContext(),MainActivity2.class)); + } else if (msg.what == 2){ + Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_LONG).show(); + } else if (msg.what == 3){ + Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_LONG).show(); + } + } + }; + +} \ No newline at end of file diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity2.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity2.java new file mode 100644 index 0000000..522eda9 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/MainActivity2.java @@ -0,0 +1,37 @@ +package com.example.hamburger; + +import android.os.Bundle; + +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.navigation.ui.AppBarConfiguration; +import androidx.navigation.ui.NavigationUI; + +import com.example.hamburger.databinding.ActivityMain2Binding; + +public class MainActivity2 extends AppCompatActivity { + + private ActivityMain2Binding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + binding = ActivityMain2Binding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + BottomNavigationView navView = findViewById(R.id.nav_view); + // Passing each menu ID as a set of Ids because each + // menu should be considered as top level destinations. + AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( + R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications) + .build(); + NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main2); + NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); + NavigationUI.setupWithNavController(binding.navView, navController); + } + +} \ No newline at end of file diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/dao/UserDao.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/dao/UserDao.java new file mode 100644 index 0000000..45497d4 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/dao/UserDao.java @@ -0,0 +1,247 @@ +package com.example.hamburger.dao; + + +import com.example.hamburger.entity.IsolationUser; +import com.example.hamburger.entity.User; +import com.example.hamburger.utils.JDBCUtils; + +import android.annotation.SuppressLint; +import android.util.Log; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.HashMap; + + +public class UserDao { + + private static final String TAG = "mysql-party-UserDao"; + + /** + * function: 登录 + * */ + @SuppressLint("LongLogTag") + public int login(String userAccount, String userPassword){ + + HashMap map = new HashMap<>(); + // 根据数据库名称,建立连接 + Connection connection = JDBCUtils.getConn(); + int msg = 0; + try { + // mysql简单的查询语句。这里是根据user表的userAccount字段来查询某条记录 + String sql = "select * from user_ where userAccount = ?"; + if (connection != null){// connection不为null表示与数据库建立了连接 + PreparedStatement ps = connection.prepareStatement(sql); + if (ps != null){ + Log.e(TAG,"账号:" + userAccount); + //根据账号进行查询 + ps.setString(1, userAccount); + // 执行sql查询语句并返回结果集 + ResultSet rs = ps.executeQuery(); + int count = rs.getMetaData().getColumnCount(); + //将查到的内容储存在map里 + while (rs.next()){ + // 注意:下标是从1开始的 + for (int i = 1;i <= count;i++){ + String field = rs.getMetaData().getColumnName(i); + map.put(field, rs.getString(field)); + } + } + connection.close(); + ps.close(); + + if (map.size()!=0){ + StringBuilder s = new StringBuilder(); + //寻找密码是否匹配 + for (String key : map.keySet()){ + if(key.equals("userPassword")){ + if(userPassword.equals(map.get(key))){ + msg = 1; //密码正确 + } + else + msg = 2; //密码错误 + break; + } + } + }else { + Log.e(TAG, "查询结果为空"); + msg = 3; + } + }else { + msg = 0; + } + }else { + msg = 0; + } + }catch (Exception e){ + e.printStackTrace(); + Log.d(TAG, "异常login:" + e.getMessage()); + msg = 0; + } + return msg; + } + + + /** + * function: 注册 + * */ + @SuppressLint("LongLogTag") + public boolean register(User user){ + HashMap map = new HashMap<>(); + // 根据数据库名称,建立连接 + Connection connection = JDBCUtils.getConn(); + + try { + String sql = "insert into user_(userAccount,userPassword,userName,userType,userState,userDel) values (?,?,?,?,?,?)"; + if (connection != null){// connection不为null表示与数据库建立了连接 + PreparedStatement ps = connection.prepareStatement(sql); + if (ps != null){ + + //将数据插入数据库 + ps.setString(1,user.getUserAccount()); + ps.setString(2,user.getUserPassword()); + ps.setString(3,user.getUserName()); + ps.setInt(4,user.getUserType()); + ps.setInt(5, user.getUserState()); + ps.setInt(6,user.getUserDel()); + + // 执行sql查询语句并返回结果集 + int rs = ps.executeUpdate(); + if(rs>0) + return true; + else + return false; + }else { + return false; + } + }else { + return false; + } + }catch (Exception e){ + e.printStackTrace(); + Log.e(TAG, "异常register:" + e.getMessage()); + return false; + } + + } + + /** + * function: 录入 + * */ + @SuppressLint("LongLogTag") + public boolean LogInfor(IsolationUser user){ + HashMap map = new HashMap<>(); + // 根据数据库名称,建立连接 + Connection connection = JDBCUtils.getConn(); + + try { + String sql = "insert into infor_(name,gender,id_number,room_number,checkin_time) values (?,?,?,?,?)"; + if (connection != null){// connection不为null表示与数据库建立了连接 + PreparedStatement ps = connection.prepareStatement(sql); + if (ps != null){ + + //将数据插入数据库 + ps.setString(1,user.getname()); + ps.setString(2,user.getGender()); + ps.setString(3,user.getIdnumber()); + ps.setInt(4,user.getRoomnumber()); + ps.setString(5, user.getCheckin_time()); + + // 执行sql查询语句并返回结果集 + int rs = ps.executeUpdate(); + if(rs>0) + return true; + else + return false; + }else { + return false; + } + }else { + return false; + } + }catch (Exception e){ + e.printStackTrace(); + Log.e(TAG, "异常loginfor:" + e.getMessage()); + return false; + } + + } + + /** + * function: 根据账号进行查找该用户是否存在 + * */ + @SuppressLint("LongLogTag") + public User findUser(String userAccount) { + + // 根据数据库名称,建立连接 + Connection connection = JDBCUtils.getConn(); + User user = null; + try { + String sql = "select * from user_ where userAccount = ?"; + if (connection != null){// connection不为null表示与数据库建立了连接 + PreparedStatement ps = connection.prepareStatement(sql); + if (ps != null) { + ps.setString(1, userAccount); + ResultSet rs = ps.executeQuery(); + + while (rs.next()) { + //注意:下标是从1开始 + int id = rs.getInt(1); + String userAccount1 = rs.getString(2); + String userPassword = rs.getString(3); + String userName = rs.getString(4); + int userType = rs.getInt(5); + int userState = rs.getInt(6); + int userDel = rs.getInt(7); + user = new User(userAccount1, userPassword); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + Log.d(TAG, "异常findUser:" + e.getMessage()); + return null; + } + return user; + } + + /** + * function: 根据姓名进行查找该用户是否存在 录入功能 + * */ + @SuppressLint("LongLogTag") + public IsolationUser findUser_(String name) { + + // 根据数据库名称,建立连接 + Connection connection = JDBCUtils.getConn(); + IsolationUser user = null; + try { + String sql = "select * from infor_ where name = ?"; + if (connection != null){// connection不为null表示与数据库建立了连接 + PreparedStatement ps = connection.prepareStatement(sql); + if (ps != null) { + ps.setString(1, name); + ResultSet rs = ps.executeQuery(); + + while (rs.next()) { + //注意:下标是从1开始 + int id = rs.getInt(1); + String name1 = rs.getString(2); + String gender = rs.getString(3); + String idnumber = rs.getString(4); + int roomnumber = rs.getInt(5); + String checkin_time = rs.getString(6); + user = new IsolationUser(name1,gender,idnumber,roomnumber,checkin_time); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + Log.d(TAG, "异常findUser:" + e.getMessage()); + return null; + } + return user; + } + +} + diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/IsolationUser.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/IsolationUser.java new file mode 100644 index 0000000..3a35df8 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/IsolationUser.java @@ -0,0 +1,72 @@ +package com.example.hamburger.entity; + +public class IsolationUser { + + private int id; + private String name; + private String gender; + private String idnumber; + private int roomnumber; + private String checkin_time; + + + public IsolationUser() { + } + + public IsolationUser(String name, String gender, String idnumber, int roomnumber, String checkin_time) { + this.id = id; + this.name = name; + this.gender = gender; + this.idnumber = idnumber; + this.roomnumber = roomnumber; + this.checkin_time = checkin_time; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getname() { + return name; + } + + public void setname(String name) { + this.name = name; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getIdnumber() { + return idnumber; + } + + public void setIdnumber(String idnumber) { + this.idnumber = idnumber; + } + + public int getRoomnumber() { + return roomnumber; + } + + public void setRoomnumber(int roomnumber) { + this.roomnumber = roomnumber; + } + + public String getCheckin_time() { + return checkin_time; + } + + public void setCheckin_time(String checkin_time) { + this.checkin_time = checkin_time; + } +} diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/User.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/User.java new file mode 100644 index 0000000..d6cb795 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/entity/User.java @@ -0,0 +1,83 @@ +package com.example.hamburger.entity; + +public class User { + + private int id; + private String userAccount; + private String userPassword; + private String userName; + private int userType; + private int userState; + private int userDel; + + + public User() { + } + + public User(String userAccount, String userPassword) { + this.id = id; + this.userAccount = userAccount; + this.userPassword = userPassword; + this.userName = userName; + this.userType = userType; + this.userState = userState; + this.userDel = userDel; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUserAccount() { + return userAccount; + } + + public void setUserAccount(String userAccount) { + this.userAccount = userAccount; + } + + public String getUserPassword() { + return userPassword; + } + + public void setUserPassword(String userPassword) { + this.userPassword = userPassword; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public int getUserType() { + return userType; + } + + public void setUserType(int userType) { + this.userType = userType; + } + + public int getUserState() { + return userState; + } + + public void setUserState(int userState) { + this.userState = userState; + } + + public int getUserDel() { + return userDel; + } + + public void setUserDel(int userDel) { + this.userDel = userDel; + } +} + diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/register.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/register.java new file mode 100644 index 0000000..42a4041 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/register.java @@ -0,0 +1,104 @@ +package com.example.hamburger; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; +import com.example.hamburger.dao.UserDao; +import com.example.hamburger.entity.User; + +import androidx.appcompat.app.AppCompatActivity; + +public class register extends AppCompatActivity { + private static final String TAG = "mysql-party-register"; + EditText userAccount = null; + EditText userPassword = null; + EditText userName = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + + userAccount = findViewById(R.id.userAccount); + userPassword = findViewById(R.id.userPassword); + userName = findViewById(R.id.userName); + } + + + public void register(View view){ + + String userAccount1 = userAccount.getText().toString(); + String userPassword1 = userPassword.getText().toString(); + String userName1 = userName.getText().toString(); + User user = new User(); + user.setUserAccount(userAccount1); + user.setUserPassword(userPassword1); + user.setUserName(userName1); + user.setUserType(1); + user.setUserState(0); + user.setUserDel(0); + + new Thread(){ + @Override + public void run() { + int msg = 0; + UserDao userDao = new UserDao(); + User uu = userDao.findUser(user.getUserAccount()); + if(uu != null){ + msg = 1; + } + else{ + boolean flag = userDao.register(user); + if(flag){ + msg = 2; + } + } + hand.sendEmptyMessage(msg); + } + }.start(); + + + } + @SuppressLint("HandlerLeak") + final Handler hand = new Handler() + { + public void handleMessage(Message msg) { + if(msg.what == 0) { + Toast.makeText(getApplicationContext(),"注册失败",Toast.LENGTH_LONG).show(); + } else if(msg.what == 1) { + Toast.makeText(getApplicationContext(),"该账号已经存在,请换一个账号",Toast.LENGTH_LONG).show(); + } else if(msg.what == 2) { + Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show(); + Intent intent = new Intent(); + //将想要传递的数据用putExtra封装在intent中 + intent.putExtra("a","注册"); + setResult(RESULT_CANCELED,intent); + finish(); + } + } + }; + + public void Ret(View view){ + //获取按钮 + Button button = (Button) findViewById(R.id.ret); + + //按钮进行监听 + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //监听按钮,如果点击,就跳转 + Intent intent = new Intent(); + //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 + intent.setClass(register.this, MainActivity.class); + startActivity(intent); + } + }); + } + +} \ No newline at end of file diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/ui/home/Inform_input.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/ui/home/Inform_input.java new file mode 100644 index 0000000..ab58cf6 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/ui/home/Inform_input.java @@ -0,0 +1,101 @@ +package com.example.hamburger.ui.home; +import androidx.appcompat.app.AppCompatActivity; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.hamburger.R; +import com.example.hamburger.dao.UserDao; +import com.example.hamburger.entity.IsolationUser; + +public class Inform_input extends AppCompatActivity{ + + private static final String TAG = "mysql-party-register"; + EditText name = null; + EditText gender = null; + EditText idnumber = null; + EditText roomnumber = null; + EditText checkin_time = null; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.infor_input); + + name = findViewById(R.id.name); + gender = findViewById(R.id.gender); + idnumber = findViewById(R.id.ID_number); + roomnumber = findViewById(R.id.roomnumber); + checkin_time = findViewById(R.id.checkin_time); + + } + + public void addInfor(View view){ + String name1 = name.getText().toString(); + String gender1 = gender.getText().toString(); + String idnumber1 = idnumber.getText().toString(); + int roomnumber1 = Integer.parseInt(roomnumber.getText().toString()); + String checkin_time1 = checkin_time.getText().toString(); + + IsolationUser user=new IsolationUser(); + + user.setname(name1); + user.setGender(gender1); + user.setIdnumber(idnumber1); + user.setRoomnumber(roomnumber1); + user.setCheckin_time(checkin_time1); + + new Thread(){ + @Override + public void run() { + + int msg = 0; + + UserDao userDao = new UserDao(); + + IsolationUser uu = userDao.findUser_(user.getname()); + if(uu != null){ + msg = 1; + } + else{ + boolean flag = userDao.LogInfor(user); + if(flag){ + msg = 2; + } + } + hand.sendEmptyMessage(msg); + + } + }.start(); + } + + @SuppressLint("HandlerLeak") + final Handler hand = new Handler() + { + public void handleMessage(Message msg) { + if(msg.what == 0) { + Toast.makeText(getApplicationContext(),"录入失败",Toast.LENGTH_LONG).show(); + } else if(msg.what == 1) { + Toast.makeText(getApplicationContext(),"该信息已经存在,请重新录入",Toast.LENGTH_LONG).show(); + } else if(msg.what == 2) { + Toast.makeText(getApplicationContext(), "录入成功", Toast.LENGTH_LONG).show(); + Intent intent = new Intent(); + //将想要传递的数据用putExtra封装在intent中 + intent.putExtra("a","录入"); + setResult(RESULT_CANCELED,intent); + finish(); + } + } + }; + + public void findInfor(View view){ + + } + +} diff --git a/AndroidStudio_projects/app/src/main/java/com/example/hamburger/utils/JDBCUtils.java b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/utils/JDBCUtils.java new file mode 100644 index 0000000..442c3a4 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/java/com/example/hamburger/utils/JDBCUtils.java @@ -0,0 +1,37 @@ +package com.example.hamburger.utils; + +import java.sql.Connection; +import java.sql.DriverManager; + +/** + * function: 数据库工具类,连接数据库用 + */ +public class JDBCUtils { + private static final String TAG = "mysql-party-JDBCUtils"; + + private static String driver = "com.mysql.jdbc.Driver";// MySql驱动 + + private static String dbName = "party";// 数据库名称 + + private static String user = "rootes";// 用户名 + + private static String password = "123456";// 密码 + + public static Connection getConn(){ + + Connection connection = null; + try{ + Class.forName(driver);// 动态加载类 + String ip = "192.168.43.7";// 写成本机地址,不能写成localhost,同时手机和电脑连接的网络必须是同一个 + + // 尝试建立到给定数据库URL的连接 + connection = DriverManager.getConnection("jdbc:mysql://" + ip + ":3306/" + dbName, + user, password); + + }catch (Exception e){ + e.printStackTrace(); + } + return connection; + } +} + diff --git a/AndroidStudio_projects/app/src/main/res/layout/activity_main.xml b/AndroidStudio_projects/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..95e4973 --- /dev/null +++ b/AndroidStudio_projects/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +