ODBC(不推荐)

要求:JDK<=1.7(jdk从1.8开始,删除了jdbc-odbc桥,所以odbc的驱动是用不了的,建议重新安装jdk1.7或者更低的版本

  1. # 方式1
  2. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  3. Connection conn = DriverManager.getConnection("jdbc:odbc:td16","dbc","dbc");
  4. # 方式2
  5. import sun.jdbc.odbc.JdbcOdbcDriver;
  6. DriverManager.registerDriver(new JdbcOdbcDriver());
  7. Connection conn = DriverManager.getConnection("jdbc:odbc:td16","dbc","dbc");

JDBC

依赖下载

https://downloads.teradata.com/download/connectivity/jdbc-driver

依赖安装

  1. mvn install:install-file -DgroupId=com.teradata.jdbc -DartifactId=terajdbc4 -Dversion=17.00.00.02 -Dpackaging=jar -Dfile=terajdbc4.jar

依赖引入

  1. <dependency>
  2. <groupId>com.teradata.jdbc</groupId>
  3. <artifactId>terajdbc4</artifactId>
  4. <version>17.00.00.02</version>
  5. </dependency>

配置

配置文件可从TTU目录获取(${TTU_HOME}\Teradata\Client\xx.xx\teragss\etc\TdgssUserConfigFile.xml)。

  1. <?xml version="1.0" encoding="US-ASCII"?>
  2. <!-- TDGSS User Configuration File -->
  3. <!-- This file consists of five sections:
  4. Header
  5. LegalValues
  6. Algorithms
  7. GlobalQops
  8. Mechanisms
  9. -->
  10. <TdgssConfigFile>
  11. <Header
  12. Version="1"
  13. ConfigFileType="User">
  14. </Header>
  15. <!-- Mechanisms Section: This section puts it all together; what
  16. mechanisms are available and what QOPs each supports. -->
  17. <Mechanisms>
  18. <!-- One entry for each supported mechanism goes here -->
  19. <!-- Teradata Method 1 has been DEPRECATED.
  20. You may still use the TD1 security mechanism by copying the
  21. TD1 configuration settings from TdgssLibraryConfigFile.xml to
  22. this file, and then modify them to enable TD1.
  23. However, it is not recommended.
  24. -->
  25. <!-- Teradata Method 2 (uses AES) -->
  26. <Mechanism Name="TD2">
  27. <!-- DHKeyP and DHKeyG are for legacy (pre-14.0) use only -->
  28. <MechanismProperties
  29. AuthenticationSupported="no"
  30. AuthorizationSupported="no"
  31. MechanismEnabled="yes"
  32. MechanismRank="20"
  33. DefaultMechanism="no"
  34. DelegateCredentials="no"
  35. MutualAuthentication="yes"
  36. ReplayDetection="yes"
  37. OutOfSequenceDetection="yes"
  38. ConfidentialityDesired="yes"
  39. IntegrityDesired="yes"
  40. AnonymousAuthentication="no"
  41. DesiredContextTime=""
  42. DesiredCredentialTime=""
  43. CredentialUsage="0"
  44. VerifyDHKey="no"
  45. DHKeyP="E4BE0A78F54C4A0B17E7E9249A78BCC08868C17281D8463C880937853E73DDC787E41580A8AFE2594D984C9E0814C590790354ECCD1BE8EA85961E5E0974B32EFE178335F061E80189B4BDAA20F67B47"
  46. DHKeyG="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
  47. />
  48. <!-- Uncomment DHKeyP2048 and DHKeyG2048, move up directly under DHKEYG above
  49. and modify to override the default values in TdgssLibraryConfigFile.xml
  50. DHKeyP2048="8AB3F86E8D374B782F31DAD5F27D6AFDA30150C11A20CF6346712AE2D2C6B70A5B79D45D4C0C232A065B207B121B2C33E147B5983C38A1087F272703B0B839CBA6F71C5D0EB51EC890934EACF2C7DD2A1DF6F55E89B145A0359D35EF8FB6C561E157B13FF927A35E69963648614902B1034EF71197F545DEF3236244EADAE0689E624CF1245953630AE042BD797C4025E37C51D9F6CBDA0B2278FA7D5CA2D9CA930BE2968330C811A4BA4D0845333C0D62E3EE742154F6B62F2951CD8C73C43B5AA1C7819DEF1D7C9314411E465F8E4796666594AADE0AEB3F1256E5719E7AE54DD34FFDA949634E4A293C5BC60AF258BB9FE558086E83B3DD3D7491966DEE93"
  51. DHKeyG2048="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
  52. -->
  53. <!-- To disable legacy (pre 14.0) security,
  54. uncomment the MechQop Value="0" directly below. -->
  55. <!-- LEGACY QOP
  56. <MechQop Value="0"/>
  57. -->
  58. <!-- To update security uncomment one or more QOPs and edit. -->
  59. <!-- DEFAULT QOP
  60. <MechQop Value="Default">
  61. AES-K128_GCM_PKCS5Padding_SHA2_DH-K2048
  62. AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
  63. AES-K192_GCM_PKCS5Padding_SHA2_DH-K2048
  64. AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
  65. AES-K256_GCM_PKCS5Padding_SHA2_DH-K2048
  66. AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
  67. </MechQop>
  68. -->
  69. <!-- LOW SECURITY QOP
  70. <MechQop Value="Low">
  71. AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
  72. </MechQop>
  73. -->
  74. <!-- MEDIUM SECURITY QOP
  75. <MechQop Value="Medium">
  76. AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
  77. </MechQop>
  78. -->
  79. <!-- HIGH SECURITY QOP
  80. <MechQop Value="High">
  81. AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
  82. </MechQop>
  83. -->
  84. </Mechanism>
  85. <!-- SSPI: Kerberos Compatability has been DEPRECATED.
  86. You may still use the KRB5C security mechanism by copying the
  87. KRB5C configuration settings from TdgssLibraryConfigFile.xml to
  88. this file, and then modify them to enable KRB5C.
  89. However, it is not recommended.
  90. -->
  91. <!-- SSPI: Kerberos -->
  92. <Mechanism Name="KRB5">
  93. <MechanismProperties
  94. AuthenticationSupported="yes"
  95. AuthorizationSupported="no"
  96. MechanismEnabled="yes"
  97. MechanismRank="40"
  98. DefaultMechanism="no"
  99. DelegateCredentials="yes"
  100. MutualAuthentication="yes"
  101. ReplayDetection="yes"
  102. OutOfSequenceDetection="yes"
  103. ConfidentialityDesired="yes"
  104. IntegrityDesired="yes"
  105. AnonymousAuthentication="no"
  106. DesiredContextTime=""
  107. DesiredCredentialTime=""
  108. CredentialUsage="0"
  109. />
  110. </Mechanism>
  111. <!-- SSPI: NTLM Compatability has been DEPRECATED.
  112. You may still use the NTLMC security mechanism by copying the
  113. NTLMC configuration settings from TdgssLibraryConfigFile.xml to
  114. this file, and then modify them to enable NTLMC.
  115. However, it is not recommended.
  116. -->
  117. <!-- SSPI: NTLM has been DEPRECATED.
  118. You may still use the NTLM security mechanism by copying the
  119. NTLM configuration settings from TdgssLibraryConfigFile.xml to
  120. this file, and then modify them to enable NTLM.
  121. However, it is not recommended.
  122. -->
  123. <!-- SSPI: SPNEGO -->
  124. <Mechanism Name="SPNEGO">
  125. <MechanismProperties
  126. AuthenticationSupported="yes"
  127. AuthorizationSupported="no"
  128. SingleSignOnSupported="yes"
  129. DefaultMechanism="no"
  130. MechanismEnabled="yes"
  131. MechanismRank="65"
  132. DelegateCredentials="yes"
  133. MutualAuthentication="yes"
  134. ReplayDetection="yes"
  135. OutOfSequenceDetection="yes"
  136. ConfidentialityDesired="yes"
  137. IntegrityDesired="yes"
  138. AnonymousAuthentication="no"
  139. DesiredContextTime=""
  140. DesiredCredentialTime=""
  141. CredentialUsage="0"
  142. />
  143. </Mechanism>
  144. <!-- LDAPv3 -->
  145. <Mechanism Name="ldap">
  146. <!-- DHKeyP and DHKeyG are for legacy (pre-14.0) use only -->
  147. <MechanismProperties
  148. AuthenticationSupported="yes"
  149. AuthorizationSupported="no"
  150. MechanismEnabled="yes"
  151. MechanismRank="70"
  152. DefaultMechanism="no"
  153. DelegateCredentials="no"
  154. MutualAuthentication="yes"
  155. ReplayDetection="yes"
  156. OutOfSequenceDetection="yes"
  157. ConfidentialityDesired="yes"
  158. IntegrityDesired="yes"
  159. AnonymousAuthentication="no"
  160. DesiredContextTime=""
  161. DesiredCredentialTime=""
  162. CredentialUsage="0"
  163. VerifyDHKey="no"
  164. DHKeyP="E4BE0A78F54C4A0B17E7E9249A78BCC08868C17281D8463C880937853E73DDC787E41580A8AFE2594D984C9E0814C590790354ECCD1BE8EA85961E5E0974B32EFE178335F061E80189B4BDAA20F67B47"
  165. DHKeyG="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
  166. LdapServerName=""
  167. LdapServerPort="389"
  168. LdapServerRealm=""
  169. LdapSystemFQDN=""
  170. LdapBaseFQDN=""
  171. />
  172. <!-- Uncomment DHKeyP2048 and DHKeyG2048, move up directly under DHKEYG above
  173. and modify to override the default values in TdgssLibraryConfigFile.xml
  174. DHKeyP2048="8AB3F86E8D374B782F31DAD5F27D6AFDA30150C11A20CF6346712AE2D2C6B70A5B79D45D4C0C232A065B207B121B2C33E147B5983C38A1087F272703B0B839CBA6F71C5D0EB51EC890934EACF2C7DD2A1DF6F55E89B145A0359D35EF8FB6C561E157B13FF927A35E69963648614902B1034EF71197F545DEF3236244EADAE0689E624CF1245953630AE042BD797C4025E37C51D9F6CBDA0B2278FA7D5CA2D9CA930BE2968330C811A4BA4D0845333C0D62E3EE742154F6B62F2951CD8C73C43B5AA1C7819DEF1D7C9314411E465F8E4796666594AADE0AEB3F1256E5719E7AE54DD34FFDA949634E4A293C5BC60AF258BB9FE558086E83B3DD3D7491966DEE93"
  175. DHKeyG2048="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"
  176. -->
  177. <!-- To disable legacy (pre 14.0) security,
  178. uncomment the MechQop Value="0" directly below. -->
  179. <!-- LEGACY QOP
  180. <MechQop Value="0"/>
  181. -->
  182. <!-- To update security uncomment one or more QOPs and edit. -->
  183. <!-- DEFAULT QOP
  184. <MechQop Value="Default">
  185. AES-K128_GCM_PKCS5Padding_SHA2_DH-K2048
  186. AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
  187. AES-K192_GCM_PKCS5Padding_SHA2_DH-K2048
  188. AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
  189. AES-K256_GCM_PKCS5Padding_SHA2_DH-K2048
  190. AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
  191. </MechQop>
  192. -->
  193. <!-- LOW SECURITY QOP
  194. <MechQop Value="Low">
  195. AES-K128_CBC_PKCS5Padding_SHA1_DH-K2048
  196. </MechQop>
  197. -->
  198. <!-- MEDIUM SECURITY QOP
  199. <MechQop Value="Medium">
  200. AES-K192_CBC_PKCS5Padding_SHA1_DH-K2048
  201. </MechQop>
  202. -->
  203. <!-- HIGH SECURITY QOP
  204. <MechQop Value="High">
  205. AES-K256_CBC_PKCS5Padding_SHA1_DH-K2048
  206. </MechQop>
  207. -->
  208. </Mechanism>
  209. <!-- TDNEGO: Teradata Negotiated Method -->
  210. <!-- To modify TDNEGO configuration, uncomment this
  211. section and edit
  212. <Mechanism Name="TDNEGO">
  213. <MechanismProperties
  214. MechanismEnabled="yes"
  215. DefaultMechanism="no"
  216. DefaultNegotiatingMechanism="no"
  217. MechanismRank="10"
  218. />
  219. <NegotiatedMechanism ObjectId="1.2.840.113554.1.2.2" Enable="yes"/>
  220. <NegotiatedMechanism ObjectId="1.3.6.1.4.1.191.1.1012.1.20" Enable="yes"/>
  221. <NegotiatedMechanism ObjectId="1.3.6.1.4.1.191.1.1012.1.1.9" Enable="yes"/>
  222. </Mechanism>
  223. (end of commented out section) -->
  224. <!-- JWT -->
  225. <!-- To modify JWT mechanism configuration, uncomment this section and edit
  226. <Mechanism Name="JWT">
  227. <MechanismProperties
  228. MechanismEnabled="yes"
  229. DefaultMechanism="no"
  230. JWTDecryptionKeyFile=""
  231. JWTVerificationKeyFile=""
  232. JWTSkewTime="300"
  233. />
  234. </Mechanism>
  235. (end of commented out section)-->
  236. </Mechanisms>
  237. </TdgssConfigFile>

示例

1. Teradata Java Simple JDBC Demo

  1. Class.forName("com.teradata.jdbc.TeraDriver");
  2. Connection conn = DriverManager.getConnection("jdbc:teradata://192.168.136.128/dbc", "dbc", "dbc");
  3. Statement stmt = conn.createStatement();
  4. ResultSet rs = stmt.executeQuery("select khzhgxxlh,cjsj,gxsj from DIF_dev.DIF_KHKZGXB0527");
  5. while (rs.next()) {
  6. System.out.println(String.format("%s,%s,%s",rs.getString(1),rs.getString(2),rs.getString(3)));
  7. }
  8. rs.close();
  9. stmt.close();
  10. conn.close();

2. Teradata Java FastExport Demo

  1. import java.sql.*;
  2. public class TeradataFastExport {
  3. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  4. Class.forName("com.teradata.jdbc.TeraDriver");
  5. String url = "jdbc:teradata://192.168.136.128/DATABASE=dbc,CHARSET=UTF8,TMODE=TERA,TYPE=FASTEXPORT,RECONNECT_COUNT=50";
  6. Connection connection = DriverManager.getConnection(url, "dbc", "dbc");
  7. PreparedStatement stmt = connection.prepareStatement("select khzhgxxlh,cjsj,gxsj from DIF_dev.DIF_KHKZGXB0527");
  8. stmt.setFetchSize(100);
  9. ResultSet rs = stmt.executeQuery();
  10. int i = 1;
  11. while (rs.next()) {
  12. System.out.println(String.format("%d - %s", i++, rs.getObject(1)));
  13. }
  14. }
  15. }