📄 studentdao.java~18~
字号:
package com.wm.dao;
import java.util.ArrayList;
import com.wm.entity.Student;
import java.sql.Connection;
import java.io.*;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class StudentDao {
public StudentDao() {
}
public static boolean insertStudent(ArrayList<Student> list){
boolean flag = false;
DBSource db = null;
try {
db = new DBSource();
Connection con = db.getConnection();
for(Student stu : list){
PreparedStatement pst = con.prepareStatement("inset into student values(?,?,?)");
pst.setInt(1,stu.getId());
pst.setString(1,stu.getName());
pst.setInt(3,stu.getAge());
int i = pst.executeUpdate();
flag = true;
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
return flag;
}
public static ArrayList<Student> getAll(){
ArrayList<Student> list = new ArrayList<Student>();
DBSource db = null;
try {
db = new DBSource();
Connection con = db.getConnection();
PreparedStatement pst = con.prepareStatement("select * from student");
ResultSet rs = pst.executeQuery();
while(rs.next()){
Student stu = new Student();
stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name"));
stu.setAge(rs.getInt("age"));
list.add(stu);
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
return list;
}
public static int deleteStudent(int id){
DBSource db = null;
try {
db = new DBSource();
Connection con = db.getConnection();
PreparedStatement pst = con.prepareStatement("delete from student where id=?");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -