31 Ekim 2016 Pazartesi

Connection to Oracle database in weka Api


  As we dig through the weka, it is clear that any machine learning process necessitate data. One of the main source of data is database. In this blog, we have been discussing about the establishing connection to Oracle database to weka java api.

  Oracle is the one of the greatest database vendor, and in our example, we are going to use it. It takes fair time for me to establish connection, and I have struggled with many errors. I have found solutions from www.stackoverflow.com. This document is a gathering of experiences in order for database connection.

1-) First of all, you should download weka.jar and odbc6.jar. First one is for weka api, and the second one is for Oracle JDBC.

2-) My java IDE is Eclipse. You should right click on the project and properties --> Java Build Path --> Libraries --> Add External JARS and select the weka.jar and  odbc6.jar.

  2.1) If you add ojdbc14.jar, you would get  “ORA-28040: No matching authentication protocol exception “ error.
  2.2) If you do not add any JDBC here, you would get “No suitable driver found for jdbc:oracle:thin:@localhost:1521:XE “ error. ,

3-) You should be in the weka.jar’s installation folder and go through weka\weka\experiment path. you should select 
DatabaseUtils.props.oracle file. Just delete .oracle extention, Hence file is transforms to DatabaseUtils.props file. Copy this file to your java application's src folder. 

  3-1) If you are getting "WEKA - JDBC Connection Exception"  article 3 will solve the problem. 

4-) The content of the DatabaseUtils.props shall as follows: 

# Database settings for Oracle 10g Express Edition
#
# General information on database access can be found here:
# http://weka.wikispaces.com/Databases
#
# url:     http://www.oracle.com/
# jdbc:    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/
# author:  Fracpete (fracpete at waikato dot ac dot nz)
# version: $Revision: 5835 $

# JDBC driver (comma-separated list)
jdbcDriver=oracle.jdbc.driver.OracleDriver

# database URL
jdbcURL=jdbc:oracle:thin:@localhost:1521/ORCL

# specific data types
#string,getString()= 0;         -->nominal
#boolean,getBoolean() = 1;  -->nominal
#double,getDouble() = 2;    -->numeric
#byte,getByte() = 3;        -->numeric
#short,getByte()= 4;        -->numeric
#int,getInteger() = 5;            -->numeric
#long,getLong() = 6;                -->numeric
#gloat,getFloat() = 7;            -->numeric
#date,getDate() = 8;                -->date
VARCHAR2=0
NUMBER=2
DOUBLE_PRECISION=2
TIMESTAMP=8

# other options
CREATE_INT=INTEGER
CREATE_STRING=VARCHAR2(4000)
CREATE_DOUBLE=NUMBER
CREATE_DATE=TIMESTAMP
DateFormat=yyyy-MM-dd HH:mm:ss
checkUpperCaseNames=true
checkForTable=true


The content in yellow is crucial. If the database located in localhost, it should be localhost.If you designate an IP adress there, you could get "The Network Adapter could not establish the connection when connecting with Oracle DB" error. The phrase ORCL is a tnsname, and it should be as is in tnsnames.ora file in oracle installation directory.
The seperator before ORCL should be "/" not ":", "ORA-12505, TNS:listener does not currently know of SID given in connect descriptor" error could be encountered otherwise. 

Hiç yorum yok:

Yorum Gönder