📄 studao.java~16~
字号:
package com.orilore.ssms.dao;
import java.util.*;
import java.sql.*;
import com.orilore.ssms.entity.Student;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class StuDao {
public StuDao() {
}
public List<Student> findAll(){
List<Student> list = new ArrayList();
Connection conn = DbManager.getConn();
PreparedStatement pst = null;
try {
pst = conn.prepareStatement("select * from student");
ResultSet rs = pst.executeQuery();
while(rs.next()){
Student s = new Student();
s.setId(rs.getInt("id"));
s.setName(rs.getString("name"));
s.setAge(rs.getInt("age"));
s.setClassName(rs.getString("className"));
list.add(s);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return list;
}
public boolean insertStudent(Student s){
boolean flag = false;
Connection conn = DbManager.getConn();
try {
PreparedStatement pst = conn.prepareStatement(
"insert into student(name,age,className) values(?,?,?)");
pst.setString(1,s.getName());
pst.setInt(2,s.getAge());
pst.setString(3,s.getClassName());
pst.executeUpdate();
flag = true;
} catch (SQLException ex) {
ex.printStackTrace();
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -