首页 > 其他分享 >12.31

12.31

时间:2025-01-07 23:45:02浏览次数:1  
标签:preparedStatement String 12.31 resultSet int sql id

package com.example.ourhomework1.dao;

import com.example.ourhomework1.pojo.*;
import com.example.ourhomework1.utils.DbOpenHelper;

import java.lang.Record;
import java.util.ArrayList;
import java.util.List;

public class UserDao extends DbOpenHelper {
public int addStudent(Student student) {

int iRow = 0;
try {
getConnection();
String sql = "insert into student values(?,?,?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, student.getId());
preparedStatement.setString(2, student.getName());
preparedStatement.setString(3, student.getPhone());
preparedStatement.setString(4, student.getStudentClass());
preparedStatement.setString(5, student.getPassword());
iRow = preparedStatement.executeUpdate();


} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return iRow;
}

public int addRecord(Records records) {
int iRow = 0;
try {
getConnection();
String sql = "insert into records values(?,?,?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, records.getId());
preparedStatement.setString(2, records.getDate());
preparedStatement.setString(3, records.getStartTime());
preparedStatement.setString(4, records.getEndTime());
preparedStatement.setString(5, records.getRecord());
iRow = preparedStatement.executeUpdate();

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return iRow;

}

public String login(int id) {
String password = "";
try {
getConnection();
String sql = "select password from student where id=?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
password = resultSet.getString("password");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return password;
}

public String teacherLogin(int id) {
String password = "";
try {
getConnection();
String sql = "select password from teacher where id=?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
password = resultSet.getString("password");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return password;
}

public String dailyRecord(int id) {
String password = "";
try {
getConnection();
String sql = "select password from teacher where id=?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
password = resultSet.getString("password");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return password;
}

public int addObject(Objectives objectives) {

int iRow = 0;
try {
getConnection();
String sql = "insert into objectives(id,objective,isFinished) values(?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, objectives.getId());
preparedStatement.setString(2, objectives.getObjective());
preparedStatement.setInt(3, objectives.getIsFinished());
iRow = preparedStatement.executeUpdate();


} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return iRow;
}

public int analysis(Analysis analysis) {

int iRow = 0;
try {
getConnection();
String sql = "insert into analysis(id,analysis,nextWeek) values(?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, analysis.getId());
preparedStatement.setString(2, analysis.getAnalysis());
preparedStatement.setString(3, analysis.getNextWeek());
iRow = preparedStatement.executeUpdate();


} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return iRow;
}

public int getCount(int id) {
int count = 0;

try {
getConnection();
String sql = "select count(*) as count from objectives where id = ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);

resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
count = resultSet.getInt("count");
}

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return count;
}

public int getIsFinished(int id) {
int isFinished = 0;
int num = 0;
int average = 0;
try {
getConnection();
String sql = "select isFinished from objectives where id = ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);

resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int temp = resultSet.getInt("isFinished");
num++;
isFinished += temp;
}
average = isFinished / num;

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return average;
}

public int getDays(int id) {
int days = 0;

try {
getConnection();
String sql = "select count(*) as count from records where id = ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);

resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
days = resultSet.getInt("count");
}

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return days;
}

public List<Records> getAllRecords() {
List<Records> allRecords = new ArrayList<>();
try {
getConnection();
String sql = "select * from records ";
preparedStatement = connection.prepareStatement(sql);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Records record = new Records();
record.setId(resultSet.getInt("id"));
record.setDate(resultSet.getString("date"));
record.setStartTime(resultSet.getString("startTime"));
record.setEndTime(resultSet.getString("endTime"));
record.setRecord(resultSet.getString("record"));

allRecords.add(record);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return allRecords;
}


public List<Records> getDailyRecords(String search) {
List<Records> allRecords = new ArrayList<>();
try {
getConnection();
String sql = "select * from records where record like concat('%',?,'%')";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, search);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Records record = new Records();
record.setId(resultSet.getInt("id"));
record.setDate(resultSet.getString("date"));
record.setStartTime(resultSet.getString("startTime"));
record.setEndTime(resultSet.getString("endTime"));
record.setRecord(resultSet.getString("record"));

allRecords.add(record);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return allRecords;
}


public List<Information> getInformation() {


List<Information> allRecords = new ArrayList<>();
try {
getConnection();
String sql = "select " +
"student.*,count(records.id) as count " +
"from student left join records " +
"on student.id = records.id " +
"group by student.id";
preparedStatement = connection.prepareStatement(sql);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Information information = new Information();
information.setId(resultSet.getInt("student.id"));
information.setName(resultSet.getString("student.name"));
information.setStudentClass(resultSet.getString("student.studentClass"));
information.setCount(resultSet.getInt("count"));
allRecords.add(information);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
closeAll();
}
return allRecords;
}

/*public AllAnalysis getAllAnalysis(int id) {
AllAnalysis allAnalysis = new AllAnalysis();
allAnalysis.setId(id);
allAnalysis.setRecordsNumber(getCount(id));
allAnalysis.setAverage(getIsFinished(id));
allAnalysis.setDayNumber(getDays(id));
return allAnalysis;
}*/
}

标签:preparedStatement,String,12.31,resultSet,int,sql,id
From: https://www.cnblogs.com/yang-----/p/18658676

相关文章

  • 2024.12.31
    《程序员修炼之道》之中最令我印象深刻的是对代码质量的重视。它强调编写代码不仅要实现功能,更要注重代码的可读性与可维护性。这一点在我的实际工作中得到了很好的验证。在一次项目中,我负责一段复杂的代码编写。起初,为了赶进度,我没有过多考虑代码的结构和注释。结果当后续需要修......
  • 12.31
    读书笔记1:编程基础与核心概念主要内容:编程语言的选择与学习:书中首先讨论了如何选择编程语言。初学者可以根据自己的兴趣和目标选择语言,例如Python适合数据分析与人工智能,Java适合企业级开发等。学习语言的过程中,注重理解编程的基本语法和结构,如变量、控制流、函数等。算法与......
  • 2024.12.23-2024.12.31
    物理波\[u(x,t)=A\sin(kx-\omegat+\phi)\]1.位移(u(x,t))(u(x,t))表示在位置(x)和时间(t)时波的位移。它是描述波动状态的函数。2.振幅(A)(A)是波的振幅,表示波动的最大位移。振幅越大,波的能量通常也越大。3.波数(k)波数(k)......
  • 静力学FEM12.31
    1.静力学方程考虑图所示变截面弹性杆的静态响应。这是线性应力分析或线弹性问题的一个例子,我们需要求杆内的应力分布σ(x)。应力由物体的变形产生,而变形由物体内各点的位移u(x)表征。位移导致用ε(x)表示的应变;应变是一个无量纲变量。杆受到分布力b(x)或集中力作用。这个力可能......
  • 12.31安全检测(软硬件面试)&信息专员
    EN、IEC安全标准介绍EN:欧洲标准(例如EN303645,针对物联网设备的网络安全要求)。身份鉴别:强身份认证、防止未授权(强密码)远程访问控制:鉴权、强密码安全更新和补丁:接收补丁更新数据保护:数据传输存储加密隐私保护:保护用户个人数据、不收集不必要信息IEC标准:国际电工委员会(IEC)的......
  • 意得辑真不错,85喆优惠码延长到25.12.31了我用editage意得辑润色SCI已经第4年了,今天他
    意得辑真不错,85喆优惠码延长到25.12.31了我用editage意得辑润色SCI已经第4年了,今天他家的学术支持老师让我写几句感受,那我真的感受太多了。因为下单太多一度被导师怀疑是在他家套经费。22年刚读博同时润色了三篇,被导师叫到办公室,问我是什么途径联系到的。我说师兄给说的,网上下......
  • 意得辑真不错,85喆优惠码延长到25.12.31
    意得辑真不错,85喆优惠码延长到25.12.31了我用editage意得辑润色SCI已经第4年了,今天他家的学术支持老师让我写几句感受,那我真的感受太多了。因为下单太多一度被导师怀疑是在他家套经费。22年刚读博同时润色了三篇,被导师叫到办公室,问我是什么途径联系到的。我说师兄给说的,网上下......
  • 2023.12.31——每日总结
    学习所花时间(包括上课):9h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习;我了解到的知识点:1.ERP明日计划:学习......
  • 闲话12.31
    明天怎么就该回学校了......
  • 12.31每日总结
    实验三:JFinal极速开发框架实验一、实验要求 根据参考资料,学习JFinal极速开发框架的使用并如下任务: 任务一:了解Maven及其使用方法,总结其功能作用(占20%) 任务二:学习JFinal框架,基于Maven建立JFinal工程,并对JFinal框架功能进行总结介绍(占30%) 任务三:基于JFinal完成一个简单的学......