代码示例:
try{
String driverName = "com.timesten.jdbc.TimesTenClientDriver"; // "sun.jdbc.odbc.JdbcOdbcDriver"
String Url = "jdbc:timesten:client:dsn=timestendb_1122"; //"jdbc:odbc:timestendb_1122";
if(args.length >= 2){
driverName = args[0];
Url = args[1];
}
System.out.println("driverName=" + driverName);
System.out.println("Url=" + Url);
System.out.println("classPath=" + System.getProperty("java.library.path"));
Class.forName(driverName).newInstance();
// Open a connection to TimesTen
Connection conn = DriverManager.getConnection(Url);
if(conn != null){
System.out.println("okay");
}
else{
System.out.println("fail");
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
odbc.ini 配置:
[ODBC Data Sources]
timestendb_11221=TimesTen 11.2.2 Driver
[timestendb_1122]
TTC_SERVER=(Host || IP)
UID=Username
PWD=Password
TTC_SERVER_DSN=Cachedb01
错误:java.sql.SQLException:加载本机库/缺少方法时出现问题:/opt/TimesTen/tt1122/lib/libttJdbcCS.so:libttclient.so:无法打开共享对象文件:没有这样的文件或目录
解决:
检查是否存在:
$ldd /opt/TimesTen/tt1122/lib/libttJdbcCS.so
屏幕:
linux-vdso.so.1 => (0x00007fff039b4000)
libttclient.so => not found
libttco.so => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f57d642e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f57d6218000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f57d5e58000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f57d5c53000)
/lib64/ld-linux-x86-64.so.2 (0x00007f57d6876000)
检查目录时间客户端:$ ll /opt/TimesTen/tt1122/lib/libttclient.so
转到文件以添加共享库:sudo vi /etc/ld.so.conf.d/extension.conf
-> 添加: /opt/TimesTen/tt1122/lib
再检查一遍
java -Djava.library.path=/opt/TimesTen/tt1122/lib -jar test1.jar
代码打印:
driverName=com.timesten.jdbc.TimesTenClientDriver
Url=jdbc:timesten:client:dsn=timestendb_1122
classPath=/opt/TimesTen/tt1122/lib
java.sql.SQLException: [TimesTen][TimesTen 11.2.2.5.0 CLIENT]Cannot find the requested DSN (timestendb_1122) in ODBCINI, Unable to open /var/TimesTen/tt1122/sys.odbc.ini. Permission denied
解决:
export ODBCINI=/etc/odbc.ini
(如果您使用 odbc 驱动程序)
export ODBCINI=/var/TimesTen/tt1122/sys.odbc.ini
(如果使用 Timesten 驱动程序)
可以为用户添加 bash 文件:
nano /home/nhatvd/.bashrc
export ODBCINI=/etc/odbc.ini
$ ldd /opt/TimesTen/tt1122/lib/libttJdbcCS.so
linux-vdso.so.1 => (0x00007fff429fe000)
libttclient.so => /opt/TimesTen/tt1122/lib/libttclient.so (0x00007fd7977ee000)
libttco.so => /opt/TimesTen/tt1122/lib/libttco.so (0x00007fd797520000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd797223000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd79700d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd796c4d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd796a48000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd796748000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd79652b000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fd796310000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd797b12000)
结果:
$ java -Djava.library.path=/opt/TimesTen/tt1122/lib -jar test1.jar
代码打印:
driverName=com.timesten.jdbc.TimesTenClientDriver
Url=jdbc:timesten:client:dsn=timestendb_1122
classPath=/opt/TimesTen/tt1122/lib
好的
完毕。