📄 ygxx.java
字号:
/*
* 创建日期 2006-2-22
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package com.zhang.operation;
import java.sql.*;
import com.zhang.common.getDBconn;
import java.util.*;
import com.zhang.bean.YgInfo;
import com.zhang.form.*;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class Ygxx {
private Connection conn = null;
private ResultSet rs = null;
private PreparedStatement pst = null;
private Statement st = null;
private ArrayList al = null;
private YgInfo yginfo = null;
private String sql = "";
private NewygForm newygform = null;
public ArrayList getYgxx() {
conn = new getDBconn().getDbConn();
sql = "select * from yginfo";
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
al = new ArrayList();
while (rs.next()) {
yginfo = new YgInfo();
yginfo.setYgid(rs.getInt(1));
yginfo.setYgname(rs.getString(2));
yginfo.setSex(rs.getString(3));
yginfo.setBumen(rs.getString(4));
yginfo.setDuty(rs.getString(5));
yginfo.setBz(rs.getString(6));
al.add(yginfo);
}
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return al;
}
public boolean addYg(String name, String sex, String bumen, String duty,
String bz) {
boolean b = false;
newygform = new NewygForm();
conn = new getDBconn().getDbConn();
sql = "select ygid from yginfo order by ygid desc";
int ygid = 0;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
if (rs.next()) {
ygid = rs.getInt(1);
}
rs.close();
st.close();
ygid = ygid + 1;
sql = "insert into yginfo values(" + ygid + ",?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, name);
pst.setString(2, sex);
pst.setString(3, bumen);
pst.setString(4, duty);
pst.setString(5, bz);
pst.executeUpdate();
System.out.println("name=" + newygform.getYgname());
System.out.println("sql:" + sql);
b = true;
rs.close();
st.close();
pst.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
public boolean updateYg(UpdateygForm updateygform) {
boolean b = false;
conn = new getDBconn().getDbConn();
sql = "update yginfo set ygname=? ,sex=?,bumen=?,duty=?,bz=? where ygid=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, updateygform.getYgname());
pst.setString(2, updateygform.getSex());
pst.setString(3, updateygform.getBumen());
pst.setString(4, updateygform.getDuty());
pst.setString(5, updateygform.getBz());
pst.setInt(6, updateygform.getYgid());
pst.executeUpdate();
b = true;
System.out.println("sql:" + sql);
System.out.println("name=" + updateygform.getYgname());
pst.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
public boolean deleteYg(int ygid) {
boolean b = false;
conn = new getDBconn().getDbConn();
sql = "delete from yginfo where ygid=" + ygid;
try {
st = conn.createStatement();
st.executeUpdate(sql);
b = true;
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
public YgInfo getYgxxOne(int ygid) {
boolean b = false;
conn = new getDBconn().getDbConn();
yginfo = new YgInfo();
sql = "select * from yginfo where ygid=" + ygid;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
rs.next();
yginfo.setYgid(rs.getInt(1));
yginfo.setYgname(rs.getString(2));
yginfo.setSex(rs.getString(3));
yginfo.setBumen(rs.getString(4));
yginfo.setDuty(rs.getString(5));
yginfo.setBz(rs.getString(6));
System.out.println("sql:" + sql);
System.out.println("name=" + yginfo.getYgname());
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return yginfo;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -