"problem in using readDatabase, writeDatabase and updateDatabase operator in Java"

arunpushkararunpushkar Member Posts: 8 Contributor II
edited June 9 in Help
As suggested by Marco Boeck(administrator) i have used rapid miner GUI for creating process in which i used readDatabase operator read table from  mysql data base and used it as a input to LOF operator and there after output of LOF operator was given to writeDatabase operator. process so created was called from java application, but when compiled it gives error on database connection variable 'netcon' which i have defined using GUI and was working well there. Then why is it not finding it when being called from java application. my java code is as follows. 
package pkg;
import java.io.IOException;

import com.rapidminer.RapidMiner;
import com.rapidminer.RapidMiner.ExecutionMode;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.IOObject;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.repository.IOObjectEntry;
import com.rapidminer.repository.MalformedRepositoryLocationException;
import com.rapidminer.repository.ProcessEntry;
import com.rapidminer.repository.RepositoryException;
import com.rapidminer.repository.RepositoryLocation;
import com.rapidminer.tools.XMLException;
import com.rapidminer.Process;


public class trydatabase {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub

// this initializes RapidMiner with your repositories available
// you have to call this for all your programs, otherwise your RapidMiner integration will not work correctly
RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
RapidMiner.init();

// loads the process from the repository
RepositoryLocation pLoc = null;
try
{
pLoc = new RepositoryLocation("//NewLocalRepository/createOutlier");
}
catch (MalformedRepositoryLocationException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
ProcessEntry pEntry = null;
try
{
pEntry = (ProcessEntry) pLoc.locateEntry();
}
catch (RepositoryException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}

String processXML = null;

try
{
processXML = pEntry.retrieveXML();
}
catch (RepositoryException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}

Process myProcess = null;

try
{
myProcess = new Process(processXML);
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (XMLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}

try
{
myProcess.run();
}
catch (OperatorException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}




}

}
And my XML process code is as follows
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.2.008">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
    <process expanded="true" height="235" width="681">
      <operator activated="true" class="read_database" compatibility="5.2.008" expanded="true" height="60" name="Read Database" width="90" x="47" y="177">
        <parameter key="connection" value="netcon"/>
        <parameter key="query" value="SELECT *&#10;FROM `nettable`"/>
        <enumeration key="parameters"/>
      </operator>
      <operator activated="true" class="anomalydetection:Local Outlier Factor (LOF)" compatibility="1.2.000" expanded="true" height="76" name="Local Outlier Factor (LOF)" width="90" x="226" y="164">
        <parameter key="k_max (MinPtsUB)" value="18"/>
      </operator>
      <operator activated="true" class="write_database" compatibility="5.2.008" expanded="true" height="60" name="Write Database" width="90" x="471" y="182">
        <parameter key="connection" value="netcon"/>
        <parameter key="table_name" value="resulttable"/>
      </operator>
      <connect from_op="Read Database" from_port="output" to_op="Local Outlier Factor (LOF)" to_port="example set"/>
      <connect from_op="Local Outlier Factor (LOF)" from_port="example set" to_op="Write Database" to_port="input"/>
      <connect from_op="Write Database" from_port="through" to_port="result 1"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
    </process>
  </operator>
</process>
Error which i am getting is
Dec 22, 2012 1:40:07 PM com.rapidminer.tools.ParameterService init
INFO: Reading configuration resource com/rapidminer/resources/rapidminerrc.
Dec 22, 2012 1:40:07 PM com.rapidminer.tools.I18N <clinit>
INFO: Set locale to en.
Dec 22, 2012 1:40:07 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
INFO: Property rapidminer.home is not set. Guessing.
Dec 22, 2012 1:40:07 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
INFO: Trying parent directory of '/home/iitm/workspace/rapidminer/rapidminer.jar'...gotcha!
Dec 22, 2012 1:40:07 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
INFO: Trying parent directory of '/opt/rapidminer/lib/rapidminer.jar'...gotcha!
Dec 22, 2012 1:40:07 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
INFO: Trying parent directory of '/opt/rapidminer/lib/launcher.jar'...gotcha!
Dec 22, 2012 1:40:08 PM com.rapidminer.parameter.ParameterTypePassword decryptPassword
WARNING: Password in XML file looks like unencrypted plain text.
Dec 22, 2012 1:40:09 PM com.rapidminer.tools.jdbc.JDBCProperties <init>
WARNING: Missing database driver class name for ODBC Bridge (e.g. Access)
Dec 22, 2012 1:40:09 PM com.rapidminer.tools.jdbc.JDBCProperties registerDrivers
INFO: JDBC driver ca.ingres.jdbc.IngresDriver not found. Probably the driver is not installed.
Dec 22, 2012 1:40:09 PM com.rapidminer.tools.jdbc.JDBCProperties registerDrivers
INFO: JDBC driver oracle.jdbc.driver.OracleDriver not found. Probably the driver is not installed.
Dec 22, 2012 1:40:09 PM com.rapidminer.tools.WrapperLoggingHandler log
INFO: No filename given for result file, using stdout for logging results!
Dec 22, 2012 1:40:09 PM com.rapidminer.Process run
INFO: Process starts
com.rapidminer.operator.UserError: Database connection failed: connection netcon is unknown. Please define the connection properly.
at com.rapidminer.tools.jdbc.DatabaseHandler.getConnectedDatabaseHandler(DatabaseHandler.java:1038)
at com.rapidminer.operator.io.DatabaseDataReader.getResultSet(DatabaseDataReader.java:111)
at com.rapidminer.operator.io.DatabaseDataReader.createExampleSet(DatabaseDataReader.java:124)
at com.rapidminer.operator.io.AbstractExampleSource.read(AbstractExampleSource.java:52)
at com.rapidminer.operator.io.DatabaseDataReader.read(DatabaseDataReader.java:96)
at com.rapidminer.operator.io.DatabaseDataReader.read(DatabaseDataReader.java:82)
at com.rapidminer.operator.io.AbstractReader.doWork(AbstractReader.java:123)
at com.rapidminer.operator.Operator.execute(Operator.java:834)
at com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:51)
at com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:711)
at com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:379)
at com.rapidminer.operator.Operator.execute(Operator.java:834)
at com.rapidminer.Process.run(Process.java:925)
at com.rapidminer.Process.run(Process.java:848)
at com.rapidminer.Process.run(Process.java:807)
at com.rapidminer.Process.run(Process.java:802)
at com.rapidminer.Process.run(Process.java:792)
at pkg.trydatabase.main(trydatabase.java:87)
Can you please suggest some solution please
Tagged:

Answers

  • aborgaborg Member Posts: 67 Contributor II
    Just a spare idea... Have you tried setting the rapidminer home? Maybe it cannot load the jdbc driver.
  • arunpushkararunpushkar Member Posts: 8 Contributor II
    How to set rapid miner home. more over mysqldriver is in the form of jar file and is in rapidminer/lib/jdbc/mysql-connector-java-5.1.17-bin.jar
    i have set the PATH to this directory. but still same error "Database connection failed: connection netcon is unknown. Please define the connection properly." How ever this connection "netcon" has been defined properly using rapidminer GUI while making the process.
    Still No solution
  • arunpushkararunpushkar Member Posts: 8 Contributor II
    I have moved a bit ahead but still got stuck again. Previously the mistake which i was making was that, in GUI mode while setting the parameters for operator "read database" i was using "define connection=predefined" but moment i used  "define connection=url" and gave all the values including username and password into it, it worked as all the connection specific details are now present in XML file. But after i moved from that error i got stuck at this error " com.rapidminer.operator.UserError: Database error occurred: Access denied for user 'root'@'localhost' (using password: YES) " when i run this process in GUI mode it doesnt give any error however when calling it from JAVA(code given in previous reply) it gives error as given above. user name and password is correct. Can anyone please suggest what might be the problem ?
  • arunpushkararunpushkar Member Posts: 8 Contributor II
    Now my XML code is: but the problem "com.rapidminer.operator.UserError: Database error occurred: Access denied for user 'root'@'localhost' (using password: YES)" remains
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.008">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
        <process expanded="true" height="531" width="832">
          <operator activated="true" class="read_database" compatibility="5.2.008" expanded="true" height="60" name="Read Database" width="90" x="112" y="120">
            <parameter key="define_connection" value="url"/>
            <parameter key="connection" value="netcon"/>
            <parameter key="database_url" value="jdbc:mysql://localhost:3306/netdata"/>
            <parameter key="username" value="root"/>
            <parameter key="password" value="UxP0KMCZjok="/>
            <parameter key="query" value="SELECT *&#10;FROM `nettable`"/>
            <enumeration key="parameters"/>
          </operator>
          <operator activated="true" class="anomalydetection:Local Outlier Factor (LOF)" compatibility="1.2.000" expanded="true" height="76" name="Local Outlier Factor (LOF)" width="90" x="265" y="118"/>
          <operator activated="true" class="write_database" compatibility="5.2.008" expanded="true" height="60" name="Write Database" width="90" x="470" y="116">
            <parameter key="define_connection" value="url"/>
            <parameter key="connection" value="netcon"/>
            <parameter key="database_url" value="jdbc:mysql://localhost:3306/netdata"/>
            <parameter key="username" value="root"/>
            <parameter key="password" value="UxP0KMCZjok="/>
            <parameter key="table_name" value="resulttable"/>
            <parameter key="overwrite_mode" value="overwrite"/>
          </operator>
          <connect from_op="Read Database" from_port="output" to_op="Local Outlier Factor (LOF)" to_port="example set"/>
          <connect from_op="Local Outlier Factor (LOF)" from_port="example set" to_op="Write Database" to_port="input"/>
          <connect from_op="Write Database" from_port="through" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
Sign In or Register to comment.