知行合一

享受过程 漠视结果

导航

不用安装Oracle客户端

1 pl/sql developer

1.1 下载解压instantclient-basic-nt-12.1.0.2.0。

1.2 在其目录下新建Network/ADMIN/tnsnames.ora文件。

1.3 文件内容如下:

test = 
(DESCRIPTION = 
	(ADDRESS_LIST = 
	(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521)) 
	) 
	(CONNECT_DATA = 
	(SERVER = DEDICATED) 
	(SERVICE_NAME = orcl) 
	) 
) 

  

1.4 打开pl/sql developer,Tools->Preferences,配置【Oracle Home】和【OCI library】。

2 .net程序

2.1 从instantclient中复制以下三个文件到exe同目录,oci.dll、oraociei12.dll、oraons.dll。

2.2 using System.Data.OracleClient; 示例代码见下:

       string conStr = "Data Source=192.168.1.100:1521/orcl;User ID=zh;Password=123;Unicode=True";
            OracleConnection conn = new OracleConnection(conStr);
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
            }

  

3 java程序

3.1 项目中导入外部jar包 ojdbc6.jar

3.2 示例代码见下:

	public static void testOracle() {
		String driverName = "oracle.jdbc.driver.OracleDriver";
		String dbURL = "jdbc:oracle:thin:@192.167.100.8:1521:orcl";
		String userName = "zh";
		String userPwd = "123";

		try {
			Class.forName(driverName);
			Connection dbConn = DriverManager.getConnection(dbURL, userName,
					userPwd);
			System.out.println("连接数据库成功");

		} catch (Exception e) {
			e.printStackTrace();
			System.out.print("连接失败");
		}
	}

  

posted on 2017-03-14 13:54  项羽  阅读(166)  评论(0编辑  收藏  举报