1
votes

i want to design the jbpm process for Online Airline reservation system. as a first step i am trying to do process for traveller registration where user will register their details. when they try to register it, it has to store the user endtered details into db in different table instead.

process that i created.

Start node -> traveller form - > registration task -> end

i have created the table called ARS_traveller in h2 database, under public schema.

in custom work item handler, i have given as below, but it throughing the error as table not found. please suggest the correct procedure to connect to the database an tables.

@Override
    public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

        Context ctx;
        try {
            System.out.println("*********From direct connection**************");
            Connection conn = this.getDirectConnection();
            conn.setAutoCommit(true);
            PreparedStatement stmt = conn
                    .prepareStatement("INSERT INTO ARS_TRAVELLER(NAME,EMAIL,USER_ID,PASSWORD,GENDER,"
                            + "AGE,MOBILE_NO,ADDRESS,CREATED_ON,UNIQUECODE,VERIFIED) VALUES(?,?,?,?,?,?,?,?,?,?,?)");
            stmt.setString(0, workItem.getParameter("Name").toString());
            stmt.setString(1, workItem.getParameter("Email").toString());
            stmt.setString(2, workItem.getParameter("UserId").toString());
            stmt.setString(3, workItem.getParameter("Password").toString());
            stmt.setString(4, workItem.getParameter("Gender").toString());
            stmt.setInt(5,
                    Integer.parseInt(workItem.getParameter("Age").toString()));
            stmt.setString(6, workItem.getParameter("MobileNo").toString());
            stmt.setString(7, workItem.getParameter("Address").toString());
            stmt.setDate(8, new Date((new java.util.Date()).getTime()));
            stmt.setString(9, ((new java.util.Date()).getTime() + ""));
            stmt.setBoolean(10, false);
            stmt.execute();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
            // TODO: handle exception
        }

        manager.completeWorkItem(workItem.getId(), null);

    }

    private Connection getDirectConnection() {
        Connection conn = null;
        try {
            String url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
            Class.forName("org.h2.Driver");
            conn = DriverManager.getConnection(url, "sa", "sa");

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
            // TODO: handle exception
        }
        return conn;
    }
1

1 Answers

1
votes

Table not found is a straight forward error, the table you are looking for does not exist. 1) Your connection information may be incorrect and your are not connecting to the expected database. Or 2) If you are connecting to the correct database, it is likely that either the table was not created, or it was somehow deleted. Do you have some type of application to look at what tables are available in your database? If you do not, you might want to look into the JDBC DatabaseMetaData.getTables method to see if your tables exists.

Here is my theory. It looks like the database you are trying to use is the same as the JBPM persistence database. I have a feeling that the database is recreated each time your JBPM environment is redeployed, which would cause your ARS_Traveller table to be dropped. I would suggest saving your application data into a separate database.

In addition to using a separate database, I would avoid using JDBC. It is very deprecated and harder to maintain over JPA.