You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by satya_08 <sb...@rediffmail.com> on 2008/02/07 10:56:42 UTC

iBATIS give me an ERROR

I am trying to develop a small web application , 

Here is the structure of my app-------------> 
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\TestStripes 
There is a jsp file , 
under C:\Program Files\Apache Software Foundation\Tomcat
5.5\webapps\TestStripes directory . 

The content of the jsp is 
******************************************************************************* 
<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<%@ taglib prefix="stripes"
uri="http://stripes.sourceforge.net/stripes.tld"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
  <head> 
      <title>LOGIN PAGE</title> 
      <style type="text/css"> 
          input.error { background-color: yellow; } 
      </style> 
  </head> 
  <body> 
                              <h1>UserID and LOGIN</h1> 



    <stripes:form action="/user_validation/UserPass.action" focus=""> 
        <stripes:errors/> 
        <table> 
            <tr> 
                <td>User ID:</td> 
                <td><stripes:text name="user_id"/></td> 
            </tr> 
            <tr> 
                <td>Password:</td> 
                <td><stripes:password name="password"/></td> 
            </tr> 
            <tr> 
                <td colspan="2"> 
                    <stripes:submit name="submit_action" value="submit"/> 
                </td> 
            </tr> 
            <tr> 
                <td>Result:</td> 
                <td>${actionBean.result}</td> 
            </tr> 
        </table> 
    </stripes:form> 
  </body> 
</html> 

******************************************************************************* 
Under WEB-INF , there are two sub directory 
   1)lib 
   2)classes 
   Under lib I have included all the necessary jars , such as
:commons-logging.jar,cos.jar,ibatis-3.0.677.jar, 
   jstl.jar,log4j-1.2.9.jar,mysql-connector-java-5.0.4-bin.jar,standard.jar
& stripes.jar 

  Under classes directory there is my UserPassActionBean.java file and
SqlMapConfig.xml and SqlMap.xml files   

The UserPassActionBean.java  is -----------> 
******************************************************************************* 

   package net.sourceforge.stripes.user_validation; 

   import net.sourceforge.stripes.action.ActionBean; 
   import net.sourceforge.stripes.action.ActionBeanContext; 
   import net.sourceforge.stripes.action.DefaultHandler; 
   import net.sourceforge.stripes.action.Resolution; 
   import net.sourceforge.stripes.action.StreamingResolution; 
 //  import net.sourceforge.stripes.validation.Validatable; 
   import net.sourceforge.stripes.validation.ValidationError; 
   import net.sourceforge.stripes.validation.ValidationErrorHandler; 
   import net.sourceforge.stripes.validation.ValidationErrors; 
   import net.sourceforge.stripes.action.ForwardResolution; 
    
    
   import com.ibatis.sqlmap.client.*; 
   import com.ibatis.common.resources.Resources; 
   import com.ibatis.common.logging.*; 


   import java.io.StringReader; 
   import java.util.List; 
   import java.io.*; 
   import java.util.*; 

   public class UserPassActionBean implements ActionBean,
ValidationErrorHandler 
   { 
              private ActionBeanContext context; 
             /* @Validate(required=true) */private String user_id; 
            /*  @Validate(required=true) */private String password; 
                                           private String result; 

              public ActionBeanContext getContext() { return context; } 
              public void setContext(ActionBeanContext context) {
this.context = context; } 

              public Resolution handleValidationErrors(ValidationErrors
errors) throws Exception 
              { 
                       StringBuilder message = new StringBuilder(); 
                       for (List<ValidationError> fieldErrors :
errors.values()) 
                       { 
                             for (ValidationError error : fieldErrors) 
                             { 
                                message.append("<div style=\"color:
firebrick;\">"); 
                               
message.append(error.getMessage(getContext().getLocale())); 
                                message.append("</div>"); 
                             } 
                       } 
                       return new StreamingResolution("text/html", new
StringReader(message.toString())); 
              } 
              /** Handles the 'submit' event, check the validation  and
returns the result. */ 
          /*    @DefaultHandler public Resolution submit() 
              { 
                  String result = String.valueOf(user_id + password); 
                  return new StreamingResolution("text", new
StringReader(result)); 
              } */ 

              // Standard getter and setter methods 
              public String getUser_id() { return user_id; } 
              public void setUser_id(String user_id) { this.user_id =
user_id; } 

              public String getPassword() { return password; } 
              public void setPassword(String password) { this.password =
password; } 
              public String getResult() { return result; } 
              public void setResult(String result) { this.result = result; } 

              /** An event handler method that adds number one to number
two. */ 
              @DefaultHandler 
              public Resolution submit() 
              { 
                  
                  try 
                  { 
                       String resources = "SqlMapConfig.xml"; 
                       Reader reader =
Resources.getResourceAsReader(resources); 
                       SqlMapClient sqlMapper =
SqlMapClientBuilder.buildSqlMapClient(reader); 
                       Map m = new HashMap(1); 
                       m.put("a",user_id); 
                       password =
(String)sqlMapper.queryForObject("out_example",m); 
                       result = user_id + password; 
                  } 
                  catch(IOException ex) 
                  { 
                      // System.out.println(ex.getMessage()); 
                        ex.printStackTrace(); 
                  } 
                  catch(Exception ex) 
                  { 
                     // System.out.println(ex.getMessage()); 
                      ex.printStackTrace(); 
                  }   
                   return new ForwardResolution("/index.jsp"); 
              } 


   } 
