Nashorn ?? JDBC ? Oracle DB ?????·?? 2
- by Homma
????
Nashorn ?? JavaScript ??????? JDBC ? Oracle DB ?????????????????????????????????????JDBC ????????????????????????????????
???????????????????????????
????? URL ? https://blogs.oracle.com/nashorn_ja/entry/nashorn_jdbc_2 ???
????????? JDBC ?????
??????????????? ${ORACLE_HOME}/jdbc/lib/ojdbc6.jar ??????????????????????????? JDBC ??????????????
????? ojdbc6.jar ??????????????
??????????????????????????????????????
var OracleDataSource = Java.type("oracle.jdbc.pool.OracleDataSource");
var ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:test/test@dbsrv:1521:orcl");
var conn = ods.getConnection();
var meta = conn.getMetaData();
print("JDBC driver version is " + meta.getDriverVersion());
???????? JDBC ?????? jjs ????? -cp ??????????????????????
$ jjs -cp ojdbc6.jar version.js
JDBC driver version is 11.2.0.3.0
?????????????????????????????
JAR ????? Main Class ??????????????
????JDBC ????????????????????????????????
?????????java -jar ojdbc6.jar ?? JDBC ??????????????????
$ java -jar ojdbc6.jar
Oracle 11.2.0.3.0 JDBC 4.0 compiled with JDK6 on Thu_Jul_11_15:43:23_PDT_2013
#Default Connection Properties Resource
#Fri May 30 10:37:32 JST 2014
????? JAR ???????????? Main-Class ???????????? main(String[]) ??????????????????? Nashorn ??????????????
JAR ????? Main-Class ????
?? Main-Class ????????????
jar ????? JAR ?????????META-INF/MANIFEST.MF ???????????????? Main-Class ???????
$ jar xf ojdbc6.jar
$ grep Main-Class META-INF/MANIFEST.MF
Main-Class: oracle.jdbc.OracleDriver
Main-Class ? oracle.jdbc.OracleDriver ?????????????
Main-Class ???
??????? oracle.jdbc.OracleDriver ???? main ????? Nashorn ????????
$ jjs -cp ojdbc6.jar
jjs> var OracleDriver = Java.type("oracle.jdbc.OracleDriver");
jjs> var StringArray = Java.type("java.lang.String[]");
jjs> OracleDriver.main(new StringArray(0))
Oracle 11.2.0.3.0 JDBC 4.0 compiled with JDK6 on Thu_Jul_11_15:43:23_PDT_2013
#Default Connection Properties Resource
#Fri May 30 10:55:22 JST 2014
null
jjs>
java ????? JAR ???????????????????????????
Java ???????????????? Java.type() ??????? JavaClass ?????????????????????
???
Nashorn ????????????? JDBC ? Oracle DB ????????JAR ????? Main-Class ????????????????
??? Oracle DB ????? SQL ???????????????