总配置文件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数据库 但出现异常 偶是新手不会 高手帮忙
<?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数据库 但出现异常 偶是新手不会 高手帮忙
解决方案 »
- hibernate版本问题
- struts2的action传递对象的问题
- unix 下部署weblogic出现问题,请大虾们指教!
- spring 多个DAO的声明式事务
- 急问:hibernate 多对一查询问题
- 在hibernate一对多的双向关联中,如果one方和many方的持久化对象均发生了变化,hibernate会怎么做?会执行哪些sql语句,为什么?
- 问大家一个关于设计的问题
- 考勤机里导出的演示数据----我只要前面2列,该怎么做?时间复杂度要求很高,做过大数据处理的兄弟帮帮忙
- 关于struts DynaActionForm的问题(100分),急啊
- 想用Web Service来做,你看行吗?
- SQL外键关联问题!
- 各位大哥,struts问题,现在没有分了,帮下忙了
http://blog.163.com/songze39@126/blog/static/610390652008823105927970/
另外CSDN有下载的可运行的例子。
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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.
com.ibatis.league.doGet(league.java:45) 标红的地方全不对吧··
你有com.ibatis这个包??包下面有个类叫league??
你先确认你的数据库是否连接上,连接上后是否执行过了sql,如果中间出现异常的话,你就可以定位到那句话出现了异常,然后看看这个异常是否是缺少包或者其他可能的错误造成的。还有你贴出来的时候,你可以把异常信息也贴出来,我们好能帮你快速的定位问题。