📄 base.java
字号:
package device;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import comm.*;
/*
说明:此类用于设置系统的基本信息
1 BaseType number 基本信息分类编号,BaseType = 1表示当前记录为"设备分类"信息,BaseType = 2表示当前记录为"部门名称"信息
2 Title varchar2 50 基本信息名称
*/
public class Base {
private int BaseType; // 基本信息分类编号
private String Title; // 基本信息名称
//定义字符串处理对象
StringOper so = new StringOper();
public boolean getBase()throws Exception
{
String condition = " Where ";
int conditionNo = 0;
//定义数据库操作对象
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Select * from Dev_Base ";
try
{
if(BaseType != 0)
{
condition += "BaseType="+ BaseType;
conditionNo++;
}
if(Title != null)
{
if(conditionNo > 0)
{
condition += " and ";
}
condition += "Title='"+Title+"'";
conditionNo++;
}
if(conditionNo > 0)
{
sql += condition;
}
rs = o_DBOper.getResultSet(sql);
if(rs.next())
{
setBaseType(rs.getInt("BaseType"));
setTitle(so.ReplaceNull(rs.getString("Title")));
return true;
}
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
return false; }
// 获得多个基本信息,返回到Vector数组
public Vector getMoreBases() throws Exception
{
Vector v_Base = new Vector(); // 定义数组变量
int conditionNo = 0; // 定义查询条件个数变量
// 连接数据库
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
// 查询语句
String sql = "Select * from Dev_Base";
String condition = " Where ";
try{
// 如果编号不为0,则增加查询条件
if(BaseType != 0){
condition += " BaseType="+BaseType;
conditionNo++;
}
// 如果名称不为空,则增加查询条件
if(Title != null){
if(conditionNo > 0) {
condition += " and ";
}
condition += "Title='"+Title+"'";
conditionNo++;
}
// 当条件个数大于0时,连接查询语句
if(conditionNo > 0)
sql += condition;
sql += " order by BaseType";
// 执行数据库查询操作,返回结果集
rs = o_DBOper.getResultSet(sql);
// 如果结果集不为空,则将信息放入对象中
while(rs.next())
{
Base o_Base = new Base();
o_Base.setBaseType(rs.getInt("BaseType"));
o_Base.setTitle(so.ReplaceNull(rs.getString("Title")));
// 把对象放入Vector数组中
v_Base.add(o_Base);
}
}
// 如果有错误发生,则抛出异常
catch(Exception e) {throw new Exception(e.getMessage());}
// 无论是否有错误发生,都要关闭数据库连接
finally{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
return v_Base;
}
//插入新设置信息
public void CreateBase() throws Exception
{
// 建立数据库对象
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
// 定义操作语句
String sql = "Insert into Dev_Base(BaseType,Title) Values("+BaseType+",'"+Title+"')";
try{
// 执行操作
o_DBOper.DataUpdate(sql);
}
// 如果有错误,则抛出异常处理
catch(Exception e){
throw new Exception(e.getMessage());
}
// 关闭数据库连接
finally{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
//更新名称
public void UpdateBase(String oldname) throws Exception
{
// 连接数据库
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
// 定义更新语句
String sql = "Update Dev_Base Set Title='"+Title+"'";
sql = sql + " Where BaseType="+BaseType+" and Title='"+oldname+"'";
try{
// 执行操作
o_DBOper.DataUpdate(sql);
}
catch(Exception e){
throw new Exception(e.getMessage());
}
finally{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
//删除名称
public void DeleteBase() throws Exception
{
// 连接数据库
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
// 定义删除语句
String sql_dlt = "Delete from Dev_Base Where BaseType =" + BaseType +" and Title='"+Title+"'";
try{
o_DBOper.DataUpdate(sql_dlt);
}
catch(Exception e){
throw new Exception(e.getMessage());
}
finally{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
public void setBaseType(int BaseType){
this.BaseType = BaseType;
}
public int getBaseType(){
return this.BaseType;
}
public void setTitle(String Title){
this.Title = Title;
}
public String getTitle(){
return this.Title;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -