5.29部落格

张佳木發表於2024-06-16

上午計網下午建民老師的課

學習內容:安卓

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;
}
}