📄 scoredao.java
字号:
package com.orilore.ssms.dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import com.orilore.ssms.entity.Score;
import java.util.List;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.orilore.ssms.entity.Student;
import com.orilore.ssms.entity.Cource;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ScoreDao {
public ScoreDao() {
}
public boolean insertScore(Score s){
boolean flag = false;
Connection conn = DbManager.getConn();
try {
PreparedStatement pst = conn.prepareStatement(
"insert into score(sid,cid,score) values(?,?,?)");
pst.setInt(1,s.getStudent().getId());
String cname = s.getCource().getCname();
CourceDao cd = new CourceDao();
int cid = cd.findIdByName(cname);
pst.setInt(2,cid);
pst.setInt(3,s.getScore());
pst.executeUpdate();
flag = true;
pst.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return flag;
}
public List findAll(){
List<Score> list = new ArrayList();
Connection conn = DbManager.getConn();
PreparedStatement pst = null;
try {
pst = conn.prepareStatement("select sc.id as scid,st.id as stid,st.name as stname,c.cname as cname,sc.score as score from score sc inner join student st on sc.sid=st.id inner join cource c on sc.cid=c.id");
ResultSet rs = pst.executeQuery();
while(rs.next()){
Score s = new Score();
s.setId(rs.getInt("scid"));
Student st = new Student();
st.setId(rs.getInt("stid"));
st.setName(rs.getString("stname"));
s.setStudent(st);
Cource c = new Cource();
c.setCname(rs.getString("cname"));
s.setScore(rs.getInt("score"));
list.add(s);
}
rs.close();
pst.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -