冲刺第四天

昨天任务是完成多条件的查询

今天的任务依旧是完成多条件的查询

困难时如何将值从前端传入后端

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



}
posted @ 2024-04-22 18:30  欧吼吼  阅读(2)  评论(0编辑  收藏  举报