📄 typedao.java~1~
字号:
package com.dao;
import com.tool.JDBConnection;
import java.util.*;
import com.domain.TypeVO;
import java.sql.*;
public class TypeDao {
private JDBConnection connection = null;
public TypeDao() {
connection = new JDBConnection();
this.connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
}
//查询全部的计量单位
public List typeSelect() {
List list = new ArrayList();
TypeVO type = null;
String sql = "select * from tb_type order by id";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
type = new TypeVO();
type.setId(Integer.valueOf(rs.getString(1)));
type.setType_number(rs.getString(2));
type.setType_name(rs.getString(3));
type.setType_remark(rs.getString(4));
list.add(type);
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return list;
}
//以编号为条件查询信息
public TypeVO typeSelectOne(String number) {
TypeVO type = null;
String sql = "select * from tb_type where type_number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
type = new TypeVO();
type.setId(Integer.valueOf(rs.getString(1)));
type.setType_number(rs.getString(2));
type.setType_name(rs.getString(3));
type.setType_remark(rs.getString(4));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return type;
}
//以名称为条件查询
public TypeVO typeSelectName(String name) {
TypeVO type = null;
String sql = "select * from tb_type where type_name='" + name + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
type = new TypeVO();
type.setId(Integer.valueOf(rs.getString(1)));
type.setType_number(rs.getString(2));
type.setType_name(rs.getString(3));
type.setType_remark(rs.getString(4));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return type;
}
//添加操作
public void typeInsert(TypeVO vo) {
String sql = "insert into tb_type values ('" + vo.getType_number() + "','" +
vo.getType_name() + "','" + vo.getType_remark() + "')";
connection.executeUpdate(sql);
connection.closeConnection();
}
//删除操作
public void typeDelete(Integer id) {
String sql = "delete from tb_type where id='" + id + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
//修改编号的操作
public void typeUpdateNumber(Integer id, String number) {
String unNumber = "type-" + String.valueOf(id);
String sql = "update tb_type set type_number='" + unNumber +
"' where type_number='" + number + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
//修改操作
public void typeUpdate(TypeVO vo) {
String sql = "update tb_type set unit_name='" + vo.getType_name() +
"',unit_remark='" + vo.getType_remark() + "' where type_number='" +
vo.getType_number() + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -