ODBC(不推荐)
要求:JDK<=1.7(jdk从1.8开始,删除了jdbc-odbc桥,所以odbc的驱动是用不了的,建议重新安装jdk1.7或者更低的版本)
# 方式1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:td16","dbc","dbc");
# 方式2
import sun.jdbc.odbc.JdbcOdbcDriver;
DriverManager.registerDriver(new JdbcOdbcDriver());
Connection conn = DriverManager.getConnection("jdbc:odbc:td16","dbc","dbc");
JDBC
依赖下载
https://downloads.teradata.com/download/connectivity/jdbc-driver
依赖安装
mvn install:install-file -DgroupId=com.teradata.jdbc -DartifactId=terajdbc4 -Dversion=17.00.00.02 -Dpackaging=jar -Dfile=terajdbc4.jar
依赖引入
<dependency>
<groupId>com.teradata.jdbc</groupId>
<artifactId>terajdbc4</artifactId>
<version>17.00.00.02</version>
</dependency>
配置
配置文件可从TTU目录获取(${TTU_HOME}\Teradata\Client\xx.xx\teragss\etc\TdgssUserConfigFile.xml)。
<?xml version="1.0" encoding="US-ASCII"?>
<!-- TDGSS User Configuration File -->
<!-- This file consists of five sections:
Header
LegalValues
Algorithms
GlobalQops
Mechanisms
-->
<TdgssConfigFile>
<Header
Version="1"
ConfigFileType="User">
</Header>
<!-- Mechanisms Section: This section puts it all together; what
mechanisms are available and what QOPs each supports. -->
<Mechanisms>
<!-- One entry for each supported mechanism goes here -->
<!-- Teradata Method 1 has been DEPRECATED.
You may still use the TD1 security mechanism by copying the
TD1 configuration settings from TdgssLibraryConfigFile.xml to
this file, and then modify them to enable TD1.
However, it is not recommended.
-->
<!-- Teradata Method 2 (uses AES) -->
<Mechanism Name="TD2">
<!-- DHKeyP and DHKeyG are for legacy (pre-14.0) use only -->
<MechanismProperties
AuthenticationSupported="no"
AuthorizationSupported="no"
MechanismEnabled="yes"
MechanismRank="20"
DefaultMechanism="no"
DelegateCredentials="no"
MutualAuthentication="yes"
ReplayDetection="yes"
OutOfSequenceDetection="yes"
ConfidentialityDesired="yes"
IntegrityDesired="yes"
AnonymousAuthentication="no"
DesiredContextTime=""
DesiredCredentialTime=""
CredentialUsage="0"
VerifyDHKey="no"
DHKeyP="E4BE0A78F54C4A0B17E7E9249A78BCC08868C17281D8463C880937853E73DDC787E41580A8AFE2594D984C9E0814C590790354ECCD1BE8EA85961E5E0974B32EFE178335F061E80189B4BDAA20F67B47"
DHKeyG="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
/>
<!-- Uncomment DHKeyP2048 and DHKeyG2048, move up directly under DHKEYG above
and modify to override the default values in TdgssLibraryConfigFile.xml
DHKeyP2048="8AB3F86E8D374B782F31DAD5F27D6AFDA30150C11A20CF6346712AE2D2C6B70A5B79D45D4C0C232A065B207B121B2C33E147B5983C38A1087F272703B0B839CBA6F71C5D0EB51EC890934EACF2C7DD2A1DF6F55E89B145A0359D35EF8FB6C561E157B13FF927A35E69963648614902B1034EF71197F545DEF3236244EADAE0689E624CF1245953630AE042BD797C4025E37C51D9F6CBDA0B2278FA7D5CA2D9CA930BE2968330C811A4BA4D0845333C0D62E3EE742154F6B62F2951CD8C73C43B5AA1C7819DEF1D7C9314411E465F8E4796666594AADE0AEB3F1256E5719E7AE54DD34FFDA949634E4A293C5BC60AF258BB9FE558086E83B3DD3D7491966DEE93"
DHKeyG2048="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
-->
<!-- To disable legacy (pre 14.0) security,
uncomment the MechQop Value="0" directly below. -->
<!-- LEGACY QOP
<MechQop Value="0"/>
-->
<!-- To update security uncomment one or more QOPs and edit. -->
<!-- DEFAULT QOP
<MechQop Value="Default">
AES-K128_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
AES-K192_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
AES-K256_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- LOW SECURITY QOP
<MechQop Value="Low">
AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- MEDIUM SECURITY QOP
<MechQop Value="Medium">
AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- HIGH SECURITY QOP
<MechQop Value="High">
AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
</Mechanism>
<!-- SSPI: Kerberos Compatability has been DEPRECATED.
You may still use the KRB5C security mechanism by copying the
KRB5C configuration settings from TdgssLibraryConfigFile.xml to
this file, and then modify them to enable KRB5C.
However, it is not recommended.
-->
<!-- SSPI: Kerberos -->
<Mechanism Name="KRB5">
<MechanismProperties
AuthenticationSupported="yes"
AuthorizationSupported="no"
MechanismEnabled="yes"
MechanismRank="40"
DefaultMechanism="no"
DelegateCredentials="yes"
MutualAuthentication="yes"
ReplayDetection="yes"
OutOfSequenceDetection="yes"
ConfidentialityDesired="yes"
IntegrityDesired="yes"
AnonymousAuthentication="no"
DesiredContextTime=""
DesiredCredentialTime=""
CredentialUsage="0"
/>
</Mechanism>
<!-- SSPI: NTLM Compatability has been DEPRECATED.
You may still use the NTLMC security mechanism by copying the
NTLMC configuration settings from TdgssLibraryConfigFile.xml to
this file, and then modify them to enable NTLMC.
However, it is not recommended.
-->
<!-- SSPI: NTLM has been DEPRECATED.
You may still use the NTLM security mechanism by copying the
NTLM configuration settings from TdgssLibraryConfigFile.xml to
this file, and then modify them to enable NTLM.
However, it is not recommended.
-->
<!-- SSPI: SPNEGO -->
<Mechanism Name="SPNEGO">
<MechanismProperties
AuthenticationSupported="yes"
AuthorizationSupported="no"
SingleSignOnSupported="yes"
DefaultMechanism="no"
MechanismEnabled="yes"
MechanismRank="65"
DelegateCredentials="yes"
MutualAuthentication="yes"
ReplayDetection="yes"
OutOfSequenceDetection="yes"
ConfidentialityDesired="yes"
IntegrityDesired="yes"
AnonymousAuthentication="no"
DesiredContextTime=""
DesiredCredentialTime=""
CredentialUsage="0"
/>
</Mechanism>
<!-- LDAPv3 -->
<Mechanism Name="ldap">
<!-- DHKeyP and DHKeyG are for legacy (pre-14.0) use only -->
<MechanismProperties
AuthenticationSupported="yes"
AuthorizationSupported="no"
MechanismEnabled="yes"
MechanismRank="70"
DefaultMechanism="no"
DelegateCredentials="no"
MutualAuthentication="yes"
ReplayDetection="yes"
OutOfSequenceDetection="yes"
ConfidentialityDesired="yes"
IntegrityDesired="yes"
AnonymousAuthentication="no"
DesiredContextTime=""
DesiredCredentialTime=""
CredentialUsage="0"
VerifyDHKey="no"
DHKeyP="E4BE0A78F54C4A0B17E7E9249A78BCC08868C17281D8463C880937853E73DDC787E41580A8AFE2594D984C9E0814C590790354ECCD1BE8EA85961E5E0974B32EFE178335F061E80189B4BDAA20F67B47"
DHKeyG="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
LdapServerName=""
LdapServerPort="389"
LdapServerRealm=""
LdapSystemFQDN=""
LdapBaseFQDN=""
/>
<!-- Uncomment DHKeyP2048 and DHKeyG2048, move up directly under DHKEYG above
and modify to override the default values in TdgssLibraryConfigFile.xml
DHKeyP2048="8AB3F86E8D374B782F31DAD5F27D6AFDA30150C11A20CF6346712AE2D2C6B70A5B79D45D4C0C232A065B207B121B2C33E147B5983C38A1087F272703B0B839CBA6F71C5D0EB51EC890934EACF2C7DD2A1DF6F55E89B145A0359D35EF8FB6C561E157B13FF927A35E69963648614902B1034EF71197F545DEF3236244EADAE0689E624CF1245953630AE042BD797C4025E37C51D9F6CBDA0B2278FA7D5CA2D9CA930BE2968330C811A4BA4D0845333C0D62E3EE742154F6B62F2951CD8C73C43B5AA1C7819DEF1D7C9314411E465F8E4796666594AADE0AEB3F1256E5719E7AE54DD34FFDA949634E4A293C5BC60AF258BB9FE558086E83B3DD3D7491966DEE93"
DHKeyG2048="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
-->
<!-- To disable legacy (pre 14.0) security,
uncomment the MechQop Value="0" directly below. -->
<!-- LEGACY QOP
<MechQop Value="0"/>
-->
<!-- To update security uncomment one or more QOPs and edit. -->
<!-- DEFAULT QOP
<MechQop Value="Default">
AES-K128_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
AES-K192_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
AES-K256_GCM_PKCS5Padding_SHA2_DH-K2048
AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- LOW SECURITY QOP
<MechQop Value="Low">
AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- MEDIUM SECURITY QOP
<MechQop Value="Medium">
AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
<!-- HIGH SECURITY QOP
<MechQop Value="High">
AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
</MechQop>
-->
</Mechanism>
<!-- TDNEGO: Teradata Negotiated Method -->
<!-- To modify TDNEGO configuration, uncomment this
section and edit
<Mechanism Name="TDNEGO">
<MechanismProperties
MechanismEnabled="yes"
DefaultMechanism="no"
DefaultNegotiatingMechanism="no"
MechanismRank="10"
/>
<NegotiatedMechanism ObjectId="1.2.840.113554.1.2.2" Enable="yes"/>
<NegotiatedMechanism ObjectId="1.3.6.1.4.1.191.1.1012.1.20" Enable="yes"/>
<NegotiatedMechanism ObjectId="1.3.6.1.4.1.191.1.1012.1.1.9" Enable="yes"/>
</Mechanism>
(end of commented out section) -->
<!-- JWT -->
<!-- To modify JWT mechanism configuration, uncomment this section and edit
<Mechanism Name="JWT">
<MechanismProperties
MechanismEnabled="yes"
DefaultMechanism="no"
JWTDecryptionKeyFile=""
JWTVerificationKeyFile=""
JWTSkewTime="300"
/>
</Mechanism>
(end of commented out section)-->
</Mechanisms>
</TdgssConfigFile>
示例
1. Teradata Java Simple JDBC Demo
Class.forName("com.teradata.jdbc.TeraDriver");
Connection conn = DriverManager.getConnection("jdbc:teradata://192.168.136.128/dbc", "dbc", "dbc");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select khzhgxxlh,cjsj,gxsj from DIF_dev.DIF_KHKZGXB0527");
while (rs.next()) {
System.out.println(String.format("%s,%s,%s",rs.getString(1),rs.getString(2),rs.getString(3)));
}
rs.close();
stmt.close();
conn.close();
2. Teradata Java FastExport Demo
import java.sql.*;
public class TeradataFastExport {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.teradata.jdbc.TeraDriver");
String url = "jdbc:teradata://192.168.136.128/DATABASE=dbc,CHARSET=UTF8,TMODE=TERA,TYPE=FASTEXPORT,RECONNECT_COUNT=50";
Connection connection = DriverManager.getConnection(url, "dbc", "dbc");
PreparedStatement stmt = connection.prepareStatement("select khzhgxxlh,cjsj,gxsj from DIF_dev.DIF_KHKZGXB0527");
stmt.setFetchSize(100);
ResultSet rs = stmt.executeQuery();
int i = 1;
while (rs.next()) {
System.out.println(String.format("%d - %s", i++, rs.getObject(1)));
}
}
}