分類  >  WEB開發 >

oracle_ibatis 報錯解決思路

tags:    時間:2013-12-09 22:51:28
oracle_ibatis 報錯
SqlMap.properties配置如下:
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:accp11g
username=ibatisUser
password=ibatisUser

SqlMapConfig.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE sqlMapConfig 
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" 
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<transactionManager type="JDBC">
<properties resource="SqlMap.properties" />
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}" />
<property name="JDBC.ConnectionURL" value="${url}" />
<property name="JDBC.Username" value="${username}" />
<property name="JDBC.Password" value="${password}" />
</dataSource>
</transactionManager>
<sqlMap resource="Userinfo.xml" />
</sqlMapConfig>

Userinfo.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE sqlMapConfig 
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" 
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMap>

<typeAlias alias="Userinfo" type="com.fhjibatis.Userinfo" />

<select id="selectAllUserinfo" resultClass="Userinfo">
select * from
userinfo
</select>
</sqlMap>

Userinfo.java實體代碼如下:

package com.fhjibatis;

public class Userinfo {

private Long id;
private String username;
private String password;
private String address;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

}

UserinfoCurd.java代碼如下:

package com.fhjibatis;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

public class UserinfoCurd {
private static SqlMapClient sqlMapClient = null;
static {
try {
Reader reader = com.ibatis.common.resources.Resources
.getResourceAsReader("com/fhjibatis/SqlMapConfig.xml");

sqlMapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder
.buildSqlMapClient(reader);

} catch (IOException e) {
e.printStackTrace();
}
};

public List<Userinfo> selectAllUserinfo() {
List<Userinfo> userinfos = null;
try {
userinfos = sqlMapClient.queryForList("selectAllUserinfo");
} catch (SQLException e) {
e.printStackTrace();
}

return userinfos;
}
}

test.servlet代碼如下:

package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fhjibatis.Userinfo;
import com.fhjibatis.UserinfoCurd;

public class test extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

推薦閱讀文章

Bookmark the permalink ,來源:互聯網