%
%    This program is free software; you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation; either version 2 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program; if not, write to the Free Software
%    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%

% Version: $Revision: 5898 $

A common query we get from our users is how to open a Windows database in the Weka Explorer. This page is intended as a guide to help you achieve this. It is a complicated process and we cannot guarantee that it will work for you. The process described makes use of the JDBC-ODBC bridge that is part of Sun's JRE/JDK 1.3 (and higher).

The following instructions are for Windows 2000. Under other Windows versions there may be slight differences.

\section*{Step 1: Create a User DSN}
\begin{enumerate}
	\item Go to the \textbf{Control Panel}
	\item Choose \textbf{Adminstrative Tools}
	\item Choose \textbf{Data Sources (ODBC)}
	\item At the \textbf{User DSN} tab, choose \textbf{Add...}
	\item Choose database
	\begin{itemize}
		\item Microsoft Access
		\begin{enumerate}
			\item Note: Make sure your database is not open in another application before following the steps below.
			\item Choose the \textbf{Microsoft Access} driver and click \textbf{Finish}
			\item Give the source a name by typing it into the \textbf{Data Source Name} field
			\item In the \textbf{Database} section, choose \textbf{Select...}
			\item Browse to find your database file, select it and click \textbf{OK}
			\item Click \textbf{OK} to finalize your DSN
		\end{enumerate}

		\item Microsoft SQL Server 2000 (Desktop Engine)
		\begin{enumerate}
			\item Choose the \textbf{SQL Server} driver and click \textbf{Finish}
			\item Give the source a name by typing it into the \textbf{Name} field
			\item Add a description for this source in the \textbf{Description} field
			\item Select the server you're connecting to from the \textbf{Server} combobox
			\item For the verification of the authenticity of the login ID choose \textbf{With SQL Server...}
			\item Check \textbf{Connect to SQL Server to obtain default settings...} and supply the user ID and password with which you installed the Desktop Engine
			\item Just click on \textbf{Next} until it changes into \textbf{Finish} and click this, too
			\item For testing purposes, click on \textbf{Test Data Source...} - the result should be \textit{TESTS COMPLETED SUCCESSFULLY!}
			\item Click on \textbf{OK}
		\end{enumerate}

		\item MySQL
		\begin{enumerate}
			\item Choose the \textbf{MySQL ODBC} driver and click \textbf{Finish}
			\item Give the source a name by typing it into the \textbf{Data Source Name} field
			\item Add a description for this source in the \textbf{Description} field
			\item Specify the server you're connecting to in \textbf{Server}
			\item Fill in the user to use for connecting to the database in the \textbf{User} field, the same for the password
			\item Choose the database for this DSN from the \textbf{Database} combobox
			\item Click on \textbf{OK}
		\end{enumerate}
	\end{itemize}
	\item Your DSN should now be listed in the \textbf{User Data Sources} list
\end{enumerate}

\section*{Step 2: Set up the DatabaseUtils.props file}
You will need to configure a file called \texttt{DatabaseUtils.props}. This file already exists under the path \texttt{weka/experiment/} in the \texttt{weka.jar} file (which is just a ZIP file) that is part of the Weka download. In this directory you will also find a sample file for ODBC connectivity, called \texttt{DatabaseUtils.props.odbc}, and one specifically for MS Access, called \texttt{DatabaseUtils.props.msaccess}, also using ODBC. You should use one of the sample files as basis for your setup, since they already contain default values specific to ODBC access.

This file needs to be recognized when the Explorer starts. You can achieve this by making sure it is in the working directory or the home directory (if you are unsure what the terms \textit{working directory} and \textit{home directory} mean, see the \textit{Notes} section). The easiest is probably the second alternative, as the setup will apply to all the Weka instances on your machine.

Just make sure that the file contains the following lines at least:

\begin{verbatim}
 jdbcDriver=sun.jdbc.odbc.JdbcOdbcDriver
 jdbcURL=jdbc:odbc:dbname
\end{verbatim}

\noindent where \textit{dbname} is the name you gave the user DSN. (This can also be changed once the Explorer is running.)

\newpage
\section*{Step 3: Open the database}
\begin{enumerate}
	\item Start up the Weka Explorer.
	\item Choose \textbf{Open DB...}
	\item The \textbf{URL} should read "jdbc:odbc:\textit{dbname}" where \textit{dbname} is the name you gave the user DSN.
	\item Click \textbf{Connect}
	\item Enter a \textbf{Query}, e.g., "\texttt{select * from \textit{tablename}}" where \textit{tablename} is the name of the database table you want to read. Or you could put a more complicated SQL query here instead.
	\item Click \textbf{Execute}
	\item When you're satisfied with the returned data, click \textbf{OK} to load the data into the Preprocess panel.
\end{enumerate}

\section*{Notes}
\begin{itemize}
 \item \textbf{Working directory} \\
  The directory a process is started from. When you start Weka from the Windows Start Menu, then this directory would be Weka's installation directory (the java process is started from that directory).
 \item \textbf{Home directory} \\
 The directory that contains all the user's data. The exact location depends on the operating system and the version of the operating system. It is stored in the following environment variable:
 \begin{itemize}
  \item Unix/Linux \\
  \texttt{\$HOME}
  \item Windows \\
   \texttt{\%USERPROFILE\%}
  \item Cygwin \\
    \texttt{\$USERPROFILE}
 \end{itemize}
  You should be able output the value in a command prompt/terminal with the echo command. E.g., for Windows this would be:

  \texttt{echo \%USERPROFILE\%}
\end{itemize}
