白天和黑夜只交替没交换无法想像对方的世界
分类: oracle
2012-03-08 23:59:38
一.如何在linux环境下调试java程序使用访问timesten:
1.配置jdk环境变量:
上传jdk-6u7-linux-i586.bin文件到/data0/目录下,执行如下命令:
[root@ora11gr2 data0]#chmod 777 jdk-6u7-linux-i586.bin
[root@ora11gr2 data0]#./jdk-6u7-linux-i586.bin
[root@ora11gr2 data0]# ln -sn /data0/jdk1.6.0_07/ /usr/java 前面为源,后面为目的
[root@ora11gr2 data0]# vim /etc/profile
在文件最后,添加如下三行:
export java_home=/data0/jdk1.6.0_07
export classpath=.:$java_home/lib:$java_home/jre/lib
export path=/usr/java/bin:$path
[root@ora11gr2 data0]# source /etc/profile
timesten用户环境变量文件~/.bash_profile下添加如下几行:
[timesten@ora11gr2 ~]$ vim ~/.bash_profile
#add timsten env
export oracle_sid=mytest
export nls_lang=american_america.zhs16gbk
export oracle_home=/app/oracle/product/11.2.0/db_1
export tt_home=/data0/timesten/timesten/tt1122
export tns_admin=/app/oracle/product/11.2.0/db_1/network/admin
export classpath=/data0/timesten/timesten/tt1122/lib/ttjdbc5.jar:/app/oracle/product/11.2.0/db_1/jdbc/lib/ojdbc5.jar:$classpath
export path=/data0/timesten/timesten/tt1122/bin/:$oracle_home/bin:$path
export ld_library_path=$oracle_home/lib:/usr/lib:$oracle_home/network/lib:/data0/timesten/timesten/tt1122/lib:$ld_library_path
[timesten@ora11gr2 ~]$ javac
usage: javac
[timesten@ora11gr2 ~]$ javac -version
javac 1.6.0_07
2.编写java测试代码:
[timesten@ora11gr2 ~]$ cat tttest.java
import java.sql.*;
import javax.sql.*;
public class tttest{
public static void main(string args[])
{
//string url = "jdbc:timesten:client:dsn=lujgcs_1122"; remote connect strings
string url = "jdbc:timesten:direct:dsn=lujg_1122";
connection con = null;
try {
class.forname("com.timesten.jdbc.timestendriver");
}
catch (classnotfoundexception ex)
{ex.printstacktrace();
}
try {
con = drivermanager.getconnection(url);
system.out.println("connected");
java.sql.statement st=con.createstatement();
java.sql.resultset rs=st.executequery("select * from test");
while (rs.next())
{
system.out.println(rs.getstring("id"));
}
con.close();
} catch (sqlexception ex) {
ex.printstacktrace();}
}
}
编译程序:
[timesten@ora11gr2 ~]$ javac tttest.java
[timesten@ora11gr2 ~]$ ll
-rw-r--r-- 1 timesten oinstall 1395 mar 8 10:13 tttest.class
-rwxr-xr-x 1 timesten oinstall 715 mar 8 10:13 tttest.java
查看执行结果:
[timesten@ora11gr2 ~]$ java tttest
connected
100
200
300