Link to home
Start Free TrialLog in
Avatar of hgbdelphi
hgbdelphi

asked on

how can i load data from xml with no limit???

hi,experts
  i want load sql statement and parament from my xml file,and combination a sql statement to execute.this is my base code.  

public class BaseXSql {

    String baseXmlUrl="";
    Document document=null;
    Element rootElement=null;
   
    public BaseXSql(){
          baseXmlUrl="c:\\jbasConfig.xml";
          document=DomXmlUtil.readXml(baseXmlUrl);  
          rootElement = document.getRootElement();
    }
   
    public void readXmlConfig(){
        Element tempElement=null;
        System.out.println("jbas-config:"+rootElement.getName());

        Element classElement=rootElement.element("class");
        System.out.println("name:"+classElement.attributeValue("name"));
     
        Element methodElement=classElement.element("method");
        System.out.println("name:"+methodElement.attributeValue("name"));

        Element itemElement=methodElement.element("item");
        System.out.println("name:"+itemElement.attributeValue("name"));
        System.out.println("outcome"+itemElement.attributeValue("outcome"));
       
        Element sqlElement=itemElement.element("sql");

        System.out.println("sqlValue:"+sqlElement.getText());
       
        Element paramElement=itemElement.element("param");
        for(int i=0;i<paramElement.elements().size();i++){
            System.out.println("param:"+((Element)paramElement.elements().get(i)).getText());  
        }

    }
   
   public static void main(String[] args){
       BaseXSql baseXSql=new BaseXSql();
       baseXSql.readXmlConfig();
   }
   
and this is my xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<jbas-config>
   <class name="com.jbas.track.user.LogonBean">
       <method name="isLogin">
           <item name="sql1" outcome="int">
                        <sql>
                   select 1 from TPERSON where LOGINNAME=? and PASSWD=? and Deleted<>'N'
                        </sql>
                        <param>
                           <type>String</type>
                           <type>String</type>
                        </param>
                  </item>

         </method>
   </class>
   


</jbas-config>


but in xml not support:<>'N' ,how can i do it ????

and experts can tell me where or how i can learn about this action:define some sql and parameter statement in xml,and in java get this value and combination a new sql statement to execute and can return ArrayList or another.i think if i do it ,when i want to change sql statement,i will not change java code ,and change xml config only.

thanks!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

wrap the sql in a CDATA block.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hgbdelphi
hgbdelphi

ASKER

thanks for objects,i solve it ,about

and experts can tell me where or how i can learn about this action:define some sql and parameter statement in xml,and in java get this value and combination a new sql statement to execute and can return ArrayList or another.i think if i do it ,when i want to change sql statement,i will not change java code ,and change xml config only


can give me some adive!

thanks very much!!!
hi,objects
  can help me another question?thanks very much.

public class TPersonBean {
    public TPerson getPersonByName(String name){
                myclass.doMethod("TPersonBean","getPersonByName");
    }
}

i want this

public class TPersonBean {
    public TPerson getPersonByName(String name){
                myclass.doMethod(this.getClass().getName(),xxxxxxxxxxxxxxxxxx???);
    }
}

unless you pass the method name, you'll need to specify it explicitly:

public class TPersonBean {
    public TPerson getPersonByName(String name){
                myclass.doMethod(this.getClass().getName(), "getPersonByName");
    }
}

you'll probably also want top pass the actual name also

public class TPersonBean {
    public TPerson getPersonByName(String name){
                myclass.doMethod(this.getClass().getName(), "getPersonByName", name);
    }
}
oh,i see
  thank for your help again.

Best regard for Object!