5.29博客

上午计网下午建民老师的课

学习内容:安卓

package com.example.app_02.utils;

import com.example.app_02.database.MySQLConnection;
import com.example.app_02.entity.User;
import com.example.app_02.entity.UserInfo;

public class UserInfoDao extends MySQLConnection {
    public int insertUserInfo(UserInfo userInfo) {
        int value = 0;
        connect();
        try {
            String sql = "insert into userinfo(studentid, name, phonenumber, class) values(?,?,?,?)";
            preparedStatement = connection.prepareStatement(sql);
            //将数据插入数据库中
            preparedStatement.setString(1, userInfo.getStudentid());
            preparedStatement.setString(2, userInfo.getName());
            preparedStatement.setString(3, userInfo.getPhonenumber());
            preparedStatement.setString(4, userInfo.getClassname());
            value = preparedStatement.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close();
        }
        return value;
    }
}
posted @ 2024-06-16 20:17  张佳木  阅读(11)  评论(0)    收藏  举报