[rules-users] DataBase Configuration for Drools

Wolfgang Laun wolfgang.laun at gmail.com
Wed Dec 22 06:39:49 EST 2010


Some remarks:

* It's strange to have a non-static method (getData) of a class
(Applicant) where that method isn't tightly connected with anything
from that class.

* price is int, getData() returns a String. This will cause problems.

* You can use
   A:Applicant( price< ( ...any Java expression... ) )
but be advised that fetching a value from a database happens at the
time where another Applicant is inserted. If that ItenPrice object is
changed later, the new value will not be used until the next Applicant
is inserted.

-W

On 22 December 2010 09:15, wasim.khan318 <khanwasim07 at yahoo.co.in> wrote:
>
> Hi every body  i am new to Drools section . What i want to achive in drool
> let me axplain with example.
> When
>
> Price==$price
>
> then
> // some code
> what we are trying to do is some how value of $price comes from
> database.rather hard coding it
> what i have did
>
> 1. Using jboss developer   studio for developing Drool Application
>
>
> 2. Using MySql DataBase
>
> 3. My Class File
>
>
> public static class Applicant {
>
>                //public static final int HELLO = 0;
>                //public static final int GOODBYE = 1;
> private String Name;
> private int Price;
>                //private String message;
>
>                //private int status;
>
>
>                public String getName()
>                {
>                        return this.Name;
>                }
>                public void setName( String name)
>                {
>                        this.Name=name;
>                }
>
>                public int getPrice()
>                {
>                return this.Price;
>                }
>                public void setPrice(int price)
>                {
>                        this.Price=price;
>                }
>
>                public String GetData()
>                {
>                        String p=null;
>                        Connection con = null;
>
>                    try {
>                      Class.forName("com.mysql.jdbc.Driver").newInstance();
>                      con = DriverManager.getConnection("my connection info ");
>
>                      if(!con.isClosed())
>                        System.out.println("Successfully connected to " +
>                          "MySQL server using TCP/IP...");
>
>                    } catch(Exception e) {
>                      System.err.println("Exception: " + e.getMessage());
>                    } finally {
>
>                    }
>                   try{
>                   Statement  smt=con.createStatement();
>
>                   ResultSet  rs=smt.executeQuery("select ItenPrice from Item Where
> ItemId= 1");
>                   while(rs.next())
>                   {
>                           p=rs.getString("ItenPrice");
>                   }
>                   }
>                   catch(Exception a)
>                   {
>                           System.err.println("Exception: " + a.getMessage());
>                   }
>
>
>                  return p;
>                }
>                public void GetNewdata(Applicant Ap)
>                {
>                        Ap.GetData();
>                }
>
>                /*
>                public String getMessage() {
>                        return this.message;
>                }
>
>                public void setMessage(String message) {
>                        this.message = message;
>                }
>
>                public int getStatus() {
>                        return this.status;
>                }
>
>                public void setStatus(int status) {
>                        this.status = status;
>                }*/
>
>        }
> 4. My drools File
> package com.sample
>
> import com.sample.DroolsTest.Applicant;
>
> rule "Hello World"
>
>        when
>
>
> A:Applicant( price<20 )
>
>
>
>        then
>
>
>        String a=A.GetData();
>        System.out.println( a );
>
> end
> 5. what i want in when section insted of writing 20 i can write GetData()
> which is returning value from data base, it is working fine in then section
> but firing error in when section
> --
> View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/DataBase-Configuration-for-Drools-tp2130161p2130161.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>




More information about the rules-users mailing list