首页 > 其他分享 >12.30

12.30

时间:2025-01-07 23:44:42浏览次数:1  
标签:preparedStatement String int 12.30 resultSet 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,int,12.30,resultSet,sql,id
From: https://www.cnblogs.com/yang-----/p/18658675

相关文章

  • 12.30~1.5 总结
    做题学习了莫队二次离线(未真正掌握)CF2034F2\(2^k\)的组合意义是选子集,这里把\(2^k\)再拆为\(1+2+\dots+2^{k-1}+1\)可以直接叠加关键点的贡献。那么一个关键点的贡献就变成了选后面的一个集合要求必须经过,这个可以dp。CF1463F显然(?)答案是关于前缀\(x+y\)个循环的。对......
  • 12.30 java网络编程之socket编程(NIO多路复用版本) socket编程大作业答案
    在本次项目中,我们将实现一个简单的客户端-服务器(Client-Server)通信模型。通过这个项目,你将学习到如何使用Java的SocketCh和ServerSocket类来创建网络连接,进行数据的发送和接收。该项目不仅涵盖了Socket编程的基础知识,还将帮助你理解网络通信中的重要概念,如TCP/IP协议、阻塞......
  • 2024.12.30
    《程序员修炼之道》这本书为程序员的成长提供了全方位的指引。读完它,我对编程有了全新的认识。书中强调了代码的质量和可维护性。它指出编写代码并非仅仅实现功能,更要注重代码的整洁与高效。例如,通过编写简洁的代码,不仅能提高代码的可读性,还能减少潜在的错误。书中提到的“代码......
  • 2024.12.30 周一
    2024.12.30周一Q1.1100FarmerJohnhasapermutation$p_1,p_2,\ldots,p_n$,whereeveryintegerfrom$0$to$n-1$occursexactlyonce.HegivesBessieanarray$a$oflength$n$andchallengeshertoconstruct$p$basedon$a$.Thearray$a$isconstr......
  • 2024.12.30 ~ 2025.1.5
    12.30忘了具体干了点啥,应该是啥也没干,因为我没记住任何东西(12.31上午模拟赛。然后题目过于困难了......
  • 2024.12.30 由于不会制表痛失一份工作,学习excel制表
    单元格格式可以用来切换其中内容的格式,小技巧,数值右对齐,文字左对齐单元格内换行输出使用Alt+Enter在>数据->分列中可以将某个单元格中的数据分成不同的列1.随机函数rand()返回一个0-1之间的数字,且图表每次更新都会进行随机randbetween(low,high)返回一个low与high之间的任一整......
  • 2024.12.30
    stateDiagram-v2[*]-->Start(开始)Start-->Login[用户登录]Login-->Verify{验证用户信息}Verify-->|成功|Authorize[权限分配]Verify-->|失败|End1[结束:登录失败]Authorize-->System[进入MES系统]System-->PlanCreate[创......
  • 2024.12.30 LGJ Round
    A有一个长度为\(n\)的序列,给你\(m\)个区间,你需要对每个\(B\)求若将\(B\)设为块长,并用分块处理这些区间需要进行多少次运算。\(n,m\le10^6\)。不在一个块内的区间的贡献可以分到其端点处,这样就只需考虑两端点在一个块内的贡献。把每个块长分成的区间求出来\(n\lnn\)......
  • 静力学FEM12.30
    1.静力学方程考虑图所示变截面弹性杆的静态响应。这是线性应力分析或线弹性问题的一个例子,我们需要求杆内的应力分布σ(x)。应力由物体的变形产生,而变形由物体内各点的位移u(x)表征。位移导致用ε(x)表示的应变;应变是一个无量纲变量。杆受到分布力b(x)或集中力作用。这个力可能......
  • 2023.12.30模拟赛总结
    前言:这次比赛打的不是很好,100pts,rank8T1赛时想到了正解,但是因为一些题面的原因和代码细节没调出来首先可以写出暴力dp:\(f[i][j]\)表示到第i位,选了i且选了j个哨岗的最大范围枚举k为上一个,直接暴力转移是\(O(n^3)\)的,过不去然后,我们发现可以分类讨论,如果\([l_i,r_i]\)和\([l_k......