1 pl/sql developerjava
1.1 下載解壓instantclient-basic-nt-12.1.0.2.0。sql
1.2 在其目錄下新建Network/ADMIN/tnsnames.ora文件。數據庫
1.3 文件內容以下:oracle
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】。.net
2 .net程序code
2.1 從instantclient中複製如下三個文件到exe同目錄,oci.dll、oraociei12.dll、oraons.dll。blog
2.2 using System.Data.OracleClient; 示例代碼見下:ci
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程序get
3.1 項目中導入外部jar包 ojdbc6.jarstring
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("鏈接失敗"); } }