这是一个图书管理系统源代码

源代码在线查看: datedb.java

软件大小: 423 K
上传用户: MOMO89752118
关键词: 图书管理 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package datebase;
				
				import date.*;
				import java.sql.*;
				import java.util.Vector;
				import exception.*;
				
				public class DateDB {
				
					protected DB db=null;
					
					public DateDB() throws Exception{
						super();
						// 取得DB的实例
						db=DB.getinstance();
					}
					
					//
					public void execute(DateBean date,String comand)throws Exception{	
						if(comand.equals("insert"))
							insert(date);
						else if(comand.equals("update"))
							update(date);
						else if(comand.equals("delet"))
							delet(date);
						else if(comand.equals("select"))
							select(date);
						else 
							throw new NoSuchSqlCommand("sql type is not exist");
						
					}
					public void insert(DateBean date) throws Exception{
						//String sql0="select "+date.getPK()+" from where "+date.getPK()+"='"+date.getPKValue()+"'";
						//ResultSet rs=db.select(sql0);
						//主键不能重复
						//if(rs.next()){
						//	date.setMessage("the primarykey is already exist");
						//	return ;
						//}
						String sql=getAddSql(date);
						db.insert(sql);
				
					}
					public void update(DateBean date)throws Exception{
						String sql=getUpdateSql(date);
						db.update(sql);
					}
					public void delet(DateBean date)throws Exception{
						String sql=getDeletSql(date);
						db.delet(sql);
						
					}
					public void select(DateBean date){
						
					}
					protected String getAddSql(DateBean date){
						//构造sql语句,下面是要用到的临时变量
						String metadate=null;
						String values=null;
						Vector vm=date.getMetaData();
						Vector vv=date.getMetaDataValue();
						//获得属性String
						if(vm!=null){
							int k=vm.size();
							metadate=(String)vm.elementAt(0);
							for(int i=1;i							{
								metadate=metadate+","+(String)vm.elementAt(i);
							}
						}
						//获得属性值String
						if(vv!=null){
							int k=vv.size();
							values="'"+(String)vv.elementAt(0)+"'";
							for(int i=1;i								values=values+","+"'"+(String)vv.elementAt(i)+"'";
							}	
						}
						//获得表名
						String table=date.getTableName();
						
						String sql="insert into "+table+"("+metadate+") "+"values("+values+")";
						
						return sql;
						
					}
					
					protected String getUpdateSql(DateBean date){
						String sql=null;
						String table=date.getTableName();
						String pk=date.getPK();
						String pkvalue=date.getPKValue();     ////////////////////////???????????????????
						Vector vm=date.getMetaData();
						Vector vv=date.getMetaDataValue();
						//构造更新的sql语句
						if(vv.size()==vm.size())
						{
							sql="update "+table+" set ";
							int k=vv.size();
							sql=sql+vm.elementAt(0)+"='"+vv.elementAt(0)+"' ";
							for(int i=1;i								sql=sql+","+vm.elementAt(i)+"='"+vv.elementAt(i)+"' ";
							}
							sql=sql+" where "+pk+"='"+pkvalue+"'";
						}
						
						return sql;
					}
					protected String getDeletSql(DateBean date){
						String sql=null;
						String table=date.getTableName();
						String pk=date.getPK();
						String pkvalue=date.getPKValue();
						sql="delete from "+table+" where "+pk+"='"+pkvalue+"'";
						return sql;
					}
				
					protected String getSelectSql(DateBean date){
						String sql=null;
						
						return sql;
					}
				
				
				}
							

相关资源