mySQL throws Exception --- Jadex plans

Anonymous
2010-10-02
2013-06-12
  • Anonymous - 2010-10-02

    Hi,

    I intend to connect the methods within a plan to a mySQL Database. Due to the fact that already the connection to a mySQL via JDBC creates exceptions leads to the problem that nested classes of a plan are permitting the throwing of exceptions….

    Below you can see my java code for the plan and the java method which I'm using out of another public java class. This code isn't working! I just want to outline my problem with it!

    My question is whether it is possible to integrate the throwing of exceptions within the usage of Jadex plans? If this isn't the case I have a question related to mySQL and whether somebody does know whether the connection, reading and updating of mySQL is realisable without throwing exceptions!

    plan java:

    public class XYZ extends Plan {

    public void body() {

    MySQLread read = new MySQLread();
    read.readDataBase();
    }
    }

    readDataBase java:

    public class MySQLread {

    Connection connect = null;
    Statement statement = null;
    PreparedStatement preparedStatementXYZ = null;
    ResultSet resultSetXYZ = null;

    public void readDataBase() throws Exception {
    try {

    // loading the MySQL driver
    Class.forName("com.mysql.jdbc.Driver");

    // Setup of the connection
    connect = DriverManager.getConnection("jdbc:mysql://localhost/XYZ?" + "user=XYZ&password=XYZ");

    // issue SQL queries to the database
    statement = connect.createStatement();
    preparedStatementXYZ= connect.prepareStatement("SELECT XYZ, XYZ, XYZ from XYZ.XYZ");
    resultSetXYZ = preparedStatementnodes.executeQuery();

    } catch (Exception e) {
    throw e;
    } finally {
    close();
    }
    }

    // close the resultSet
    private void close() {
    try {
    if (resultSetXYZ != null) {
    resultSetXYZ.close();
    }

    if (statement != null) {
    statement.close();
    }

    if (connect != null) {
    connect.close();
    }
    }

    catch (Exception e) {

    }

    }

    Thanks a lot!

     
  • Anonymous - 2010-10-02

    … the nested classes of a Jadex plan are not permitting the throwing of exceptions

     
  • Lars Braubach

    Lars Braubach - 2010-10-02

    Hi,

    I am not sure if I undersand your problem.
    Jadex plans are normal Java classes and of course you can call other methods as you like. This does not depend on if the called method can throw an exception. If in a body method an exception occurs that is not catched by your code Jadex will consider the plan as failed. If you want the plan being executed further just use a try catch block inside the body method:
    public void body() {
    try{
    MySQLread read = new MySQLread();
    read.readDataBase();
    }catch(Exception e){
    e.printStackTrace();
    }
    }

     
  • Anonymous - 2010-10-03

    Hi,

    I thought the same, that it should be no problem! When trying your proposed catching of the exception Eclipse also doesn't have  problems to compile the code but…

    when I execute the agent I get the following exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver …
    which I do not get in my plain Java code:

    public static void main(String args) throws Exception {
    MySQLread read = new MySQLread();
    read.readDataBase();
    }

    but sadly the Jadex packages doesn't allow sth. like:

    public void body () throws Exception {
    MySQLread read = new MySQLread();
    read.readDataBase();

    }

    hmmm…

    In fact I have no real idea what else i could try. Besides I tried so far without success the usage of nested classes, as apparently the main class throws exceptions when an inner class throws exceptions…

    Hmm but somehow it must be possible but how..

    Regards

     
  • Lars Braubach

    Lars Braubach - 2010-10-03

    Hi,

    when I execute the agent I get the following exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver …

    Then you should add the driver jar to the classpath. Note that starting Jadex with the -jar options neglects your own global classpath settings (this is a Java feature ;-) If you use the JCC you could add the driver jar in the library center.

    public void body () throws Exception {

    This would not make sense at all. Where should the exception propagate to?
    The semantics is that a plan fails if an uncought exception occurs. Log level can be used to hide/show such exceptions on console output.

    Best
    Lars

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks