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

📄 yoursqlstatement.java

📁 原创的DBMS 数据库! 功能很简单
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				int proindex=0;
				int propertyflag=0;
				int propertyflagset=0;
				int proindexset=0;
				for(int k=0;k<headnum;k++)
				{
					 char[] namece = new char[100]; 
					 char[] typece=new char[100];
				        for(int i = 0; i < namece.length; i++) 
				             namece[i] = randomAccessFile.readChar(); 
				        for(int i = 0; i < typece.length; i++) 
				        	typece[i] = randomAccessFile.readChar(); 
				        
				        name[k]=new String(namece).replace('\0', ' ');
				        type[k]=new String(typece).replace('\0', ' ');
				        if(name[k].startsWith(property))
					       {
					    	   propertyflag=ptemp;
					    	   proindex=k;
					       }
				        if(name[k].startsWith(propertyset))
					       {
					    	   propertyflagset=ptemp;
					    	   proindexset=k;
					       }
				        if(type[k].startsWith("int"))
				        	ptemp+=4;
				        if(type[k].startsWith("string"))
				        	ptemp+=200;
				        if(type[k].startsWith("double"))
				        	ptemp+=8;
				       
				}
				for(int i=0;i<filenum;i++)
				{
					String valueget="";
					randomAccessFile.seek(headlongth+i*filelongth+propertyflag);
					if(type[proindex].startsWith("int"))
					{
						valueget=Integer.toString(randomAccessFile.readInt());
					}
					if(type[proindex].startsWith("string"))
					{
						char[] vtemp=new char[100];
						for(int g=0;g<vtemp.length;g++)
						{
							vtemp[g]=randomAccessFile.readChar(); 
						}
						valueget=new String(vtemp).replace('\0', ' ');
					}
					if(type[proindex].startsWith("double"))
					{
						valueget=Double.toString(randomAccessFile.readDouble());
					}
					if(valueget.startsWith(propertyval))
					{
						randomAccessFile.seek(headlongth+i*filelongth+propertyflagset);
						if(type[proindexset].startsWith("int"))
						{
							randomAccessFile.writeInt(Integer.parseInt(propertysetval));
						}
						if(type[proindexset].startsWith("string"))
						{
							StringBuilder builder = null; 
						       if(propertysetval != null) 
						           builder = new StringBuilder(propertysetval); 
						       else    
						           builder = new StringBuilder(100); 
						       builder.setLength(100); 
						      String propertysetval2 = builder.toString(); 
							randomAccessFile.writeChars(propertysetval2);
						}
						if(type[proindexset].startsWith("double"))
						{
							randomAccessFile.writeDouble(Double.parseDouble(propertysetval));
						}
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(str.startsWith("delete")){
			
		      String tname=null,field=null,value=null;
		      int t_end,f_end,length=0,frontLength=0,headlength=0,filenum;
		      
		      t_end=str.indexOf("where");
		      f_end=str.indexOf("=");
		      
		      tname=str.substring(12,t_end-1);		      
		      field=str.substring(t_end+6,f_end);
		      value=str.substring(f_end+1);
		      
		      System.out.println("TABLE NAME:"+tname);
		      System.out.println("TABLE NAME:"+field);
		      System.out.println("TABLE NAME:"+value);
		      
		      File file = new File("E:/"+tname+".dbf");
				try {
					
					RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");				
				    RandomAccessFile randomAccessFile_2=new RandomAccessFile(file, "rw");
				    headlength=randomAccessFile.readInt();
					System.out.println("HEADLONGTH :"+headlength);
					int headnumce=randomAccessFile.readInt();
					System.out.println("HEADNUM :"+headnumce);
					System.out.println("FILELONGTH :"+randomAccessFile.readInt());
					filenum=randomAccessFile.readInt();
					System.out.println("FILENUM :"+filenum);
					
					String type[]=new String [headnumce];
					String field_name[]=new String[headnumce];
				   int size[]=new int[headnumce];
					for(int k=0;k<headnumce;k++)
					{
						 char[] namece = new char[100]; 
						 char[] typece=new char[100];
						 
					        for(int i = 0; i < namece.length; i++) 
					             namece[i] = randomAccessFile.readChar(); 
					        
					        for(int i = 0; i < typece.length; i++) 
					        	typece[i] = randomAccessFile.readChar(); 
					        
					     field_name[k]=new String(namece).replace('\0',' ');
					     type[k]=new String(typece).replace('\0', ' ');    
					     if(field_name[k].startsWith(field)){
					    	 
					           if(type[k].startsWith("int"))
					         {
					    	        Integer.parseInt(value);
					    	        size[k]=4;
					         }
					           else if(type[k].startsWith("double")){
					        	    Double.parseDouble(value);
					        	    size[k]=8;
					           }
					           else if(type[k].startsWith("string")){
					        	    size[k]=200;
					           }
					           else{
					        	   System.out.println("error: type!");
					           }
	
					     }
					}
				
//查找相应记录并且删除--------------------------------------------
			    File temp = new File("E:/"+"temp"+".dbf");
			   
			    RandomAccessFile tempFile=new RandomAccessFile(temp,"rw");
			    randomAccessFile.seek(0);
			    
			    for(int i=0;i<4;i++){
			    	tempFile.writeInt(randomAccessFile.readInt());
			    }
			    
			    for(int j=0;j<headnumce;j++){
			    	tempFile.writeChars(field_name[j]);
			        tempFile.writeChars(type[j]);
			       readChars(randomAccessFile);
			       readChars(randomAccessFile);
			    }
			  int num;
			    for(num=0;num<headnumce;num++){
			    		if(field_name[num].startsWith(field)){
			    	    break;  		     
			    		  }
			    }
			   
			    for(int xx=0;xx<num;xx++)
			    {
			    	frontLength+=size[xx];
			    }
			   for(int yy=0;yy<headnumce;yy++){
				   length+=size[yy];
			   }
			     randomAccessFile_2.seek(headlength);
			     randomAccessFile.seek(headlength);
			     int all=0;
			     int number=filenum;
			     while(filenum>0){
			    	     boolean flag=false;
			    	     for(int i1=0;i1<headnumce;i1++){
			    	    	 
			    	    	   if(type[i1].startsWith("int")){	
			    	    		   int tempInt=randomAccessFile.readInt();//!!!!!!!!!!!!!!!
			    	    		    if(field_name[i1].startsWith(field)){		    	    		    	
			    	    		          if(tempInt==Integer.parseInt(value)){
			    	    		       	  flag=true;
			    	    		       	  all++;
			    	    		         }
			    	    		   }
			    	    	   }
			    	    	   if(type[i1].startsWith("double")){
			    	    		   double tempDouble=randomAccessFile.readDouble();
			    	    		    if(field_name[i1].startsWith(field)){
			    	    		         
			    	    		          if(tempDouble==Double.parseDouble(value)){
			    	    		        	flag=true;
			    	    		        	all++;
			    	    		         }
			    	    		         
			    	    		   }
			    	    	   }
			    	    	   if(type[i1].startsWith("string")){
			    	    		   System.out.println("bjj"+"string");
			    	    		   String tempString=readChars(randomAccessFile);
			    	    		    if(field_name[i1].startsWith(field)){
			    	    		    	  
			    	    		          System.out.println("bjj"+tempString);
			    	    		          System.out.println(value);
			    	    		          if(tempString.startsWith(value)){
			    	    		        	flag=true;
			    	    		        	all++;
			    	    		         }
			    	    		         
			    	    		   }
			    	    	   }
			    	   }
			    	     if(flag==true){
			    	    	 for(int i2=0;i2<headnumce;i2++){
			    	    		 if(type[i2].startsWith("int")){
			    	    			 randomAccessFile_2.readInt();
			    	    		 }
			    	    		 if(type[i2].startsWith("double"))  {
			    	    			 randomAccessFile_2.readDouble();
			    	    		 }
			    	    		 if(type[i2].startsWith("string"))  {
			    	    			readChars(randomAccessFile_2);
			    	    			System.out.println("delete");
			    	    		 }
			    	    	 }
			    	     }
			    	     else{
			    	    	 for(int i3=0;i3<headnumce;i3++){
			    	    		 if(type[i3].startsWith("int")){
			    	    			 int tempInt=randomAccessFile_2.readInt();
			    	    			 tempFile.writeInt(tempInt);
			    	    			 System.out.println(tempInt);
			    	    		 }
			    	    		 if(type[i3].startsWith("double"))  {
			    	    			 double tempDouble=randomAccessFile_2.readDouble();
			    	    			 tempFile.writeDouble(tempDouble);
			    	    			 System.out.println(tempDouble);
			    	    		 }
			    	    		 if(type[i3].startsWith("string"))  {
			    	    			 String tempChars=readChars(randomAccessFile_2);
			    	    			tempFile.writeChars(tempChars);
			    	    			System.out.println(tempChars);
			    	    		 }
			    	    	 }
			    	     }
			    	   filenum--;
			    }
			     tempFile.seek(12);
			     int changefilenum=0;
			     changefilenum=tempFile.readInt();
			     tempFile.seek(12);
			     tempFile.writeInt(changefilenum-all);
			     
			     randomAccessFile_2.close();
			     randomAccessFile.close();
			     file.delete();
			     tempFile.close();
			     temp.renameTo(new File("E:/"+tname+".dbf"));
			    
				}catch(Exception e){
					e.printStackTrace();
				}
		}
		else if(str.startsWith("show table"))
		{
			int snum=0,fnum=0;
			//int headnum=0,headlongth=0;
			int strend=str.length();			
			String stemp="";
			snum=13;
			fnum=str.lastIndexOf(32,strend);
			if(fnum==strend-6){
				try   
				  {   				     
				  String   dir="E:/";  
				  File   f=new   File(dir);   
				  String[]   file=f.list();   
				  for(int   i=0;i<file.length;i++)   
				  {   
				  if(file[i].endsWith("dbf"))//此处可换成你想要的扩展名   
				  {   
				  System.out.println(file[i]);//此处可写成你想要的操作   
				    
				  }   
				  }   
				  }   
				  catch(Exception   e)   
				  {   
				  e.printStackTrace();   
				  }  
			}
			else{
				stemp=str.substring(fnum+1,strend);
				System.out.println("TABLE NAME :"+stemp);
				
				File file = new File("E:/"+stemp+".dbf");
				try {
					RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
					System.out.println("HEADLONGTH :"+randomAccessFile.readInt());				
					System.out.println("HEADNUM :"+randomAccessFile.readInt());
					System.out.println("FILELONGTH :"+randomAccessFile.readInt());			
					System.out.println("FILENUM :"+randomAccessFile.readInt());
					System.out.println("TABLE LENGTH :"+randomAccessFile.length());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		}
		return 0;
	}
	private String readChars(RandomAccessFile randomAccessfile) throws Exception{
		 
        char[] name = new char[100]; 
        for(int i = 0; i < name.length; i++) 
             name[i] = randomAccessfile.readChar(); 
        return new String(name).replace('\0', ' ');//去掉空白字符
}
	public int executeUpdate(String arg0, int arg1) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int executeUpdate(String arg0, int[] arg1) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int executeUpdate(String arg0, String[] arg1) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public Connection getConnection() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getFetchDirection() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getFetchSize() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public ResultSet getGeneratedKeys() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getMaxFieldSize() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getMaxRows() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public boolean getMoreResults() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean getMoreResults(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public int getQueryTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public ResultSet getResultSet() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getResultSetConcurrency() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getResultSetHoldability() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getResultSetType() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getUpdateCount() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public SQLWarning getWarnings() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isClosed() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isPoolable() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public void setCursorName(String arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setEscapeProcessing(boolean arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setFetchDirection(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setFetchSize(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setMaxFieldSize(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setMaxRows(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setPoolable(boolean arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setQueryTimeout(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public boolean isWrapperFor(Class arg0) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public Object unwrap(Class arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}

⌨️ 快捷键说明

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