十万火急 老大们求求你们帮我看下 用了ibatis

qq382263361 2009-09-23 09:18:45
总配置文件sqlMapConfig
<?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>
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="soccer">
<property name="JDBC.Driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="JDBC.ConnectionURL" value="jdbc:sqlserver://localhost:1433"/>
<property name="JDBC.Username" value="sa"/>
<property name="JDBC.Password" value="123"/>
</dataSource>
</transactionManager>
<sqlMap resource="model/league.xml"/>
</sqlMapConfig>


映射文件
<?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 >
<typeAlias alias="League" type="model.League"/>
<resultMap id="LeagueResult" class="League">

<result property="year" column="year"/>
<result property="season" column="season"/>
<result property="title" column="title"/>
</resultMap>
<insert id="insertLeague" parameterClass="League">
insert into league (
year,
season,
title)
values (
#year#, #season#,#title#
)
</insert>
</sqlMap>


package model;

public class League {
private int year;
private String season;
private String title;

public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getSeason() {
return season;
}
public void setSeason(String season) {
this.season = season;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

}


public class LeagueBLL {

private static SqlMapClient sqlMap;
static {
try {
Reader reader = Resources.getResourceAsReader("model/SqlMapConfig.xml");
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (Exception e) {
// Fail fast.
throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
}
}
public void AddLeague(League league)
{
try {
sqlMap.insert("insertLeague", league);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String []args){
LeagueBLL stu = new LeagueBLL();

System.out.println("------------------------------- start ------------------------------");

League league = new League();
league.setYear(year);
league.setSeason(season);
league.setTitle(title);

LeagueBLL lb=new LeagueBLL();
lb.AddLeague(league);
}


我想用ibatis框架把他写进sql server2005数据库 但出现异常 偶是新手不会 高手帮忙
...全文
95 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
menjianguo 2009-09-23
  • 打赏
  • 举报
回复
感觉像是 缺少 jar 包。
qq382263361 2009-09-23
  • 打赏
  • 举报
回复
我用了那个例子 怎么还是出异常啊
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoClassDefFoundError
com.ibatis.league.doGet(league.java:45)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
  • 打赏
  • 举报
回复
楼主给你个例子吧
http://blog.163.com/songze39@126/blog/static/610390652008823105927970/


另外CSDN有下载的可运行的例子。
wanwan108 2009-09-23
  • 打赏
  • 举报
回复
数据库名咋都没找到?这个类LeagueBLL 里面 获取这个SqlMapClient 对象的代码放到构造函数里去。
JackRui2008 2009-09-23
  • 打赏
  • 举报
回复
你可以跟踪你的代码来检查你具体错误的地方啊,这样看很累的。
你先确认你的数据库是否连接上,连接上后是否执行过了sql,如果中间出现异常的话,你就可以定位到那句话出现了异常,然后看看这个异常是否是缺少包或者其他可能的错误造成的。

还有你贴出来的时候,你可以把异常信息也贴出来,我们好能帮你快速的定位问题。
imasmallbird 2009-09-23
  • 打赏
  • 举报
回复
java.lang.NoClassDefFoundError
com.ibatis.league.doGet(league.java:45)

标红的地方全不对吧··
你有com.ibatis这个包??包下面有个类叫league??

67,542

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