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

📄 dyfiletable.java

📁 java 数据库连接通用源码 java 数据库连接通用源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.dyit.sql;

import com.dyit.net.*;
import java.util.*;
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
 
/* 
* DyFileTable  	ver 0.91  beginner 0.9
* author :zhanghan             
* write-time :2002.5.10
* debug-time: 2002.5.28 
* write for dyit-bsjs com
* function :  abstract blob table
*
* debug:0.91 change InputStream searchFile(DYDataSource ds) to InputStream searchFile(Connection con)
*		del  InputStream searchFile(DYDataSource ds,String rowid)
*		for  InputStream can't be holded when connection closed.
*	0.92  debug SQLupdate()  older sql lost the "column =" 
*/
/**提供对单个带有大文件类型字段的数据库表的 插入,修改,删除,查询
*<p>所有列变量都以string类型传入, Date型变量 有两种写法
*<p>"YYYY-MM-DD" 或 "YYYY-MM-DD hh24:mi:ss" 注意空格
*<p>注意 :实际数据库表中的日期 字段都要以"D_"开头,否则无法自动生成SQL语句
*
*/
public abstract class DyFileTable extends DYtable {


/**表中的blob字段的列的列值
*/
protected int blobset=-1;
private InputStream fin;
/**/
public void setFileValue(InputStream in)throws DyIOException,IOException{
	if(in==null||in.available()<=0)throw new DyIOException(" file data stream is not available. ");
	fin = in;
	}
/**设置全体列值
*@param String[] 列值 按构建顺序(如果库表中的列可以为空,该列可以缺项)
*@return int 0 设置成功,1失败
*/
public int setValues(java.lang.String[] Values){
	hColumn.clear();//update 2001-9-10 v0.98
	if(Values.length!=iTbColumn)return 1;
	for(int i=0;i<iTbColumn;i++)set(colName[i],Values[i]);
	return 0;
}
/**得到单条记录的插入语句
*<p>使用时可以将结果打印出来进行检查
*<p>但对于操作来说,该语句并不完整,因为大文件字段(blob)数据没有加入
*@return String 经过组合的SQL语句
*/
public String SQLinsert(){
	//String strsql = "insert into "+strTbName+" values(";
	if(blobset<0) return "blob column set error: have not set the blob column.";
	String strsql = " values(";//值
	String strsql1 = "(";//列
	Iterator iterCol = hColumn.keySet().iterator();
	if(!iterCol.hasNext()) return " no value set, please set values first.";
	while(iterCol.hasNext()){
		String stemp = (String)iterCol.next();	
		String stempValue = (String)hColumn.get(stemp);
		if((stempValue!=null&&!stempValue.equals(""))||stemp.equals(colName[blobset])){
			strsql1 = strsql1+stemp+",";
			if(stemp.indexOf("D_")!=-1){
				//表中日期数据以D_ 开头,对其格式化一下
				if(stempValue.indexOf(":")>0)
					strsql = strsql+"to_date('"+stempValue+"','yyyy-mm-dd hh24:mi:ss'), ";
				else	strsql = strsql+"to_date('"+stempValue+"','yyyy-mm-dd '), ";
				}
			else if(stemp.equals(colName[blobset])) strsql+=" empty_blob() , ";
			else strsql = strsql+"'"+stempValue+"' , ";
			}
		}
	strsql = "insert into "+strTbName+strsql1.substring(0,strsql1.lastIndexOf(","))+")"+strsql.substring(0,strsql.lastIndexOf(","))+")";
	return strsql;
	}
/**得到单条记录的修改语句
*使用时可以将结果打印出来进行检查
*@return String 经过组合的SQL语句
*/
public String SQLupdate(){
	return SQLupdate(null);
}
/**得到单条记录的修改语句
*使用时可以将结果打印出来进行检查
*@param String rowId   oracle数据库中的伪列的值,可以唯一标示一条记录。注意:该值应从数据库中查询出来
*@return String 经过组合的SQL语句
*@update 2001-8-29
*/
public String SQLupdate(String rowId){
	String sPrimaryKey = null;
	if(blobset<0)return "blob column set error: have not set the blob column.";
	if(rowId==null||rowId.equals("")){
		try{	sPrimaryKey = getPrmKeyCndtion();}
		catch(DySQLException e){
			return "主键的值不全,不能进行相关操作";
		}
	}
	else sPrimaryKey =" rowid ='"+rowId+"'";
	String strsql = "Update "+strTbName+" set ";
	Iterator iterCol = hColumn.keySet().iterator();
	if(!iterCol.hasNext()) return " no value set, please set values first.";
	while(iterCol.hasNext()){
		String stemp = (String)iterCol.next();
		String stempValue = (String)hColumn.get(stemp);
		if(stempValue!=null&&!stempValue.equals("")){
			if(stemp.indexOf("D_")!=-1){
				//表中日期数据以D_ 开头,对其格式化一下
				if(stempValue.indexOf(":")>0)
					strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd hh24:mi:ss'), ";
				else	strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd '), ";
				}
			else if(stemp.equals(colName[blobset])) strsql+=" empty_blob() , ";
			else strsql = strsql+stemp+"='"+stempValue+"' , ";
			}
	}
	
	strsql = strsql.substring(0,strsql.lastIndexOf(","))+" where "+sPrimaryKey;
	
	return strsql;
}
/**得到单条记录的删除语句
*使用时可以将结果打印出来进行检查
*@return String 经过组合的SQL语句
*/
public String SQLdel(){
	return SQLdel(null);
	}
/**得到单条记录的删除语句
*使用时可以将结果打印出来进行检查
*@param String rowId   oracle数据库中的伪列的值,可以唯一标示一条记录。注意:该值应从数据库中查询出来
*@return String 经过组合的SQL语句
*@update 2001-8-29
*/
public String SQLdel(String rowId){
	String sPrimaryKey = null;
	if(rowId==null||rowId.equals("")){
		try{		sPrimaryKey = getPrmKeyCndtion();}
		catch(DySQLException e){
			return "主键的值不全,不能进行相关操作";
		}
	}
	else sPrimaryKey =" rowid ='"+rowId+"'";
	String strsql = "delete from "+strTbName+" where "+sPrimaryKey;
	return strsql;
}
/**得到单条记录的查询语句
*使用时可以将结果打印出来进行检查
*@return String 经过组合的SQL语句
*@update 2001/8/7
*/
public String SQLsearch(){
	return SQLsearch(false);
	}
/**得到单条记录的查询语句
*使用时可以将结果打印出来进行检查(建议一定要检查)
*@param boolean bflag true 带有rowid 的查询语句 false 一般查询语句
*@return String 经过组合的SQL语句
*@update 2001/8/7
*/
public String SQLsearch(boolean bflag){
	String strsql = " , rowid ";
	String str = "";
	try{str = getSearchCols();//如果返回“*” 就不能加" rowid, "了,已经不能返回"*"了
	}catch(DySQLException e){
		e.printStackTrace();
		return " column values is not set ";		
	}
	if(bflag)strsql = "select "+str+strsql+" from "+strTbName+" where ";
	else strsql = "select "+str+" from "+strTbName+" where ";
	int iflag =0;
	Iterator iterCol = hColumn.keySet().iterator();
	while(iterCol.hasNext()){
		String stemp = (String )iterCol.next();
		String stempValue = (String)hColumn.get(stemp);
		if(stempValue!=null&&!stempValue.equals("")){
				if(stemp.indexOf("D_")!=-1){
				//表中日期数据以D_ 开头,对其格式化一下
					if(stempValue.indexOf(":")>0)
						strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd hh24:mi:ss') and ";
					else	strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd ') and ";
					}
				else strsql = strsql+stemp+"='"+stempValue+"' and ";
				iflag++;
			}
		}
	//hColumn有值 最后的strsql多余了 一个 "and" 
	if(iflag>0)strsql = strsql.substring(0,strsql.lastIndexOf("and"));
	//hColumn空值 最后的strsql多余 "where"
	else strsql = strsql.substring(0,strsql.lastIndexOf("where"));
	return strsql;
}
/**得到单条记录的大文件字段的sql语句
*使用时可以将结果打印出来进行检查(建议一定要检查)
*<p>用于插入和更新文件字段
*@param boolean bflag true 带有rowid 的查询语句 false 一般查询语句
*@return String 经过组合的SQL语句
*@update 2001/8/7
*/
protected String SQLsearchBlob(String rowid)throws DySQLException{
	if(blobset<0)throw new DySQLException("blob column set error: have not set the blob column.");
	String strsql = " select "+colName[blobset]+" from "+strTbName+" where ";
	int iflag =0;
	if(rowid!=null&& !rowid.equals(""))strsql+= " rowid ='"+rowid+"'";
	else{
		Iterator iterCol = hColumn.keySet().iterator();
		while(iterCol.hasNext()){
			String stemp = (String )iterCol.next();
			String stempValue = (String)hColumn.get(stemp);
			if(stempValue!=null&&!stempValue.equals("")){
					if(stemp.indexOf("D_")!=-1){
					//表中日期数据以D_ 开头,对其格式化一下
						if(stempValue.indexOf(":")>0)
							strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd hh24:mi:ss') and ";
						else	strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd ') and ";
						}
					else strsql = strsql+stemp+"='"+stempValue+"' and ";
					iflag++;
				}
			}
		
		//hColumn有值 最后的strsql多余了 一个 "and" 
		if(iflag>0)strsql = strsql.substring(0,strsql.lastIndexOf("and"));
		//hColumn空值 最后的strsql多余 "where"
		else strsql = strsql.substring(0,strsql.lastIndexOf("where"));
	}
	 
	return strsql;
}
/**更新单条记录的大文件字段的sql语句 
*使用时可以将结果打印出来进行检查(建议一定要检查)
*<p>用于插入和更新文件字段
*@param boolean bflag true 带有rowid 的查询语句 false 一般查询语句
*@return String 经过组合的SQL语句
*@update 2001/8/7
*/
protected String OracleSQLUpdateBlob(String rowid)throws DySQLException{
	if(blobset<0)throw new DySQLException("blob column set error: have not set the blob column.");
	String str = colName[blobset];//如果返回“*” 就不能加" rowid, "了
	String strsql = " select "+str+" from "+strTbName+" where ";
	int iflag =0;
	if(rowid!=null&& !rowid.equals(""))strsql+= " rowid ='"+rowid+"'";
	else{
		Iterator iterCol = hColumn.keySet().iterator();
		while(iterCol.hasNext()){
			String stemp = (String )iterCol.next();
			String stempValue = (String)hColumn.get(stemp);
			if(stempValue!=null&&!stempValue.equals("")){
					if(stemp.indexOf("D_")!=-1){
					//表中日期数据以D_ 开头,对其格式化一下
						if(stempValue.indexOf(":")>0)
							strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd hh24:mi:ss') and ";
						else	strsql = strsql+stemp+"=to_date('"+stempValue+"','yyyy-mm-dd ') and ";
						}
					else strsql = strsql+stemp+"='"+stempValue+"' and ";
					iflag++;
				}
			}
		
		//hColumn有值 最后的strsql多余了 一个 "and" 
		if(iflag>0)strsql = strsql.substring(0,strsql.lastIndexOf("and"));
		//hColumn空值 最后的strsql多余 "where"

⌨️ 快捷键说明

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