【C/C++10】天气APP_Oracle数据库安装,表操作,C语言操作Oracle数据库
发布日期:2021-04-30 21:01:37
浏览次数:113
分类:精选文章
本文共 4259 字,大约阅读时间需要 14 分钟。
??Oracle???C????
??Oracle??????????????????????????????Oracle???????????C???????
1. ??Oracle
1.1 ??swap???
???Oracle???????????swap????????????swap???????
????swap??
????free -m ??swap????????swap???
??dd if=/dev/zero of=/home/swap bs=1024 count=2048000 ??swap????swap??????swap??
??mkswap /home/swap ???????swap?????swap???
??swapon /home/swap ?swap????????/etc/fstab??
?????????swap??????????/etc/fstab ?????????/home/swap swap swap defaults 0 0
?????swap??
??swapoff /home/swap ????swap????????swap?? rm /home/swap?1.2 ????????????
??Oracle???????????????
????????
??yum install -y binutils* compat-libstdc* elfutils-libelf* gcc* glibc* ksh* libaio* libgcc* libstdc* make* sysstat* libXp* glibc-kernheaders????????
??/etc/sysctl.conf ??????????fs.file-max = 6815744fs.aio-max-nr = 1048576kernel.shmall = 2097152kernel.shmmax= 2147483648kernel.shmmni= 4096kernel.sem = 250 32000100 128net.ipv4.ip_local_port_range= 9000 65500net.core.rmem_default= 262144net.core.rmem_max= 4194304net.core.wmem_default = 262144net.core.wmem_max= 1048576
????????
??/etc/security/limits.conf ??????????oracle soft nproc 2047oracle hard nproc 16384oracle soft nofile 1024oracle hard nofile 65536oracle hard stack 10240
??PAM??
??session required /lib/security/pam_limits.so ? /etc/pam.d/login ???????????
??/etc/profile ??????????if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fifi
??selinux?????
- ??
/etc/selinux/config???selinux=disabled? - ?
/etc/inittab????????3????????
?????
??init 6 ? reboot ??????2. ??Oracle????
2.1 ??dba??oracle??
??dba?
??groupadd dba ??dba????oracle??
??useradd -n oracle -g dba -d /oracle ??oracle?????oracle????
??passwd oracle ??oracle??????3. ??????????
3.1 ????
?????
?Win????oracle11g1.tgz ?Linux? /tmp ???????
?root??????/ ?????tar zxvf /tmp/oracle11g.tgz
????????oracle?????
3.2 ?????
???????
??lsnrctl start ?????????dbstart ????????????????
????SQL??????????vi /oracle/home/bin/dbstart
?????
sqlplus / as sysdba &
??????
?? systemd ????/usr/lib/systemd/system/oracle.service??????[Unit]Description=Oracle RDBMS[Service]Type=simpleExecStart=/usr/bin/su - oracle -c "/oracle/home/bin/dbstart > /tmp/oracle.log"ExecReload=/usr/bin/su - oracle -c "/oracle/home/bin/dbrestart > /tmp/oracle.log"ExecStop=/usr/bin/su - oracle -c "/oracle/home/bin/dbshut > /tmp/oracle.log"RemainAfterExit=yes[Install]WantedBy=multi-user.target
????
??systemctl enable oracle ??Oracle???4. C????Oracle
4.1 ??OCI?????
Oracle???OCI?Oracle Call Interface?????C???????????????????????
#include#include // ?????struct connection { OCIEnv *env; OCISession *session;};// ????????connection conn;if (conn.connecttodb("scott/tiger@snorcl11g", "UTF-8") != 0) { printf("???????\n"); return -1;}// ??SQL??sqlstatement stmt(&conn);stmt.prepare("insert into goods values(:id, :name, :sal, :btime)");stmt.bindin(1, &id);stmt.bindin(2, &name);stmt.bindin(3, &sal);stmt.bindin(4, &btime);// ??SQL??if (stmt.execute() != 0) { printf("????\n"); return -1;}// ????conn.commit();
4.2 ??Makefile??
?????C?????Makefile?
# Oracle?????-INCL = -I$(ORACLE_HOME)/rdbms/public# Oracle?????-L = -L$(ORACLE_HOME)/lib -L.# OCI?-LIBS = -lclntsh# ????CFLAGS = -g -Wno-write-strings -Wno-unused-variable# ???????all: g++ $(CFLAGS) -o createtable createtable.cpp $(INCL) $(L) $(LIBS)# ??clean: rm -f * .o * .exe
5. ???
5.1 ???
sqlplus / as sysdba <
5.2 ????
#include#include struct goods { long id; char name[31]; double sal; char btime[20];};connection conn;sqlstatement stmt(&conn);// ??SQL??stmt.prepare("insert into goods values(:id, :name, :sal, :btime)");stmt.bindin(1, &id);stmt.bindin(2, &name);stmt.bindin(3, &sal);stmt.bindin(4, &btime);// ????for (int i = 1; i <= 10; ++i) { memset(&goods, 0, sizeof(goods)); goods.id = i; sprintf(goods.name, "??%d", i); goods.s = i * 2.11; memcpy(goods.btime, "2020-01-01 12:00:00", sizeof(goods.btime)); if (stmt.execute() != 0) { printf("????\n"); return -1; } printf("???%d?????\n", i);}conn.commit();
???????????Oracle???????C???Oracle?????????????????????????Oracle????????????
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2026年06月09日 11时50分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
php版本升级总结
2023-03-01
php版本微信公众号开发
2023-03-01
php版的微信公众号开发演示
2023-03-01
php生成html文件的多种方法介绍
2023-03-01
php生成二维码到图片上
2023-03-01
php生成二维码并下载图片(适应于框架)
2023-03-01
PHP生成及获取JSON文件的方法
2023-03-01
PHP生成唯一不重复的编号
2023-03-01
PHP生成器-动态生成内容的数组
2023-03-01
PHP的ip2long和long2ip升级函数
2023-03-01
php的web路径获取
2023-03-01
php的一些小笔记--字符串
2023-03-01
php的几种运行模式CLI、CGI、FastCGI、mod_php
2023-03-01
php的四大特性八大优势
2023-03-01
RabbitMQ
2023-03-01
PHP的威胁函数与PHP代码审计实战
2023-03-01
PHP的引用举例
2023-03-01
PHP相关代码
2023-03-01