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

📄 booktype.java

📁 用JDK做的图书类型管理.通过jdk+Access实现
💻 JAVA
字号:
/**
   @forlink 2006-2

*/

import java.sql.*;

public class BookType 
{ 
   private Statement bookT;
   private String id;   /*书架类型的唯一标识,对应数据库的ID*/
   private String name; /* 图书类型名*/
   
   
   public  BookType() 
   {   
	   
   }   

   /**
   Access method for the id property.   
   @return the current value of the id property
    */
   public String getId() 
   {
	  return id;
   }
   
   /**
   Sets the value of the id property.   
   @param aId the new value of the id property
    */
   public void setId(String aId) 
   {
      id = aId;
   }
   
   /**
   Access method for the name property.   
   @return   the current value of the name property
    */
   public String getName() 
   {
	   return name;
   }
   
   /**
   Sets the value of the name property.   
   @param aName the new value of the name property
    */
   public void setName(String aName) 
   {
      name = aName;
   }   

  
   
   static int mode = 1;
   static String sID = "TP312";
   static String sName = "计算机";    
	 
   /**
     书架查询
   */
   public void SelectBT(int Mode)
   {
	   mode = Mode;
	   sID = id;
	   sName = name;
		try
		 {
			 DbConnect driver = new DbConnect();
			 BookType  query = new BookType ();
			 ResultSet rs;
			 String sqlCommand = "";
			 driver.setURL("jdbc:odbc:book");
			 driver.setUser("");
			 driver.setPassword("");
			 Connection con = driver.getConnection();
			 query.setStatement(con);
			 
			 if(mode == 1)            /*按ID查询*/
		     {
			    sqlCommand = "select * from BookType where id = '" + sID + "'" ; 
			 }
		     else
			     if(mode == 2)       /*按name查询*/
		         {
			         sqlCommand = "select * from BookType where name = '" + sName + "'";
			     }
		   
		      rs = query.executeQuery(sqlCommand);
			  rs.next();
			  System.out.println("查询结果如下:");
			  System.out.println("ID \t" + "Name \t\t" + "valid_flag" + "\t" + "UpDate_time");
			  for(int i = 0; i<rs.getRow(); i++)
		      {
				  System.out.println(rs.getString("id") + "\t" + rs.getString("name") +"\t\t" +
					  rs.getString("valid_flag") + "\t" + rs.getString("update_time"));
			      rs.next();
		      }
			  rs.close();
			  query.closeStatement();
			  con.close();
		  }
		  catch (Exception e)
		  {
		      System.out.println(e.toString());
	      }
	 }
	 
	 public void setStatement(Connection con)
	 {
	     try
	     {
		   	   this.bookT = con.createStatement(); 
		 }
		 catch (Exception e)
	     {
		      System.out.println(e.toString());
	     }
	  }

	  public ResultSet executeQuery(String sqlCommand)
	  {
		  try
		  {
		   	   return bookT.executeQuery(sqlCommand); 
		  }
		  catch (Exception e)
	      {
		       System.out.println(e.toString());
	      }
		  return null;
	  }

	  public void closeStatement()
	  {
	      try
		  {
		   	   bookT.close(); 
		  }
		  catch (Exception e)
	      {
		       System.out.println(e.toString());
	      }
	  }
	  
	  
	/**
	  书架更新
	*/

    static String uID="" ;
    static String uName="" ;
	public void UpdateBT(String id,String name)
    {
        uID=id ;
        uName=name ;
        try 
        {
            DbConnect driver=new DbConnect();
            BookType  update=new BookType ();
            ResultSet rs;
            String sqlCommand;
            driver.setURL("jdbc:odbc:book");
            driver.setUser("");
            driver.setPassword("");
            Connection con=driver.getConnection();
            update.setStatement(con);
            
            sqlCommand="UPDATE BookType SET name='"+uName+"' where id ='"+uID+"'";
		   	rs=update.executeQuery(sqlCommand);
			
			sqlCommand = "select * from BookType" ;
			rs=update.executeQuery(sqlCommand);
			rs.next();
			System.out.println("更新结果如下:");
			System.out.println("ID \t" + "Name \t\t" + "valid_flag" + "\t" + "UpDate_time");
			for(int i = 0; i<rs.getRow(); i++)
		    {
				  System.out.println(rs.getString("id") + "\t" + rs.getString("name") +"\t\t" +
					  rs.getString("valid_flag") + "\t" + rs.getString("update_time"));
			      rs.next();
		    }
			
            rs.close();
            update.closeStatement();
            con.close();
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
    }
}

⌨️ 快捷键说明

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