Nashorn ?? JDBC ? Oracle DB ?????
- by Homma
????
????????????Nashorn ?? JavaScript ??????? JDBC ? API ??????Oracle DB ??????????????????????
?????????????????????JDBC ? API ???????????????
????????? URL ? https://blogs.oracle.com/nashorn_ja/entry/nashorn_jdbc_1 ???
????
???? DB ????Oracle Linux 6.5 ?? Oracle 11.2.0.3.0 ??????????????
JDBC ????????????? DB ?????????????????
????
?Oracle Database JDBC ???????????????????????Nashorn ?? JavaScript ?????????????????????? JDBC ? Oracle DB ???????
Nashorn ?? JavaScript ??????? JDBC ? Oracle DB ??????
JavaScript ?????? DB ????????????????
JavaScript ?????? oracle ?????????
JavaScript ?????? DB ?????????????????????????????????DB ???????????? JavaScript ????????????????????????
oracle ?????????? JDBC ???????????????????????
????
DB ??????
?????? DB ????????????
SQL> create user test identified by "test";
SQL> grant connect, resource to test;
Java 8 ???????
???? JDK 8 ?????????????????????????????? 8u5 ????
Java 8 ???????
???????? JDK ? yum ???????????????
# yum install ./jdk-8u5-linux-x64.rpm
JDK ?????????????????????
# java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
Nashorn ?????
oracle ??????????PATH ???????
$ vi ~/.bash_profile
PATH=${PATH}:/usr/java/latest/bin
export PATH
$ . ~/.bash_profile
jjs ??????????????????
$ jjs -fv
nashorn full version 1.8.0_05-b13
?????????????
JDBC ??????????????
JDBC ?????????JDBC ?????? ???????????????????
???????? JDBC ?????????????????????????
??????????????
JavaScript ??????????jjs ???????????????????? Nashorn ? JavaScript ??????????????????
JDBC ??????? jjs ????? -cp ?????? JDBC ????? JAR ???????????
$ vi version.js
var OracleDataSource = Java.type("oracle.jdbc.pool.OracleDataSource");
var ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:test/test@localhost:1521:orcl");
var conn = ods.getConnection();
var meta = conn.getMetaData();
print("JDBC driver version is " + meta.getDriverVersion());
$ jjs -cp ${ORACLE_HOME}/jdbc/lib/ojdbc6.jar version.js
JDBC driver version is 11.2.0.3.0
??????JavaScript ???????? JDBC ?????????? (11.2.0.3.0) ?????????
Java.type() ??????? JavaClass ??????? new ????? Java ??????????????????????????? Java ????????????????????
?????????????????????????????????????????????????????
?????????????????????????????????????? Java ??????????????? JavaScript ????????????????????????????????
??????
???????????????? jjs ???????????Nashorn ??????????????jjs ???????????????????????????
$ jjs -cp ${ORACLE_HOME}/jdbc/lib/ojdbc6.jar
jjs> var OracleDataSource = Java.type("oracle.jdbc.pool.OracleDataSource");
jjs> var ods = new OracleDataSource();
jjs> ods.setURL("jdbc:oracle:thin:test/test@localhost:1521:orcl");
null
jjs> var conn = ods.getConnection();
jjs> var meta = conn.getMetaData();
jjs> print("JDBC driver version is " + meta.getDriverVersion());
JDBC driver version is 11.2.0.3.0
???????? JDBC ?????????? (11.2.0.3.0) ?????????
?????????????????????????????????????????????????????????JDBC ??????????????????????
???
Nashorn ???????? JDBC ? API ????????????? API ????????????????
???????? JavaScript ??????????????????????????????????
???????????? JDBC ? DB ???????????????? JDBC ???????????????????????????
????
Oracle Database JDBC?????? 11g????2(11.2) ???????
jjs ??????????
Nashorn User's Guide
Java Scripting Programmer's Guide
Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM