【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????????????

    上一篇:SSH协议和Telnet协议远程登录 区别
    下一篇:【git2】ssh,减少commit次数

    发表评论

    最新留言

    初次前来,多多关照!
    [***.217.46.12]2026年06月09日 11时50分19秒