planclass.java
来自「实习的时候做的数字校园系统」· Java 代码 · 共 196 行
JAVA
196 行
package com.xxgl.business;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.xxgl.data.DBconnection;
import com.xxgl.data.DBUtil;
import com.xxgl.bean.PlanBean;
public class Planclass {
public int insertPlan(PlanBean Croom) {
String sql = "insert into planTable (p_id,p_type,p_date,p_ms,t_id) values (?,?,?,?)";
Connection con = DBconnection.getConnection();
PreparedStatement pstmt = null;
int count = 0;
try {
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, Croom.getP_id());
pstmt.setString(2, Croom.getP_type());
pstmt.setDate(3, Croom.getP_date());
pstmt.setString(4, Croom.getP_ms());
pstmt.setInt(5, Croom.getT_id());
count = pstmt.executeUpdate();
DBUtil.close(pstmt);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(con);
}
return count;
}
public int updatePlan(PlanBean Croom) {
String sql = "update planTable set p_type=?,p_date=?,p_ms=?,t_id=? where p_id=?";
Connection con = DBconnection.getConnection();
PreparedStatement pstmt = null;
int count = 0;
try {
pstmt = con.prepareStatement(sql);
pstmt.setString(1, Croom.getP_type());
pstmt.setDate(2, Croom.getP_date());
pstmt.setString(3, Croom.getP_ms());
pstmt.setInt(4, Croom.getT_id());
pstmt.setInt(5, Croom.getP_id());
count = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt);
DBUtil.close(con);
}
return count;
}
public int deleteBy(int p_id) {
String sql = "delete from planTable where p_id=?";
Connection con = DBconnection.getConnection();
PreparedStatement pstmt = null;
int count = 0;
try {
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, p_id);
count = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt);
DBUtil.close(con);
}
return count;
}
public PlanBean selectPlan(int p_id) {
String sql = "select p_id,p_type,p_date,p_ms,t_id from planTable where p_id=?";
Connection con = DBconnection.getConnection();
PreparedStatement pstmt = null;
PlanBean pdBean = null;
try {
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, p_id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
pdBean = new PlanBean();
pdBean.setP_id(rs.getInt("p_id"));
pdBean.setT_id(rs.getInt("t_id"));
pdBean.setP_type(rs.getString("p_type"));
pdBean.setP_date(rs.getDate("p_date"));
pdBean.setP_ms(rs.getString("p_ms"));
}
DBUtil.close(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt);
DBUtil.close(con);
}
return pdBean;
}
public List selectAll() {
String sql = "select p_id,t_id,p_type,p_date,p_ms from planTable";
Connection con = DBconnection.getConnection();
PreparedStatement pstmt = null;
List list = new ArrayList();
try {
pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
PlanBean pdBean = new PlanBean();
pdBean.setP_id(rs.getInt("p_id"));
pdBean.setT_id(rs.getInt("t_id"));
pdBean.setP_type(rs.getString("p_type"));
pdBean.setP_date(rs.getDate("p_date"));
pdBean.setP_ms(rs.getString("p_ms"));
list.add(pdBean);
}
DBUtil.close(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt);
DBUtil.close(con);
}
return list;
}
public static void main(String[] args) {
PlanBean bean = new PlanBean();
bean.setP_id(107);
bean.setP_type("02");
bean.setP_date(null);
bean.setP_ms("asdl");
Planclass bo = new Planclass();
int count = bo.insertPlan(bean);
System.out.println("count: " + count);
System.out.println("p_date: " + bean.getP_id());
// bean.setP_id(101);
// Planclass bo = new Planclass();
// int count = bo.updatePlan(bean);
// System.out.println("count: " + count);
// Planclass bo = new Planclass();
// int count = bo.deleteBy(101);
// System.out.println("count=" + count);
// Planclass bo = new Planclass();
// PlanBean testBean = bo.selectPlan(101);
// System.out.println(testBean.getP_id()+" "+testBean.getP_type()+" "+"p_date=" + testBean.getP_date());
// Planclass bo = new Planclass();
// List list = bo.selectAll();
// System.out.println("list length: " + list.size());
// for(int i = 0; i < list.size(); i++) {
// PlanBean testBean = (PlanBean)list.get(i);
// System.out.println(testBean.getP_id()+" "+testBean.getP_type()+" "+testBean.getP_date());
// }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?