歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

如何在Linux環境下調試Java程序使用訪問Timesten

一.如何在linux環境下調試JAVA程序使用訪問timesten:

1.配置jdk環境變量:

上傳jdk-6u7-linux-i586.bin文件到/data0/目錄下,執行如下命令:
[root@ www.linuxidc.com data0]#chmod 777 jdk-6u7-linux-i586.bin
[root@ www.linuxidc.com data0]#./jdk-6u7-linux-i586.bin
[root@ www.linuxidc.com data0]# ln -sn /data0/jdk1.6.0_07/ /usr/java 前面為源,後面為目的
[root@ www.linuxidc.com 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@ www.linuxidc.com 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 <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...]Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system

[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

Copyright © Linux教程網 All Rights Reserved