冲刺第四天
昨天任务是完成多条件的查询
今天的任务依旧是完成多条件的查询
困难时如何将值从前端传入后端
package com.example.shiyan.dao;
import android.util.Log;
import android.widget.Toast;
import com.example.shiyan.entity.Student;
import com.example.shiyan.studentdata;
import com.example.shiyan.util.DbOpenHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class studentdao extends DbOpenHelper {
//数据的插入操作
public int charuStudent(Student student)
{
int iRow=0;
try{
getConnection();//获取数据库连接
String sql="insert into student(id,password,name,age) values(?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,student.getId());
pstmt.setString(2,student.getPassword());
pstmt.setString(3,student.getName());
pstmt.setString(4,student.getAge());
iRow=pstmt.executeUpdate();
//
// if (iRow > 0) {
// System.out.println("注册成功");
// // 可以选择清空输入框或做其他处理
// } else {
// System.out.println("注册失败");
// }
}catch (Exception e)
{
e.printStackTrace();
}finally{
closeAll();
}
return iRow;
}
//数据的更新操作
public int updateStudent(Student student){
int iRow=0;
try {
getConnection();//获取数据库连接
String sql="UPDATE student SET password = ?, name = ?, age = ? WHERE id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, student.getPassword());
pstmt.setString(2,student.getName());
pstmt.setString(3, student.getAge());
pstmt.setString(4,student.getId());
//执行更新操作并记录受影响的行数
iRow= pstmt.executeUpdate();
}catch (Exception e){
e.printStackTrace();
}finally {
closeAll();
}
return iRow;
}
//数据库删除操作
public int deletestudent(Student student){
int iRow=0;
try {
getConnection();//获取数据库连接
String sql="DELETE FROM student WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, student.getId());
//执行删除操作并获取受影响的行数
iRow = pstmt.executeUpdate();
}catch (Exception e){
e.printStackTrace();
}finally {
closeAll();
}
return iRow;
}
}
import android.util.Log;
import android.widget.Toast;
import com.example.shiyan.entity.Student;
import com.example.shiyan.studentdata;
import com.example.shiyan.util.DbOpenHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class studentdao extends DbOpenHelper {
//数据的插入操作
public int charuStudent(Student student)
{
int iRow=0;
try{
getConnection();//获取数据库连接
String sql="insert into student(id,password,name,age) values(?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,student.getId());
pstmt.setString(2,student.getPassword());
pstmt.setString(3,student.getName());
pstmt.setString(4,student.getAge());
iRow=pstmt.executeUpdate();
//
// if (iRow > 0) {
// System.out.println("注册成功");
// // 可以选择清空输入框或做其他处理
// } else {
// System.out.println("注册失败");
// }
}catch (Exception e)
{
e.printStackTrace();
}finally{
closeAll();
}
return iRow;
}
//数据的更新操作
public int updateStudent(Student student){
int iRow=0;
try {
getConnection();//获取数据库连接
String sql="UPDATE student SET password = ?, name = ?, age = ? WHERE id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, student.getPassword());
pstmt.setString(2,student.getName());
pstmt.setString(3, student.getAge());
pstmt.setString(4,student.getId());
//执行更新操作并记录受影响的行数
iRow= pstmt.executeUpdate();
}catch (Exception e){
e.printStackTrace();
}finally {
closeAll();
}
return iRow;
}
//数据库删除操作
public int deletestudent(Student student){
int iRow=0;
try {
getConnection();//获取数据库连接
String sql="DELETE FROM student WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, student.getId());
//执行删除操作并获取受影响的行数
iRow = pstmt.executeUpdate();
}catch (Exception e){
e.printStackTrace();
}finally {
closeAll();
}
return iRow;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现