十万火急 老大们求求你们帮我看下 用了ibatis
总配置文件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数据库 但出现异常 偶是新手不会 高手帮忙