白天和黑夜只交替没交换无法想像对方的世界
分类: 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