******************************************************************************* 
It gives an error of reading  Reader reader =
Resources.getResourceAsReader(resources);   
The content of the sqlMap.xml is 
******************************************************************************* 
<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE sqlMap       
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"       
    "http://ibatis.apache.org/dtd/sql-map-2.dtd"> 
<sqlMap> 

<parameterMap id="pm_out_example" class="java.util.Map"> 
   <parameter property="a" mode="IN" /> 
</parameterMap> 
<procedure id="out_example" parameterMap="pm_out_example" 
                            resultClass="String"> 
{call usp_sel_ggl_users_passwd(?)} 
</procedure> 

</sqlMap> 

******************************************************************************* 
& the content of the SqlMapConfig.xml is 
******************************************************************************* 
<?xml version="1.0" encoding="UTF-8"?> 
  <!DOCTYPE sqlMapConfig 
      PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" 
      "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> 

  <sqlMapConfig> 
      

      <!-- Statement namespaces are required for Abator --> 
      <settings useStatementNamespaces="true" /> 

      <!-- Setup the transaction manager and data source that are 
          appropriate for your environment--> 
      <transactionManager type="JDBC"> 
          <dataSource type="SIMPLE"> 

              <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" /> 
              <property name="JDBC.ConnectionURL"
value="jdbc:mysql://189.160.100.72/_db" /> 

              <property name="JDBC.Username" value="root" /> 
              <property name="JDBC.Password" value="sql123" /> 
          </dataSource> 
      </transactionManager> 

      <!-- SQL Map XML files should be listed here --> 
      <sqlMap resource="SqlMap.xml" /> 

          

  </sqlMapConfig> 
******************************************************************************* 
Please Help me ,,, 

Thanks 

Satya 

-- 
View this message in context: http://www.nabble.com/iBATIS-give-me-an-ERROR-tp15330504p15330504.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: iBATIS give me an ERROR

Posted by Adam Zimowski <zi...@gmail.com>.
First, build your resources only once, not every time you handle
request. You can do this with a factory class that gets called on
servlet initialization.

As to your problem, you are loading a different file than you have.
Make sure your sqlMap.xml is in the same location where java class
which loads it, and change it from "SqlMapConfig.xml" to "sqlMap.xml"

PS. Are you familiar with DAO pattern? Use it.
http://java.sun.com/blueprints/patterns/DAO.html

-adam

