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

📄 jdbcquery.java

📁 类似于ibatis的一个JDBC的封装包.只需要传入配置文件,即可使用.使用方法和Delphi的Ado类似
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @函数用途: 执行存储函数
	 * @参数列表: nIndex[参数的序号] strPara[参数值.都用String]
	 * @注意事项: 重载本函数是为给hibernate中调用存储过程提供便利
	 **************************************************************************/
	public String ExecuteFunc(Connection con, String strProcName,
				ArrayList listPara) throws SQLException
	{
		String strRet = "";
		//Connection con = null;
		CallableStatement proc = null;

		// 生成执行存储过程所需要的SQL语句
		String strSQL = "{ ?=call " + strProcName + " (";
		for (int i = 0; i < listPara.size(); i++)
		{
			if (i < listPara.size() - 1)
			{
				strSQL = strSQL + "?,";
			}
			else
			{
				strSQL = strSQL + "?";
			}
		}
		strSQL = strSQL + ") }";

		//执行存储函数并返回数据
		try
		{
			//con = getConnection();
			if (con != null)
			{
				proc = con.prepareCall(strSQL);
				proc.registerOutParameter(1, Types.VARCHAR);

				for (int i = 0; i < listPara.size(); i++)
				{
					String strPara = (String) listPara.get(i);
					proc.setString(i + 2, strPara);
				}

				proc.execute();
				strRet = proc.getString(1);
			}
		}
		finally
		{
			try
			{
				proc.close();
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}

			try
			{
				con.close();
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}

		return strRet;
	}



	/***************************************************************************
	 * @函数名称: Bof()
	 * @函数用途: 是否结果集first()
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public boolean Bof()
	{
		boolean boolRet = false;

		if (set_m != null)
		{
			try
			{
				if (set_m.isBeforeFirst())
				{
					boolRet = true;
				}
			}
			catch (Exception e)
			{
			}
		}

		return boolRet;
	}



	/***************************************************************************
	 * @函数名称: Eof()
	 * @函数用途: 是否结果集last()
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public boolean Eof()
	{
		boolean boolRet = true;

		if (set_m != null)
		{
			try
			{
				if (!set_m.isAfterLast())
				{
					boolRet = false;
				}
			}
			catch (Exception e)
			{
			}
		}

		return boolRet;
	}



	/***************************************************************************
	 * @函数名称: RowCount()
	 * @函数用途: 集合的行个数
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public int RowCount()
	{
		int nRet = 0;

		try
		{
			nRet = set_m.size();
		}
		catch (Exception e)
		{
		}

		return nRet;
	}



	/***************************************************************************
	 * @函数名称: Next()
	 * @函数用途: 结果集向下移动
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public boolean Next()
	{
		boolean boolRet = false;

		try
		{
			set_m.next();

			if (!Eof())
			{
				boolRet = true;
			}
		}
		catch (Exception e)
		{
		}

		return boolRet;
	}



	/***************************************************************************
	 * @函数名称: Prior()
	 * @函数用途: 结果集向上移动
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public boolean Prior()
	{
		boolean boolRet = false;

		try
		{
			set_m.previous();

			if (!Bof())
			{
				boolRet = true;
			}
		}
		catch (Exception e)
		{
		}

		return boolRet;
	}



	/***************************************************************************
	 * @函数名称: First()
	 * @函数用途: 结果集移动到顶端
	 * @参数列表:
	 * @注意事项:
	 **************************************************************************/
	public boolean First()
	{
		boolean boolRet = false;

		try
		{
			set_m.first();
			boolRet = true;
		}
		catch (Exception e)
		{
		}

		return boolRet;
	}



	/***************************************************************************
	 * @函数名称: Last()
	 * @函数用途: 结果集移动到底端
	 * @参数列表: 
	 * @注意事项: 
	 **************************************************************************/
	public boolean Last()
	{
		boolean boolRet = false;

		try
		{
			set_m.last();
			boolRet = true;
		}
		catch (Exception e)
		{
		}

		return boolRet;
	}



	/***************************************************************************
	 * @throws SQLException 
	 * @函数名称: getRetString()
	 * @函数用途: 获取结果集合中名字为strFieldName的值
	 * @参数列表: strFieldName结果集的字段名
	 * @注意事项:
	 **************************************************************************/
	public String getRetString(String strFieldName) throws SQLException
	{
		String strRet = set_m.getString(strFieldName);
		return strRet;
	}



	/****************************************************************************
	 * @throws SQLException 
	 * @函数名称: getRetInt
	 * @函数用途: 获取结果集中的结果,取整形
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public int getRetInt(String strFieldName) throws SQLException
	{
		int nRet = 0;

		String strRet = set_m.getString(strFieldName);
		nRet = Integer.parseInt(strRet);

		return nRet;
	}



	/****************************************************************************
	 * @throws SQLException 
	 * @函数名称: getRetFloat
	 * @函数用途: 获取
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public float getRetFloat(String strFieldName) throws SQLException
	{
		String strRet = set_m.getString(strFieldName);
		float fltRet = Float.parseFloat(strRet);

		return fltRet;
	}



	/****************************************************************************
	 * @函数名称: getRetDate
	 * @函数用途: 获取Date型的结果值
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public Timestamp getRetDate(String strFieldName) throws SQLException
	{
		String strRet = set_m.getString(strFieldName);
		Timestamp tsRet = Timestamp.valueOf(strRet);
		return tsRet;
	}



	/***************************************************************************
	 * @throws SQLException 
	 * @函数名称: getStringFields
	 * @函数用途: 用字段序号获取结果值.
	 * @参数列表: nIndex:结果集中的序号
	 * @注意事项:
	 **************************************************************************/
	public String getStringFields(int nIndex) throws SQLException
	{
		String strRet = set_m.getString(nIndex);
		return strRet;
	}



	/****************************************************************************
	 * @throws SQLException 
	 * @函数名称: getIntFields
	 * @函数用途: 读取整形的field
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public int getIntFields(int nIndex) throws SQLException
	{
		String strRet = set_m.getString(nIndex);
		int nRet = Integer.parseInt(strRet);

		return nRet;
	}



	/****************************************************************************
	 * @throws SQLException 
	 * @函数名称: getFloatFields
	 * @函数用途: 获取float形的field
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public float getFloatFields(int nIndex) throws SQLException
	{
		String strRet = set_m.getString(nIndex);
		float fltRet = Float.parseFloat(strRet);

		return fltRet;
	}



	/****************************************************************************
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws SQLException 
	 * @函数名称: main
	 * @函数用途: 主测试函数
	 * @参数列表:
	 * @注意事项:
	 
	 INSERT INTO T_TEST T(VALUE) VALUES('222')
	 INSERT INTO T_TEST T(VALUE) VALUES('333')
	 INSERT INTO T_TEST T(VALUE) VALUES('444')
	 ***************************************************************************/
	public static void main(String[] args) throws FileNotFoundException,
				IOException, SQLException
	{
		JDBCConPool jcp = null;
		JDBCQuery jqry = null;
		String strOut = "";

		try
		{
			//jcp = new JDBCConPool("D://JavaWork//VkTOOLS//smart.cnfg");
			jcp = new JDBCConPool("D://JavaWork//VkTOOLS//HSQL.config");
			jqry = new JDBCQuery(jcp);

			//jqry.setSQL("INSERT INTO T_TEST (VALUE) VALUES('111')");
			//jqry.Execute();
			jqry.addBatch("INSERT INTO T_TEST (VALUE) VALUES('111')");
			jqry.addBatch("INSERT INTO T_TEST (VALUE) VALUES('222')");
			jqry.executeBatch();

			jqry = new JDBCQuery(jcp);
			jqry.addBatch("INSERT INTO T_TEST (VALUE) VALUES('333')");
			jqry.addBatch("INSERT INTO T_TEST (VALUE) VALUES('444')");
			jqry.executeBatch();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			//jqry.Close();
			jcp.Close();
		}

		System.out.println(strOut);
	}



	public static void main3(String[] args) throws FileNotFoundException,
				IOException, SQLException
	{
		JDBCConPool jcp = null;
		JDBCQuery jqry = null;
		String strOut = "";

		try
		{
			jcp = new JDBCConPool("D://JavaWork//VkTOOLS//smart.cnfg");
			jqry = new JDBCQuery(jcp);

			ArrayList listPara = new ArrayList();
			listPara.add("13136129752");
			listPara.add("1015002");
			strOut = jqry.ExecuteFunc("MassSendSms.GetCommendSongList", listPara);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			jcp.Close();
		}

		System.out.println(strOut);
	}



	/****************************************************************************
	 * @函数名称: 
	 * @函数用途: 
	 * @参数列表:
	 * @注意事项:
	 ***************************************************************************/
	public static void main2(String[] args)
	{
		JDBCConPool jcp = null;
		JDBCQuery jqry = null;

		try
		{
			jcp = new JDBCConPool("D://JavaWork//VkTOOLS//smart.cnfg");
			jqry = new JDBCQuery(jcp);

			ArrayList listPara = new ArrayList();
			listPara.add("13136129752");
			listPara.add("1015002");
			listPara.add("回复或回拨 1东风破 2南风破 3西风破 4北风破 三元每首");
			listPara.add("1");
			//jqry.ExecuteProc("MassSendSms.SetMTScript", listPara);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			jcp.Close();
		}
	}
}

⌨️ 快捷键说明

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