[Problem details] link weka in ubuntu to mysql database
Preparation 1. First download weka, the related link is http://www.cs.waikato.ac.nz/ml/weka/downloading.html
Decompress the package and use unzip weka ***. zip.
You can set a directory by yourself ~ /Home/chicho/tools/weka-3-7-12
Add/home/chicho/tools/weka-3-7-12/weka. jar to the environment variable.
2. The database I use is MySQL. You can find a lot of related information on the Internet for MySQL installation and usage. I will not describe it here. The JDBC Driver used by MySQL is com. mysql. jdbc. Driver. here we need to make some additional configuration. You need to install jdk on your ubuntu to download the jdbc driver. Set a lib directory under the weka installation directory, and then put the jdbc driver under the lib directory.
Configure environment variables 1. Use gedit ~ /. The bashrc command adds the JDBC driver to the CLASSPATH so that the CLASSPATH can point to the driver.
<span style="font-size:14px;">export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25 export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:/home/chicho/tools/weka-3-7-12/lib/mysql-connector-java-5.1.27-bin.jarexport PATH=${JAVA_HOME}/bin:$PATHexport PATH=$PATH:/home/chicho/tools/weka-3-7-12/weka.jar</span>
2. Use source ~ /. Make the environment variable take effect
3. Because weka is developed based on java, we need to perform subsequent operations in Linux (Ubuntu platform) Java to connect to the MySQL database through JDBC. The steps are as follows:
DownloadJdbc: mysql-connector-java-5.1.18.tar.gz
ExtractJdbc: tar-zxvf mysql-connector-java-5.1.18.tar.gz
ConfigurationJdbc: cp mysql-connector-java-5.1.18-bin.jar/usr/local/jdk1.8.0 _ 25/jre/lib/ext/
Do not forget this step; otherwise, errors may occur.
Configuration
Open weka. jar \ experiment with the archive and find DatabaseUtils. props.
# General information on database access can be found here:# http://weka.wikispaces.com/Databases## Version: $Revision: 11144 $# The comma-separated list of jdbc drivers to use#jdbcDriver=RmiJdbc.RJDriver,jdbc.idbDriver#jdbcDriver=jdbc.idbDriver#jdbcDriver=RmiJdbc.RJDriver,jdbc.idbDriver,org.gjt.mm.mysql.Driver,com.mckoi.JDBCDriver,org.hsqldb.jdbcDriver#jdbcDriver=org.gjt.mm.mysql.DriverjdbcDriver=com.mysql.jdbc.Driver# The url to the experiment database#jdbcURL=jdbc:rmi://expserver/jdbc:idb=experiments.prp#jdbcURL=jdbc:idb=experiments.prp#jdbcURL=jdbc:mysql://mysqlserver/usernamejdbcURL=jdbc:mysql://localhost:3306/database_name# the method that is used to retrieve values from the db# (java datatype + RecordSet.<method>)# 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# float, getFloat() = 7; --> numeric# date, getDate() = 8; --> date# text, getString() = 9; --> string# time, getTime() = 10; --> date# the original conversion: <column type>=<conversion>#char=0#varchar=0#longvarchar=0#binary=0#varbinary=0#longvarbinary=0#bit=1#numeric=2#decimal=2#tinyint=3#smallint=4#integer=5#bigint=6#real=7#float=2#double=2#date=8#time=10#timestamp=8#mysql-conversionCHAR=0TEXT=0VARCHAR=0LONGVARCHAR=9BINARY=0VARBINARY=0LONGVARBINARY=9BIT=1NUMERIC=2DECIMAL=2FLOAT=2DOUBLE=2TINYINT=3SMALLINT=4#SHORT=4SHORT=5INTEGER=5BIGINT=6LONG=6REAL=7DATE=8TIME=10TIMESTAMP=8#mappings for table creationCREATE_STRING=TEXTCREATE_INT=INTCREATE_DOUBLE=DOUBLECREATE_DATE=DATETIMEDateFormat=yyyy-MM-dd HH:mm:ss#database flagscheckUpperCaseNames=falsecheckLowerCaseNames=falsecheckForTable=truesetAutoCommit=truecreateIndex=false# All the reserved keywords for this databaseKeywords=\AND,\ASC,\BY,\DESC,\FROM,\GROUP,\INSERT,\ORDER,\SELECT,\UPDATE,\WHERE# The character to append to attribute names to avoid exceptions due to# clashes between keywords and attribute namesKeywordsMaskChar=_#flags for loading and saving instances using DatabaseLoader/SavernominalToStringLimit=50idColumn=auto_generated_id
Add the red part.
JdbcURL = jdbc: mysql: // localhost: 3306/database_name & lt; = This location is changed based on your needs.
Save and update.