⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tphmbrandimpl.java

📁 HW-中国移动企业信息机,请查看
💻 JAVA
字号:
package com.sxit.phonemanager;
import java.util.*;
import java.sql.*;
/**
 * <p>类名: TphmbrandImpl</p>
 * <p>功能: 品牌</p>
 * <p>公司: 深讯信科</p>
 * <p>版本: 1.0</p>
 * @程序 sxit
 * @日期 2005-03-22
 * @修改纪录
 */
public class TphmbrandImpl
{
     public TphmbrandImpl()
     {
          super();
     }
     protected long brandid;//品牌
     protected String brandname;//品牌名
     public void setBrandid(long brandid)
     {
          this.brandid = brandid;
     }
     public long getBrandid()
     {
          return brandid;
     }
     public void setBrandname(String brandname)
     {
          this.brandname = brandname;
     }
     public String getBrandname()
     {
          return brandname;
     }
     /**
      * 创建数据,需要初始化类
      */
     public void create(Connection con,long brandid) throws SQLException
     {
          PreparedStatement stmt=null;
          ResultSet rs=null;
          String sql="";
          try{
               sql="select brandid,brandname from tphmbrand where brandid=?";
               stmt=con.prepareStatement(sql);
               stmt.setLong(1,brandid);
               rs=stmt.executeQuery();
               if(rs.next()){
                    this.brandid = rs.getLong("brandid");
                    brandname = rs.getString("brandname");
               }
               stmt.close();
          }
          finally{
               if(stmt!=null) stmt.close();
          }
     }
     /**
      * 插入数据,无需要初始化类
      */
     public static int insert(Connection con,long brandid,String brandname) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          try
          {
               sql="insert into tphmbrand "+
                   "(brandid,brandname) "+
                   "values (?,?)";
               stmt=con.prepareStatement(sql);
               stmt.setLong(1, brandid);
               stmt.setString(2, brandname);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally
          {
               if(stmt!=null) stmt=null;
          }
          return cnt;
     }
     /**
      * 插入数据,需要初始化类,并将设置类的域
      */
     public int insert(Connection con) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          try
          {
               sql="insert into tphmbrand "+
                   "(brandid,brandname) "+
                   "values (?,?)";
               stmt=con.prepareStatement(sql);
               stmt.setLong(1, brandid);
               stmt.setString(2, brandname);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally
          {
               if(stmt!=null) stmt=null;
          }
          return cnt;
     }
     /**
      * 更新数据,无需要初始化类
      */
     public static int update(Connection con,long brandid,String brandname) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          try
          {
               sql="update tphmbrand set brandname=? where brandid=?";
               stmt=con.prepareStatement(sql);
               stmt.setString(1, brandname);
               stmt.setLong(2, brandid);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally
          {
               if(stmt!=null) stmt=null;
          }
          return cnt;
     }
     /**
      * 更新数据,需要初始化类,并将设置类的域
      */
     public int update(Connection con) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          try
          {
               sql="update tphmbrand set brandname=? where brandid=?";
               stmt=con.prepareStatement(sql);
               stmt.setString(1, brandname);
               stmt.setLong(2, brandid);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally
          {
               if(stmt!=null) stmt=null;
          }
          return cnt;
     }
     /**
      * 删除一条数据
      */
     public static int delete(Connection con,long brandid) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          try{
               sql="delete from tphmbrand where brandid=?";
               stmt=con.prepareStatement(sql);
               stmt.setLong(1,brandid);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally{
               if(stmt!=null) stmt.close();
          }
          return cnt;
     }
     /**
      * 删除多条数据
      */
     public static int delete(Connection con, String brandid[]) throws SQLException
     {
          PreparedStatement stmt=null;
          String sql="";
          int cnt=0;
          int i=0;
          try{
               sql="delete from tphmbrand where brandid in (";
               for (i=0;i<brandid.length;i++ ) {
                    if(i==0) sql=sql+brandid[i];
                    else sql=sql+","+brandid[i];
               }
               sql=sql+")";
               stmt = con.prepareStatement(sql);
               cnt=stmt.executeUpdate();
               stmt.close();
          }
          finally{
               if(stmt!=null) stmt.close();
          }
          return cnt;
     }
     /**
      * 外键下拉表单数据
      */
     public static String getBrandid(Connection con) throws SQLException
     {
          PreparedStatement stmt=null;
          ResultSet rs=null;
          String sql="";
          String str="";
          int i=0;
          try {
               sql="select brandid,brandname from tphmbrand order by brandid";
               stmt=con.prepareStatement(sql);
               rs=stmt.executeQuery();
               str="<option value=\"0\">请选择</option>";
     
               while(rs.next())
               {
                         str=str+
                             "<option value=\""+
                             rs.getLong("brandid")+
                             "\">"+
                             rs.getString("brandname")+
                             "</option>";
               }
               stmt.close();
          }
          finally {
               if(stmt!=null) stmt.close();
          }
          return str;
     }
     /**
      * 外键下拉表单数据(选定)
      */
     public static String getBrandid(Connection con,long brandid) throws SQLException
     {
          PreparedStatement stmt=null;
          ResultSet rs=null;
          String sql="";
          String str="";
          int i=0;
          try {
               sql="select brandid,brandname from tphmbrand order by brandid";
               stmt=con.prepareStatement(sql);
               rs=stmt.executeQuery();
               str="<option value=\"0\">请选择</option>";
  
               while(rs.next())
               {
                    if(rs.getLong("brandid")==brandid){
                         str=str+
                             "<option selected value=\""+
                             rs.getLong("brandid")+
                             "\">"+
                             rs.getString("brandname")+
                             "</option>";
                    }else{
                         str=str+
                             "<option value=\""+
                             rs.getLong("brandid")+
                             "\">"+
                             rs.getString("brandname")+
                             "</option>";
                    }
               }
               stmt.close();
          }
          finally {
               if(stmt!=null) stmt.close();
          }
          return str;
     }
     /**
      * 获取外键名
      */
     public static String getBrandname(Connection con,long brandid) throws SQLException
     {
          PreparedStatement stmt=null;
          ResultSet rs=null;
          String sql="";
          String str="";
          int i=0;
          try {
               sql="select brandid,brandname from tphmbrand where brandid=?";
               stmt=con.prepareStatement(sql);
               stmt.setLong(1,brandid);
               rs=stmt.executeQuery();
               str="";
  
               if(rs.next())
               {
                    str=rs.getString("brandname");
               }
               stmt.close();
          }
          finally {
               if(stmt!=null) stmt.close();
          }
          return str;
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -