當前位置:首頁 » 操作系統 » linuxc連接oracle資料庫連接

linuxc連接oracle資料庫連接

發布時間: 2023-05-19 22:35:54

linux C/C++用什麼連接oracle資料庫啊解決辦法

在Windows的控制面板中,查找ODBC數據源,配置一個能夠連接Oracle的數據源,並測試能夠成功連接。然後在VS中連接這個數據源即可。

㈡ 如何連接到linux上的oracle資料庫

裝好oracle資料庫,我們准備用PLsql Developer 這個軟體來連接伺服器的資料庫!

下面簡單介紹設置此軟體並連接oracle資料庫的方法:

一、下載並安裝好PLSQL Developer(綠色版的也可以);

二、下載並解壓

Oracle免安裝版的客戶端:

http://download.oracle.com/otn/nt/instantclient/112030/instantclient-basic-nt-11.2.0.3.0.zip



三、建立tns配置文件。
1、在解壓的:「nstantclient-basic-nt-11.2.0.3.0」文件夾的下面建文件夾,路徑像這樣「nstantclient-basic-nt-11.2.0.3.0 eidownadmin「,其實這個倒是無所謂的,只是看起來與服務端上的更接近而已,與文章後面的環境變數要對應。
2、拷貝服務端目錄「$ORACLE_HOME$ etworkadmin nsnames.ora」到客戶端的「nstantclient-basic-nt-11.2.0.3.0 eidownadmin「目錄,這個文件的內容如下:(也可自行建立)

  • # tnsnames.ora Network Configuration File: /home/oradb/oracle/proct/11.2.0/db_1/network/admin/tnsnames.ora

  • # Generated by Oracle configuration tools.

  • ORCL =

  • (DESCRIPTION =

  • (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))

  • (CONNECT_DATA =

  • (SERVER = DEDICATED)

  • (SERVICE_NAME = orcl.localdomain)

  • )

  • )

  • 復制代碼以上的代碼 做個簡要的介紹,本例中安裝在linux中的oracle資料庫,其環境配置如下:
  • ORACLE_BASE=/home/oradb/oracle

  • ORACLE_HOME=$ORACLE_BASE/proct/11.2.0/db_1

  • ORACLE_SID=orcl

  • PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

  • LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

  • LANG=C

  • 復制代碼拷貝到客戶端後,用記事本打開它,修改如下幾個參數:
  • # tnsnames.ora Network Configuration File: /home/oradb/oracle/proct/11.2.0/db_1/network/admin/tnsnames.ora

  • # Generated by Oracle configuration tools.

  • ORCL =

  • (DESCRIPTION =

  • (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))

  • (CONNECT_DATA =

  • (SERVER = DEDICATED)

  • (SERVICE_NAME = orcl.localdomain)

  • )

  • )

  • 復制代碼重要:以上除了HOST是伺服器ip外,其他三個紅字必須與服務端的這個文件一致,否則連接的時候將會導致ORA-12514錯誤。


  • 四、設置PLSQL Developer程序的oci庫路徑。

  • 運行PLSQL Developer程序,在彈出的登錄框點「取消」

  • 在菜單「工具-首選項」中的「連接」中,

    找到「Oracle主目錄名」,輸入

  • 解壓的:「nstantclient-basic-nt-11.2.0.3.0」文件夾的路徑 比如:

  • "D:PLSQLinstantclient_11_2"

  • 找到「OCI庫」,輸入

  • 解壓的:「nstantclient-basic-nt-11.2.0.3.0」文件夾下oci.dll文件的路徑,比如:

  • "D:PLSQLinstantclient_11_2oci.dll"

  • 如下圖:



  • 如果伺服器中的資料庫字元編碼是GBK則設置為:SIMPLIFIED CHINESE_CHINA.ZHS16GBK

  • 如果設置不對會亂碼。

  • 注意:設定了環境變數之後,要注銷或者重啟電腦生效。

㈢ linux下c++遠程連接oracle資料庫

你說的復合結構應該是結構體吧。若是舉個例子給你看看

/*
* sample2.pc
*
* This program connects to ORACLE, declares and opens a cursor,
* fetches the names, salaries, and commissions of all
* salespeople, displays the results, then closes the cursor.
*/
#include <stdio.h>
#include <sqlca.h>
#define UNAME_LEN 20
#define PWD_LEN 40
/*
* Use the precompiler typedef』ing capability to create
* null-terminated strings for the authentication host
* variables. (This isn』t really necessary--plain char *』s
* does work as well. This is just for illustration.)
*/
typedef char asciiz[PWD_LEN];
EXEC SQL TYPE asciiz IS STRING(PWD_LEN) REFERENCE;
asciiz username;
asciiz password;
struct emp_info
{
asciiz emp_name;
float salary;
float commission;
};
/* Declare function to handle unrecoverable errors. */
void sql_error();
main()
{
struct emp_info *emp_rec_ptr;
/* Allocate memory for emp_info struct. */
if ((emp_rec_ptr =
(struct emp_info *) malloc(sizeof(struct emp_info))) == 0)
{
fprintf(stderr, "Memory allocation error. ");
exit(1);
}
/* Connect to ORACLE. */
strcpy(username, "SCOTT");
strcpy(password, "TIGER");
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--");
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf(" Connected to ORACLE as user: %s ", username);
/* Declare the cursor. All static SQL explicit cursors
* contain SELECT commands. 』salespeople』 is a SQL identifier,
* not a (C) host variable.
*/
EXEC SQL DECLARE salespeople CURSOR FOR
SELECT ENAME, SAL, COMM FROM EMP WHERE JOB LIKE 』SALES%』;
/* Open the cursor. */
EXEC SQL OPEN salespeople;
/* Get ready to print results. */
printf(" The company』s salespeople are-- ");
printf("Salesperson Salary Commission ");
printf("----------- ------ ---------- ");
/* Loop, fetching all salesperson』s statistics.
* Cause the program to break the loop when no more
* data can be retrieved on the cursor.
*/
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
{
EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
printf("%-11s%9.2f%13.2f ", emp_rec_ptr->emp_name,emp_rec_ptr->salary, emp_rec_ptr->commission);
}
/* Close the cursor. */
EXEC SQL CLOSE salespeople;
printf(" Arrivederci. ");
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}
void sql_error(msg) char *msg;
{
char err_msg[512];
int buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf(" %s ", msg);
/* Call sqlglm() to get the complete text of the
* error message.
*/
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s ", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(1);
}

㈣ linux中連接Oracle資料庫報ORA-12514錯誤,找不到原因

服務沒有注冊到監聽上,請把下面命令執行結果貼出來

  1. cat /etc/hosts

  2. cat /opt/oracle/app/proct/11.2.0/dbhome_1/network/admin/listener.ora

  3. show parameter local_listener

  4. hostname

㈤ 如何在linux虛擬機上使用win7安裝的oracle資料庫

在linux虛擬機上使用win7安裝的oracle資料庫:
1.環境及安裝前規劃:虛擬機及OS如下
環境:VMware Wordstation ACE版 6.0.2
操作系統:OracleLinux-R5-U8-Server-i386-dvd 3.2G
操作系統下載地址:http://mirrors.dotsrc.org/oracle-linux/

安裝操作系統,這里需要注意的是磁碟空間要預留足夠。
我的規劃是:
虛擬機槐歷分配1024M內存,當然如果主機內存足夠,安裝時內存設置2048M可以更快。
虛擬機分配一塊磁碟,30G磁碟空間。
/boot 100M ext3
/ 20G ext3
swap 2048M
剩餘的近8G空間留著做ASM時用。
同時最好安裝系統時選擇凱明吵圖形模式安裝,直接安裝好圖形模式,比較省事。

2.OS的配置:
操作系統安裝好後,暫時需要配盯侍置以下內容
固定IP及DNS /etc/sysconfig/network-scripts/ifcfg-eth0
主機名 /etc/sysconfig/network
修改開機運行級別 /etc/inittab
關閉SELINUX /boot/grub/menu.lst
修改sshd_config,解決SSH超時自動斷開問題

