Last active
August 29, 2015 14:27
-
-
Save fivejjs/dbe660ce43f050a18402 to your computer and use it in GitHub Desktop.
jython 2.7.0 access Teradata with the modifed classPathHacker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### refer to https://gist.github.com/linkerlin/4654376#file-classpathhacker-py-L20 | |
### http://www.jython.org/jythonbook/en/1.0/appendixB.html#working-with-classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### author: Jinjun Sun | |
### email: jsunster@gmail.com | |
### refer to https://gist.github.com/linkerlin/4654376#file-classpathhacker-py-L20 | |
### refer to http://www.jython.org/jythonbook/en/1.0/appendixB.html#working-with-classpath | |
import java.sql as sql | |
import java.lang as lang | |
class classPathHacker : | |
import java.lang.reflect.Method | |
import java.io.File | |
import java.net.URL | |
import java.net.URLClassLoader | |
import jarray | |
@classmethod | |
def addFile(cls, s): | |
u = [i.toURL() for i in [cls.java.io.File(i) for i in s]] | |
sysloader = cls.java.lang.ClassLoader.getSystemClassLoader() | |
sysclass = cls.java.net.URLClassLoader | |
method = sysclass.getDeclaredMethod("addURL", [cls.java.net.URL]) | |
method.setAccessible(1) | |
cls.jarray.array(u, cls.java.lang.Object) | |
return [method.invoke(sysloader, ui) for ui in u] | |
urlStd = "jdbc:teradata://P/TMODE=ANSI,CHARSET=UTF8" | |
driver, user, passwd = ("com.teradata.jdbc.TeraDriver", 'your_username', 'your_pass') | |
classPathHacker.addFile([r'D:/Oracle/JDBC/tdgssconfig.jar', r'D:/Oracle/JDBC/terajdbc4.jar']) | |
lang.Class.forName(driver) | |
conStd = sql.DriverManager.getConnection(urlStd, user, passwd) | |
stmtStd = conStd.createStatement() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment