ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: ibatis, eclipse, and tomcat
Date Sat, 22 Jul 2006 15:39:23 GMT
Hmmm,

It sounds to me like you are new to the Java world Aaron. The questions you
are asking are only partially iBATIS questions... but I'll answer anyways.
In regards to eclipse you need to make sure your jars are on the Build
Path(Classpath in pure java terms). Assuming your project is setup as a Java
project and that you are in the Java Perspective in eclipse, you can right
click a .jar file and select "Build Path > Add To Build Path".

In regards to using SQL Maps on a JSP, this is regarded as a bad practice
for most anything in the java world. JSP pages should be a very simple
display of data that is passed to it.

You have stated two goals in your email. You want a quick prototyping
ability and scalability. "Quick" prototyping is a rather relative word. I
would recommend that for this type of thing you consider your development
methodology. Using techniques like XP can provide you with good prototyping
time while laying the foundations of scalability.

Finally, to answer your question. You would want to create a class that
initializes and persists your SQLMap as a static instance variable. Your JSP
page would import that class and reference it through a getSqlMapClient
method. See the following class as an example.

----- Start example SqlMapConfig.java ------

package com.somebiz.myapp.dao.ibatis;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class SqlMapConfig {

  private static final SqlMapClient sqlMapClient;

  static {

    try {
      String resource = "com/somebiz/myapp/dao/ibatis/sqlmapconfig.xml";
      Reader reader = Resources.getResourceAsReader(resource);
      sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
    } catch (Exception e) {
      throw new RuntimeException("Could not initialize SqmMapConfig.  Cause:
" + e);
    }
  }

  public static SqlMapClient getSqlMapClient() {
    return sqlMapClient;
  }

}

----- End example SqlMapConfig.java ------

Cheers,
Brandon

On 7/21/06, Aaron Luke <bluenike@gmail.com> wrote:
>
> Hi-
>
> These are 2 newbie questions...  I searched everywhere for the answer...
> if i do get the answer (if it didn't exist elsewhere), I promise to put it
> up in a tutorial for people looking to do the same...
>
> All I'm trying to do is make my way through the iBATIS SQLMaps tutorial (
> http://cvs.apache.org/dist/ibatis/ibatis.java/docs/iBATIS-SqlMaps-2-Tutorial.pdf),
> but I'm trying to do this on Tomcat using an Eclipse environment.
>
> The first problem is that I'm wondering where the best place to put the
> MyAppSqlConfig instantiation if you are using just JSP... Do I just
> instantiate a sqlMap at the top of each JSP page?  Or is there a better way
> to do this?
>
> The second problem is that I get an error from Eclipse in the IDE when I
> enter the statement "import com.ibatis.sqlmap.client.*;" at the top of
> file for a java class that is used by our jsp test page.  The error says
> that the import cannot be resolved.  I have put both of the jar files (
> ibatis-sqlmap-2.jar and ibatis-common-2.jar) in the WEB-INF/lib directory
> by drag-n-drop into the IDE.  That didn't work so I also put both of the jar
> files in the tomcat/shared/lib directory as well... that didn't work
> either... what's wrong?  sorry i know this is more of an eclipse/tomcat
> question...
>
> Thank you for any help in advance...  we are evaluating the ability of
> Java to do quick-and-dirty prototyping and iBATIS/Eclipse/Tomcat look like
> they have a lot of potential compared to what we usually use (Perl, Python,
> etc), in additional to being able to grow into a large-scale system...  It's
> just the learning curve...
>
> Thanks-
> Aaron
>

Mime
View raw message