login as: root
[email protected]'s password:
Last login: Wed Jun 5 09:11:26 2013
[root@oel-01 ~]# hostname
oel-01
[root@oel-01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970[PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0C:29:99:8B:C9
ONBOOT=yes
NETMASK=255.255.255.128
IPADDR=192.168.1.212
GATEWAY=192.168.1.254
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

[root@oel-01 ~]# cat /etc/resolv.conf
nameserver 222.88.88.88

[root@oel-01 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=oel-01

[root@oel-01 ~]# vi /etc/inittab
id:3:initdefault:

[root@oel-01 ~]# vi /boot/grub/menu.lst
在kernel 行末尾增加selinux=0關閉SELINUX。也可以在安裝完系統時的圖形配置界面中關閉。

[root@oel-01 ~]# cd /etc/ssh/
[root@oel-01 ssh]# grep "ClientAlive" sshd_config
#ClientAliveInterval 0
#ClientAliveCountMax 3
[root@oel-01 ssh]# cp sshd_configsshd_config.bak
[root@oel-01 ssh]# sed -i "s/#ClientAliveInterval 0/ClientAliveInterval 60/g" sshd_config
[root@oel-01 ssh]# grep "ClientAlive" sshd_config
ClientAliveInterval 60
#ClientAliveCountMax 3
[root@oel-01 ssh]# sed -i "s/#ClientAliveCountMax 3/ClientAliveCountMax 10/g" sshd_config
[root@oel-01 ssh]# grep "ClientAlive" sshd_config
ClientAliveInterval 60
ClientAliveCountMax 10

[root@oel-01 ssh]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]

到此應該將系統重啟,驗證以上各項配置是否生效。如生效,關機,在VMWARE中做快照
3.創建安裝ORACLE的用戶組

[root@oel-01 ~]# groupadd -g 1000 oinstall
[root@oel-01 ~]# groupadd -g 1031 dba
[root@oel-01 ~]# groupadd -g 1032 oper
[root@oel-01 ~]# useradd oracle
[root@oel-01 ~]# passwd oracle
Changing password for user oracle.
New UNIX password:
BAD PASSWORD: it is based on a dictionaryword
Retype new UNIX password:
passwd: all authentication tokens updatedsuccessfully.
[root@oel-01 ~]# usermod -g oinstall -Gdba,oper oracle
[root@oel-01 ~]# mkdir -p/u01/app/oracle/proct/11.2.0/dbhome_1
[root@oel-01 ~]# chown -R oracle:oinstall/u01/
[root@oel-01 ~]# chmod 775 /u01/
[root@oel-01 app]# pwd
/u01/app
[root@oel-01 app]# ls -al
total 16
drwxrwxr-x 4 oracle oinstall 4096 Jun 5 10:56 .
drwxrwxr-x 3 oracle oinstall 4096 Jun 5 10:55 ..
drwxrwxr-x 2 oracle oinstall 4096 Jun 5 10:55 oracle

4.掛載光碟,安裝軟體
[root@oel-01 ~]# cd /etc/yum.repos.d/
[root@oel-01 yum.repos.d]# ls
[root@oel-01 yum.repos.d]# viOEL_CDROM.repo
[root@oel-01 yum.repos.d]# catOEL_CDROM.repo
[OEL5.8]
name=oracle linux
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[root@oel-01 yum.repos.d]# cd /mnt/
[root@oel-01 mnt]# mkdir cdrom
[root@oel-01 mnt]# mount /dev/cdrom/mnt/cdrom
mount: block device /dev/cdrom iswrite-protected, mounting read-only
[root@oel-01 mnt]# ls
cdrom
[root@oel-01 mnt]# cd cdrom/
[root@oel-01 cdrom]# ls
blafdoc.css eula.py README-en.html Server
Cluster GPL RELEASE-NOTES-en supportinfo
ClusterStorage images RELEASE-NOTES-en.html TRANS.TBL
EULA isolinux RPM-GPG-KEY VT
eula.en_US README-en RPM-GPG-KEY-oracle
[[root@oel-01 Server]# pwd
/mnt/cdrom/Server
[root@oel-01 Server]# ls /etc/pki/rpm-gpg/
RPM-GPG-KEY RPM-GPG-KEY-fedora RPM-GPG-KEY-oracle
RPM-GPG-KEY-EL4 RPM-GPG-KEY-fedora-test
[root@oel-01 Server]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

開始安裝軟體
方法一:
[root@oel-01 Server]# yum -y install oracleasm-support-2.1.7-1.el5.i386.rpm
[root@oel-01 Server]# yum -y install readline-devel-5.1-3.el5.i386.rpm
[root@oel-01 Server]# yum -y install unixODBC
[root@oel-01 Server]# yum -y install make* gcc* glibc* compat-db* compat-gcc*compat-gcc* compat-libstdc++* compat-libstdc* openmotif* setarch*
[root@oel-01 Server]# yum -y install elfutils-libelf-devel-* lio-devel-0.3.106-5.i386.rpm sysstat-7.0.2-11.el5.i386.rpm unixODBC-devel-2.2.11-10.el5.i386.rpm
安裝rlwrap-0.37.tar.gz,這里我也是上傳上去的,這個軟體可以在網上自己找。
[root@oel-01 ~]# ls
anaconda-ks.cfg install.log rlwrap-0.37
Desktop install.log.syslog rlwrap-0.37.tar.gz
[root@oel-01 ~]# tar -zxvfrlwrap-0.37.tar.gz
[root@oel-01 rlwrap-0.37]# pwd
/root/rlwrap-0.37
[root@oel-01 rlwrap-0.37]# ./configure
[root@oel-01 rlwrap-0.37]# make
[root@oel-01 rlwrap-0.37]# make install

㈥ c連接oracle資料庫的連接語句

我只會在unix下面寫,嘿嘿win的我還不會呢。。
把代碼貼上。至於怎麼
編譯,再查查吧~
int
main()
{
EXEC
SQL
BEGIN
DECLARE
SECTION;
char
oc_passwd[101];
/*資料庫密碼*/
char
oc_userid[101];
/*資料庫用戶名*/
char
oc_dbname[101];
/*資料庫名*/
char
oc_coad[101];
EXEC
SQL
END
DECLARE
SECTION;
memset(oc_passwd,
0x00,
sizeof(oc_passwd));
memset(oc_userid,
0x00,
sizeof(oc_userid));
memset(oc_dbname,
0x00,
sizeof(oc_dbname));
/*取資料庫用戶名*/
strcpy(oc_userid,
"userid");
/*取資料庫用戶密碼*/
strcpy(oc_passwd,
"passwd")
;
/*取資料庫名*/
strcpy(oc_dbname,
"dbname");
EXEC
SQL
CONNECT
:oc_userid
IDENTIFIED
BY
:oc_passwd
USING
:oc_dbname;
if
(sqlca.sqlcode
!=
0)
{
printf("用戶名[%s]密碼[%s]資料庫[%s]\n",
oc_userid,
oc_passwd,
oc_dbname);
printf("連接資料庫失敗,sqlcode=%d\n",
sqlca.sqlcode);
return
-1;
}
/*讀table取coad欄位*/
memset(oc_coad,
0x00,
sizeof(oc_coad));
EXEC
SQL
SELECT
coad
INTO
:oc_coad
FROM
table
WHERE
1=1;
if
(sqlca.sqlcode
==
NORECORD)
{
printf("查詢無記錄\n");
return
-1;
}
else
if
(sqlca.sqlcode
!=
0)
{
printf("查詢失敗,sqlcode=%d\n",
sqlca.sqlcode);
return
-1;
}
return
0;
}

㈦ linux怎麼登陸oracle資料庫

×

loading..

資訊
安全
論壇
下載
讀書
程序開發
資料庫
系統
網路
電子書
微信學院
站長學院
QQ
手機軟體
考試

頻道欄目

SQL Server|
MySQL|
Oracle|
DB2|
Sybase|
其他綜合|
SQL教程|

登錄注冊

首頁 > 資料庫 > Oracle > 正文

連接Linux伺服器操作Oracle資料庫

2013-03-20 10:48:47
0個評論

收藏
我要投稿

連接Linux伺服器操作Oracle資料庫

由於項目已經上線,現場的資料庫伺服器不允許直接用Oracle的客戶端plsqldev.exe來連接,只能通過Linux伺服器的命令來操作。 以下是用SecureCRT 5.1客戶端連接Linux伺服器來操作Oracle資料庫:

1.連接到Linux伺服器(輸入伺服器的ip地址)

ssh 10.199.94.227

連接成功後會提示輸入密碼,輸入成功會提示。

2.切換到操作Oracle資料庫

su - oracle

切換成功會提示相關資料庫的實例。例如:oracle@linux-cg01:~>

3.切換到sqlplus操作

sqlplus /nolog

切換成功會提示相關的提示:例如:

SQL*Plus: Release 11.2.0.2.0 Proction on Thu Jan 19 11:19:48 2012

Copyright (c) 1982, 2010, Oracle. All rights reserved.

4.輸入資料庫的用戶名和密碼

conn personal/personal

5.會提示Connected.(連接成功),顯示 SQL> :

6.以下是相關的SQL語句操作:

(1) 查詢的語句後面要一定要加 ; ,否則不能執行查詢,相當於plsqldev.exe工具的命令窗口的操作

select *from newuseraccount (記得查詢的時候一定要加;)

select email,password from userreg where accountstype=1 and userstate=1;

(2)插入或更新的語句記得還要加提交語句,才能提交事務。相當於plsqldev.exe工具的命令窗口的操作。

update newuseraccount set address='address ' where userid=638 ;

commit ;

㈧ 怎麼在linux環境下通過c/c++語言連接oracle資料庫

推薦你使用pc語言,用這個編寫代碼很容易對資料庫oracle進行操作.各種操作都非常簡單.
例如:
EXEC SQL CONNECT :UserName IDENTIFIED BY :PassWord using :ServerName;
這樣一個簡單語句就可以實現連接資料庫.
EXEC SQL CALL insert_data_sms(:spnumber,:usernumber,:content,:flag,:priority,:spnode,:sequenid_sp,:iresult);
EXEC SQL COMMIT;/*提交事務*/
可調用存儲過程.
你可以找找這方便的書看看

㈨ linux怎樣連接oracle資料庫

Linux系統下可以用sqlplus命令連接oracle資料庫,方法如下:
sqlplus命令語法:
#sqlplus usr/pwd@//host:port/sid
#usr:用戶名
#pwd:密碼
#host:資料庫伺服器IP
#port:埠
#sid:資料庫標識符
sqlplus命令連接Oracle示例:
[oracle@mzl ~]$ sqlplus risenet/1@//192.168.130.99:1521/risenet
SQL*Plus: Release 10.2.0.1.0 - Proction on Mon Feb 18 15:53:34 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Proction
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Proction
#測試資料庫select查詢語句
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
risenet OPEN
SQL>

㈩ c程序通過什麼連接oracle

一般C語言連接oracle資料庫通過使用oracle提供的OCI介面和PROC編程介面兩種方式。
OCI方式純粹是一些函數介面。
PROC是oracle提供的一種C與ORACLE
SQL的混合編程。程序(以.pc為後綴)編好之後,使用oracle提供的proc預編譯程序,將pc文件編譯成c文件(這一過程,相當於將SQL轉換為OCI的介面),然後再使用c語言編譯器生成可以執行文件。
OCI方式不容易入門,它擁有大量的介面函數,要很快熟悉它,非常難。但OCI方式的編程效率很高。
porc方式簡單易用。可用於對性能要求不太高的項目。

熱點內容
liststringjava 發布:2025-04-23 02:56:18 瀏覽:406
asi源碼 發布:2025-04-23 02:46:45 瀏覽:576
小候編程 發布:2025-04-23 02:46:41 瀏覽:559
網路工程師使用哪些軟體寫腳本 發布:2025-04-23 02:28:43 瀏覽:458
c語言短路現象 發布:2025-04-23 02:23:54 瀏覽:302
可運行腳本怎麼寫 發布:2025-04-23 02:23:09 瀏覽:324
安卓死亡空間怎麼飛行 發布:2025-04-23 02:17:21 瀏覽:545
安卓機怎麼設置語音開機 發布:2025-04-23 02:08:01 瀏覽:485
mysql存儲過程事務控制 發布:2025-04-23 02:02:04 瀏覽:652
伺服器ip承載量 發布:2025-04-23 01:53:37 瀏覽:595