【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-TypeDao.java,希望本篇文章对您学习有所帮助。
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 type_name='" + vo.getType_name() +
"',type_remark='" + vo.getType_remark() + "' where type_number='" +
vo.getType_number() + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
}