Many databases can be used in Weka. Firstly, the DatabaseUtils.props file must be edited to match your database; specifically you must provide your database's name, location, port and correct driver.
jdbcDriver=org.gjt.mm.mysql.Driver
jdbcURL=jdbc:mysql://localhost:3306/my_database
Then the database can be loaded by using some simple code.
import weka.core.Instances;
import weka.experiment.InstanceQuery;
...
InstanceQuery query = new InstanceQuery();
query.setUsername("user");
query.setPassword("pass");
query.setQuery("select * from mytable");
Instances data = query.retrieveInstances();
Some notes about loading from a database:
InstanceQuery
method converts VARCHAR to nominal attributes and TEXT to string attributes. A filter, such as NominalToString
or StringToNormal
, can convert the attributes back to their correct type.