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

📄 db_oracle.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.db;

import java.sql.*;

import oracle.jdbc.*;
import oracle.sql.*;

/**
 *  Oracle Database Port
 *
 *  @author     Jorg Janke
 *  @version    $Id: DB_Oracle.java,v 1.15 2002/10/21 04:42:35 jjanke Exp $
 */
public class DB_Oracle implements CompiereDatabase
{
	/**
	 *  Oracle Database
	 */
	public DB_Oracle()
	{
	}   //  DB_Oracle

	/** Static Driver           */
	private OracleDriver        s_driver = new OracleDriver();

	/** Default Port            */
	public static final int DEFAULT_PORT = 1521;
	/** Default Connection Manager Port */
	public static final int DEFAULT_CM_PORT = 1630;

	/** Connection String       */
	private String          	m_connectionURL;

	/**
	 *  Get Database Name
	 *  @return database short name
	 */
	public String getName()
	{
		return Database.DB_ORACLE;
	}   //  getName

	/**
	 *  Get Database Description
	 *  @return database long name and version
	 */
	public String getDescription()
	{
		return s_driver.toString();
	}   //  getDescription

	/**
	 *  Get Standard JDBC Port
	 *  @return standard port
	 */
	public int getStandardPort()
	{
		return DEFAULT_PORT;
	}   //  getStandardPort

	/**
	 *  Get Database Driver
	 *  @return Driver
	 */
	public Driver getDriver()
	{
		return s_driver;
	}   //  getDriver

	/**
	 *  Get Database Connection String.
	 *  <pre>
	 *  Timing:
	 *  - CM with source_route not in address_list  = 28.5 sec
	 *  - CM with source_route in address_list      = 58.0 sec
	 *  - direct    = 4.3-8 sec  (no real difference if on other box)
	 *  - bequeath  = 3.4-8 sec
	 *  </pre>
	 *  @param connection Connection Descriptor
	 *  @return connection String
	 */
	public String getConnectionURL (CConnection connection)
	{
		StringBuffer sb = null;
		//  Server Connections (bequeath)
		if (connection.isBequeath())
		{
			sb = new StringBuffer ("jdbc:oracle:oci8:@");
			//  bug: does not work if there is more than one db instance - use Net8
		//	sb.append(connection.getDbName());
		}
		else        //  thin driver
		{
			sb = new StringBuffer ("jdbc:oracle:thin:@");
			//  direct connection
			if (connection.isViaFirewall())
			{
				//  (description=(address_list=
				//  ( (source_route=yes)
				//    (address=(protocol=TCP)(host=cmhost)(port=1630))
				//    (address=(protocol=TCP)(host=dev)(port=1521))
				//  (connect_data=(service_name=dev1.compiere.org)))
				sb.append("(DESCRIPTION=(ADDRESS_LIST=")
					.append("(SOURCE_ROUTE=YES)")
					.append("(ADDRESS=(PROTOCOL=TCP)(HOST=").append(connection.getFwHost())
						.append(")(PORT=").append(connection.getFwPort()).append("))")
					.append("(ADDRESS=(PROTOCOL=TCP)(HOST=").append(connection.getDbHost())
						.append(")(PORT=").append(connection.getDbPort()).append(")))")
					.append("(CONNECT_DATA=(SERVICE_NAME=").append(connection.getDbName()).append(")))");
			}
			else
			{
				//  dev:1521:dev1
				sb.append(connection.getDbHost())
					.append(":").append(connection.getDbPort())
					.append(":").append(connection.getDbName());
			}
		}
		m_connectionURL = sb.toString();
		return m_connectionURL;
	}   //  getConnectionString

	/**
	 *  Supports BLOB
	 *  @return true if BLOB is supported
	 */
	public boolean supportsBLOB()
	{
		return true;
	}   //  supportsBLOB

	/**
	 *  String Representation
	 *  @return info
	 */
	public String toString()
	{
		StringBuffer sb = new StringBuffer("DB_Oracle[");
		sb.append(m_connectionURL)
			.append("]");
		return sb.toString();
	}   //  toString

	/*************************************************************************/

	/**
	 *  Convert an individual Oracle Style statements to target database statement syntax.
	 *  NOP
	 *  @param oraStatement oracle statement
	 *  @return converted Statement oracle statement
	 *  @throws Exception
	 */
	public String convertStatement (String oraStatement)
	{
		return oraStatement;
	}   //  convertStatement

	/*************************************************************************/

	/**
	 *  Set the RowID
	 *  @param pstmt statement
	 *  @param pos position in result set
	 *  @param rowID ROWID
	 *  @throws SQLException
	 */
	public void setRowID (PreparedStatement pstmt, int pos, Object rowID) throws SQLException
	{
		((OraclePreparedStatement)pstmt).setROWID (pos, (ROWID)rowID);
	}   //  setRowID

	/**
	 *  Get the RowID
	 *  @param rs result set
	 *  @param pos psoition in result set
	 *  @return rowID ROWID
	 *  @throws SQLException
	 */
	public Object getRowID (ResultSet rs, int pos) throws SQLException
	{
		return ((OracleResultSet)rs).getROWID (pos);
	}   //  getRowID

	/*************************************************************************/

	/**
	 * 	Testing
	 * 	@param args ignored
	 */
	public static void main (String[] args)
	{
		//	Connection option 1
		try
		{
			System.setProperty("oracle.jdbc.Trace", "true");
			DriverManager.registerDriver(new OracleDriver());
			Connection con = DriverManager.getConnection("jdbc:oracle:thin:@dev:1521:dev", "compiere", "compiere");
			System.out.println("Catalog=" + con.getCatalog());
			DatabaseMetaData md = con.getMetaData();
			System.out.println("URL=" + md.getURL());
			System.out.println("User=" + md.getUserName());
			//
			System.out.println("Catalog");
			ResultSet rs = md.getCatalogs();
			while (rs.next())
				System.out.println("- " + rs.getString(1));
			//
			System.out.println("Table");
			rs = md.getTables(null, "COMPIERE", null, new String[] {"TABLE"});
			while (rs.next())
				System.out.println("- User=" + rs.getString(2) + " | Table=" + rs.getString(3)
					+ " | Type=" + rs.getString(4) + " | " + rs.getString(5));
			//
			System.out.println("Column");
			rs = md.getColumns(null, "COMPIERE", "C_ORDER", null);
			while (rs.next())
				System.out.println("- Tab=" + rs.getString(3) + " | Col=" + rs.getString(4)
					+ " | Type=" + rs.getString(5) + ", " + rs.getString(6)
					+ " | Size=" + rs.getString(7) + " | " + rs.getString(8)
					+ " | Digits=" + rs.getString(9) + " | Radix=" + rs.getString(10)
					+ " | Null=" + rs.getString(11) + " | Rem=" + rs.getString(12)
					+ " | Def=" + rs.getString(13) + " | " + rs.getString(14)
					+ " | " + rs.getString(15) + " | " + rs.getString(16)
					+ " | Ord=" + rs.getString(17) + " | Null=" + rs.getString(18)
					);

			con.close();
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
		}
	}	//	main
}   //  DB_Oracle

⌨️ 快捷键说明

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