You can add a LogWriter to get more information on what happens :
PrintWriter writer = new Logger(System.out).setPrefix("test");
JDO jdo = new JDO();
jdo.setLogWriter(writer);Jonathan Asbell wrote:
I am having the most difficult time getting results from a query. I understand the following thus far:
1) I make a bean (getters and setters) with fields which I define and match to names in the mapping file.
2) I make a mapping file which declares the correct types and mappings to the java class(bean)
3) I create a query which uses the specific names in the class and mapping file (case sensitive);
I am getting exceptions that range from "An inapropriate token (20) was encountered in an expression.", to just plain "null". Any help?
=================================
ATTEMPTS/RESULTS
=================================
OQLQuery oql = db.getOQLQuery("select * from com.mh.fwsf.castor.TaxtableBean bean");
An inapropriate token (20) was encountered in an expression
OQLQuery oql = db.getOQLQuery("select bean from com.mh.fwsf.castor.TaxtableBean bean");
null
=================================
MY CODE
=================================
public void test_Get_Tax_Table() {
Mapping mapping = new Mapping(getClass().getClassLoader());
try {
mapping.loadMapping(new InputSource(new FileInputStream(new File("D:\\jakarta-tomcat-4.1.12\\webapps\\mhfwsf\\WEB-INF\\mapping.xml"))));
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (MappingException e) {
System.out.println(e.getMessage());
}
JDO jdo = new JDO();
jdo.setConfiguration("D:\\jakarta-tomcat-4.1.12\\webapps\\mhfwsf\\WEB-INF\\database.xml");
jdo.setDatabaseName("advantage");
jdo.setClassLoader(getClass().getClassLoader());
Database db = null;
try {
db = jdo.getDatabase();
db.begin();
OQLQuery oql = db.getOQLQuery("select bean from com.mh.fwsf.castor.TaxtableBean bean");
QueryResults results = oql.execute();
assertNotNull(results);
while (results.hasMore()) {
TaxtableBean bean = (TaxtableBean) results.next();
System.out.println(bean.getBgn_zip());
}
db.commit();
} catch (Exception e) {
System.out.println(e.getMessage());
try {
db.rollback();
} catch (TransactionNotInProgressException tnipe) {
System.out.println(tnipe.getMessage());
}
} finally {
try {
if (db != null) {
db.close();
}
} catch (Exception ne) {
System.out.println(ne.getMessage());
}
db = null;
}
}
=================================
JAVA CLASS (BEAN)
=================================
package com.mh.fwsf.castor;
import org.exolab.castor.jdo.engine.JDOFieldDescriptor;
import java.util.Date;
public class TaxtableBean {
private String tax_type;
private String cun_typ;
private String end_zip;
private int eff_cpl;
private String tax_typ2;
private Date eff_dte;
private int per_cnt;
private String ste_cde;
private String jur_nme;
private String rpt_jur;
private String bgn_zip;
private String inc_shp;
public String getTax_type() {
return tax_type;
}
public void setTax_type(String tax_type) {
this.tax_type = tax_type;
}
public String getCun_typ() {
return cun_typ;
}
public void setCun_typ(String cun_typ) {
this.cun_typ = cun_typ;
}
public String getEnd_zip() {
return end_zip;
}
public void setEnd_zip(String end_zip) {
this.end_zip = end_zip;
}
public int getEff_cpl() {
return eff_cpl;
}
public void setEff_cpl(int eff_cpl) {
this.eff_cpl = eff_cpl;
}
public String getTax_typ2() {
return tax_typ2;
}
public void setTax_typ2(String tax_typ2) {
this.tax_typ2 = tax_typ2;
}
public Date getEff_dte() {
return eff_dte;
}
public void setEff_dte(Date eff_dte) {
this.eff_dte = eff_dte;
}
public int getPer_cnt() {
return per_cnt;
}
public void setPer_cnt(int per_cnt) {
this.per_cnt = per_cnt;
}
public String getSte_cde() {
return ste_cde;
}
public void setSte_cde(String ste_cde) {
this.ste_cde = ste_cde;
}
public String getJur_nme() {
return jur_nme;
}
public void setJur_nme(String jur_nme) {
this.jur_nme = jur_nme;
}
public String getRpt_jur() {
return rpt_jur;
}
public void setRpt_jur(String rpt_jur) {
this.rpt_jur = rpt_jur;
}
public String getBgn_zip() {
return bgn_zip;
}
public void setBgn_zip(String bgn_zip) {
this.bgn_zip = bgn_zip;
}
public String getInc_shp() {
return inc_shp;
}
public void setInc_shp(String inc_shp) {
this.inc_shp = inc_shp;
}
}
=================================
MAPPING FILE
=================================
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd" <http://castor.exolab.org/mapping.dtd>>
<mapping>
<class name="com.mh.fwsf.castor.TaxtableBean" identity="end_zip">
<description>Taxtable in Advantage</description>
<map-to table="ADV.TAXRTE_M"/>
<field name="tax_type" type="string">
<sql name="tax_type" type="varchar"/>
</field>
<field name="cun_typ" type="string">
<sql name="cun_typ" type="varchar"/>
</field>
<field name="end_zip" type="string">
<sql name="end_zip" type="varchar"/>
</field>
<field name="eff_cpl" type="integer">
<sql name="eff_cpl" type="integer"/>
</field>
<field name="tax_typ2" type="string">
<sql name="tax_typ2" type="varchar"/>
</field>
<field name="eff_dte" type="date">
<sql name="tax_type" type="date"/>
</field>
<field name="per_cnt" type="integer">
<sql name="per_cnt" type="integer"/>
</field>
<field name="ste_cde" type="string">
<sql name="ste_cde" type="varchar"/>
</field>
<field name="jur_nme" type="string">
<sql name="jur_nme" type="varchar"/>
</field>
<field name="rpt_jur" type="string">
<sql name="rpt_jur" type="varchar"/>
</field>
<field name="bgn_zip" type="string">
<sql name="bgn_zip" type="varchar"/>
</field>
<field name="inc_shp" type="string">
<sql name="inc_shp" type="varchar"/>
</field>
</class>
</mapping>
--
Mickael Guessant
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
