大龙的博客

常用链接

统计

最新评论

linux下远程连接oracle数据库

1.安装instantclient的相关包:

instantclient-basic-linux-x86-64-11.2.0.2.0.zip 基础包

 

instantclient-sdk-linux-x86-64-11.2.0.2.0.zip 使用c或perl连接db

  instantclient-sqlplus-linux-x86-64-11.2.0.2.0.zip sqlplus

2.设置环境变量

 

export PATH=/home/loganalysis/perlM/instantclient/instantclient_11_2:$PATH

export ORACLE_HOME=/home/loganalysis/perlM/instantclient/instantclient_11_2

export  LD_LIBRARY_PATH=/home/loganalysis/perlM/instantclient/instantclient_11_2

export  SQLPATH=/home/loganalysis/perlM/instantclient/instantclient_11_2:${SQLPATH}

export  TNS_ADMIN=/home/loganalysis/perlM/instantclient/instantclient_11_2:${TNS_ADMIN}

 

3.复制tnsnames.ora至/home/loganalysis/perlM/instantclient/instantclient_11_2

开始测试。 

  #!/usr/bin/perl 

use DBI; 
$dbname="bossdata"; 
$user="system"; 
$passwd="javama"; 
$dbh=""; 
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can't connect to database "; 
$sth=$dbh->prepare("select * from user_tables"); 
$sth->execute; 
while (@recs=$sth->fetchrow_array) { 
print $recs[0].":".$recs[1]."\n"; 

$dbh->disconnect; 
print "hello \n"; 

//测试通过。 

posted on 2011-11-15 02:42 大龙 阅读(2196) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理