On Feb 7, 2008 3:56 AM, satya_08 <sb...@rediffmail.com> wrote:
>
> I am trying to develop a small web application ,
>
> Here is the structure of my app------------->
> C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\TestStripes
> There is a jsp file ,
> under C:\Program Files\Apache Software Foundation\Tomcat
> 5.5\webapps\TestStripes directory .
>
> The content of the jsp is
> *******************************************************************************
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <%@ taglib prefix="stripes"
> uri="http://stripes.sourceforge.net/stripes.tld"%>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html>
>   <head>
>       <title>LOGIN PAGE</title>
>       <style type="text/css">
>           input.error { background-color: yellow; }
>       </style>
>   </head>
>   <body>
>                               <h1>UserID and LOGIN</h1>
>
>
>
>     <stripes:form action="/user_validation/UserPass.action" focus="">
>         <stripes:errors/>
>         <table>
>             <tr>
>                 <td>User ID:</td>
>                 <td><stripes:text name="user_id"/></td>
>             </tr>
>             <tr>
>                 <td>Password:</td>
>                 <td><stripes:password name="password"/></td>
>             </tr>
>             <tr>
>                 <td colspan="2">
>                     <stripes:submit name="submit_action" value="submit"/>
>                 </td>
>             </tr>
>             <tr>
>                 <td>Result:</td>
>                 <td>${actionBean.result}</td>
>             </tr>
>         </table>
>     </stripes:form>
>   </body>
> </html>
>
> *******************************************************************************
> Under WEB-INF , there are two sub directory
>    1)lib
>    2)classes
>    Under lib I have included all the necessary jars , such as
> :commons-logging.jar,cos.jar,ibatis-3.0.677.jar,
>    jstl.jar,log4j-1.2.9.jar,mysql-connector-java-5.0.4-bin.jar,standard.jar
> & stripes.jar
>
>   Under classes directory there is my UserPassActionBean.java file and
> SqlMapConfig.xml and SqlMap.xml files
>
> The UserPassActionBean.java  is ----------->
> *******************************************************************************
>
>    package net.sourceforge.stripes.user_validation;
>
>    import net.sourceforge.stripes.action.ActionBean;
>    import net.sourceforge.stripes.action.ActionBeanContext;
>    import net.sourceforge.stripes.action.DefaultHandler;
>    import net.sourceforge.stripes.action.Resolution;
>    import net.sourceforge.stripes.action.StreamingResolution;
>  //  import net.sourceforge.stripes.validation.Validatable;
>    import net.sourceforge.stripes.validation.ValidationError;
>    import net.sourceforge.stripes.validation.ValidationErrorHandler;
>    import net.sourceforge.stripes.validation.ValidationErrors;
>    import net.sourceforge.stripes.action.ForwardResolution;
>
>
>    import com.ibatis.sqlmap.client.*;
>    import com.ibatis.common.resources.Resources;
>    import com.ibatis.common.logging.*;
>
>
>    import java.io.StringReader;
>    import java.util.List;
>    import java.io.*;
>    import java.util.*;
>
>    public class UserPassActionBean implements ActionBean,
> ValidationErrorHandler
>    {
>               private ActionBeanContext context;
>              /* @Validate(required=true) */private String user_id;
>             /*  @Validate(required=true) */private String password;
>                                            private String result;
>
>               public ActionBeanContext getContext() { return context; }
>               public void setContext(ActionBeanContext context) {
> this.context = context; }
>
>               public Resolution handleValidationErrors(ValidationErrors
> errors) throws Exception
>               {
>                        StringBuilder message = new StringBuilder();
>                        for (List<ValidationError> fieldErrors :
> errors.values())
>                        {
>                              for (ValidationError error : fieldErrors)
>                              {
>                                 message.append("<div style=\"color:
> firebrick;\">");
>
> message.append(error.getMessage(getContext().getLocale()));
>                                 message.append("</div>");
>                              }
>                        }
>                        return new StreamingResolution("text/html", new
> StringReader(message.toString()));
>               }
>               /** Handles the 'submit' event, check the validation  and
> returns the result. */
>           /*    @DefaultHandler public Resolution submit()
>               {
>                   String result = String.valueOf(user_id + password);
>                   return new StreamingResolution("text", new
> StringReader(result));
>               } */
>
>               // Standard getter and setter methods
>               public String getUser_id() { return user_id; }
>               public void setUser_id(String user_id) { this.user_id =
> user_id; }
>
>               public String getPassword() { return password; }
>               public void setPassword(String password) { this.password =
> password; }
>               public String getResult() { return result; }
>               public void setResult(String result) { this.result = result; }
>
>               /** An event handler method that adds number one to number
> two. */
>               @DefaultHandler
>               public Resolution submit()
>               {
>
>                   try
>                   {
>                        String resources = "SqlMapConfig.xml";
>                        Reader reader =
> Resources.getResourceAsReader(resources);
>                        SqlMapClient sqlMapper =
> SqlMapClientBuilder.buildSqlMapClient(reader);
>                        Map m = new HashMap(1);
>                        m.put("a",user_id);
>                        password =
> (String)sqlMapper.queryForObject("out_example",m);
>                        result = user_id + password;
>                   }
>                   catch(IOException ex)
>                   {
>                       // System.out.println(ex.getMessage());
>                         ex.printStackTrace();
>                   }
>                   catch(Exception ex)
>                   {
>                      // System.out.println(ex.getMessage());
>                       ex.printStackTrace();
>                   }
>                    return new ForwardResolution("/index.jsp");
>               }
>
>
>    }
> *******************************************************************************
> It gives an error of reading  Reader reader =
> Resources.getResourceAsReader(resources);
> The content of the sqlMap.xml is
> *******************************************************************************
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMap
>     PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
>     "http://ibatis.apache.org/dtd/sql-map-2.dtd">
> <sqlMap>
>
> <parameterMap id="pm_out_example" class="java.util.Map">
>    <parameter property="a" mode="IN" />
> </parameterMap>
> <procedure id="out_example" parameterMap="pm_out_example"
>                             resultClass="String">
> {call usp_sel_ggl_users_passwd(?)}
> </procedure>
>
> </sqlMap>
>
> *******************************************************************************
> & the content of the SqlMapConfig.xml is
> *******************************************************************************
> <?xml version="1.0" encoding="UTF-8"?>
>   <!DOCTYPE sqlMapConfig
>       PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
>       "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
>
>   <sqlMapConfig>
>
>
>       <!-- Statement namespaces are required for Abator -->
>       <settings useStatementNamespaces="true" />
>
>       <!-- Setup the transaction manager and data source that are
>           appropriate for your environment-->
>       <transactionManager type="JDBC">
>           <dataSource type="SIMPLE">
>
>               <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
>               <property name="JDBC.ConnectionURL"
> value="jdbc:mysql://189.160.100.72/_db" />
>
>               <property name="JDBC.Username" value="root" />
>               <property name="JDBC.Password" value="sql123" />
>           </dataSource>
>       </transactionManager>
>
>       <!-- SQL Map XML files should be listed here -->
>       <sqlMap resource="SqlMap.xml" />
>
>
>
>   </sqlMapConfig>
> *******************************************************************************
> Please Help me ,,,
>
> Thanks
>
> Satya
>
> --
> View this message in context: http://www.nabble.com/iBATIS-give-me-an-ERROR-tp15330504p15330504.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>