下面是部分代码
-----------------------SpringStoredProcedure类,网上抄的~!呵呵---------------------
在return execute(this.inParam);这句出的异常。前面的信息也都打印出了。package jp.co.mySpring.frame.dao.helper;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.RowMapperResultReader;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
/**
*
* @author quwei
*
*/
public class SpringStoredProcedure extends StoredProcedure {
public ArrayList set = new ArrayList();
private Map inParam;
public SpringStoredProcedure() {
}
public SpringStoredProcedure(DataSource ds, String SQL) {
setDataSource(ds);
setSql(SQL);
} public SpringStoredProcedure(JdbcTemplate jt, String SQL) {
setJdbcTemplate(jt);
setSql(SQL);
}
private RowMapper rm = new RowMapper(){
public Object mapRow(ResultSet rs,int rowNum) throws SQLException{
return null;
}
};
private RowMapperResultReader callback = new RowMapperResultReader(rm ){
public void processRow(ResultSet rs)throws SQLException{
int count = rs.getMetaData().getColumnCount();
String[] header = new String[count];
for(int i=0;i<count;i++){
header[i] = rs.getMetaData().getColumnName(i+1);
}
while(rs.next()){
HashMap row = new HashMap(count+7);
for(int i=0;i<count;i++){
row.put(header[i],rs.getString(i+1));
}
set.add(row);
}
}
};
public void setParameter(String column,int type){
declareParameter(new SqlParameter(column, type));
}
public void setOutParameter(String column,int type){
declareParameter(new SqlOutParameter(column, type,callback));
}
public void SetInParam(Map inParam){
this.inParam = inParam;
}
public Map execute() {
compile();
System.out.println("inParam = " + this.inParam);
System.out.println("inParam.vcSql = " + this.inParam.get("vcSql"));
System.out.println("inParam.iNowPage = " + this.inParam.get("iNowPage"));
System.out.println("inParam.iMaxNum = " + this.inParam.get("iMaxNum"));
return execute(this.inParam);
}
}
-----------------------SpringStoredProcedure类,网上抄的~!呵呵---------------------
在return execute(this.inParam);这句出的异常。前面的信息也都打印出了。package jp.co.mySpring.frame.dao.helper;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.RowMapperResultReader;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
/**
*
* @author quwei
*
*/
public class SpringStoredProcedure extends StoredProcedure {
public ArrayList set = new ArrayList();
private Map inParam;
public SpringStoredProcedure() {
}
public SpringStoredProcedure(DataSource ds, String SQL) {
setDataSource(ds);
setSql(SQL);
} public SpringStoredProcedure(JdbcTemplate jt, String SQL) {
setJdbcTemplate(jt);
setSql(SQL);
}
private RowMapper rm = new RowMapper(){
public Object mapRow(ResultSet rs,int rowNum) throws SQLException{
return null;
}
};
private RowMapperResultReader callback = new RowMapperResultReader(rm ){
public void processRow(ResultSet rs)throws SQLException{
int count = rs.getMetaData().getColumnCount();
String[] header = new String[count];
for(int i=0;i<count;i++){
header[i] = rs.getMetaData().getColumnName(i+1);
}
while(rs.next()){
HashMap row = new HashMap(count+7);
for(int i=0;i<count;i++){
row.put(header[i],rs.getString(i+1));
}
set.add(row);
}
}
};
public void setParameter(String column,int type){
declareParameter(new SqlParameter(column, type));
}
public void setOutParameter(String column,int type){
declareParameter(new SqlOutParameter(column, type,callback));
}
public void SetInParam(Map inParam){
this.inParam = inParam;
}
public Map execute() {
compile();
System.out.println("inParam = " + this.inParam);
System.out.println("inParam.vcSql = " + this.inParam.get("vcSql"));
System.out.println("inParam.iNowPage = " + this.inParam.get("iNowPage"));
System.out.println("inParam.iMaxNum = " + this.inParam.get("iMaxNum"));
return execute(this.inParam);
}
}
--------------------------------------------------------------------
public List queryForList(String query,
List list,int nowPage) throws DataAccessException{
//DriverManagerDataSource ds = (DriverManagerDataSource) this.getDataSource();
// DriverManagerDataSource ds =new DriverManagerDataSource();
// ds.setDriverClassName("oracle.jdbc.OracleDriver");
// ds.setUrl("jdbc:oracle:thin:@192.168.30.32:1521:kt11t");
// ds.setUsername("alinco");
// ds.setPassword("alinco");
// SpringStoredProcedure sp = new SpringStoredProcedure(ds,"PACK_PAGE.GetRecordSet");
//SpringStoredProcedure sp = new SpringStoredProcedure(this.getDataSource(),"PACK_PAGE.GetRecordSet");
//StoredProcedure sq = new StoredProcedure(this.getJdbcTemplate(),"PACK_PAGE.GetRecordSet");
SpringStoredProcedure sp = new SpringStoredProcedure(this.getJdbcTemplate(),"PACK_PAGE.GetRecordSet");
sp.setParameter("vcSql",java.sql.Types.VARCHAR);
sp.setParameter("iMaxNum",java.sql.Types.INTEGER);
sp.setParameter("iNowPage",java.sql.Types.INTEGER);
sp.setOutParameter("rst_cur",oracle.jdbc.OracleTypes.CURSOR);
sp.setOutParameter("err_cur",oracle.jdbc.OracleTypes.CURSOR);
//-------------
Map in = new HashMap();
//OracleLobHandler olh = new OracleLobHandler();
// in.put("vcSql",new SqlLobValue(query, olh));
// in.put("iMaxNum",new SqlLobValue(String.valueOf("1"), olh));
// in.put("iNowPage",new SqlLobValue(String.valueOf(nowPage), olh));
in.put("vcSql",query);
in.put("iMaxNum",String.valueOf("1"));
in.put("iNowPage",String.valueOf(nowPage));
sp.SetInParam(in);
System.out.println("77777777777777777777777");
sp.execute();
System.out.println("888888888888888888888888");
//System.out.println("sp.set.get(0).getClass() = " + sp.set.get(0).getClass());
return null;
}
in.put("iMaxNum",String.valueOf("1"));
in.put("iNowPage",String.valueOf(nowPage));
这2个的问题!
--------------------------------------------------------------
虽然我们设置了这2个参数的类型即:
sp.setParameter("iMaxNum",java.sql.Types.INTEGER);
sp.setParameter("iNowPage",java.sql.Types.INTEGER);
这2句。但是在类型转换时不知道为什么会出错。
---------------------------------------------------------------
而
sp.setParameter("vcSql",java.sql.Types.VARCHAR);
和对应的
in.put("vcSql",query);
却没有问题。
---------------------------------------------------------------
把
in.put("iMaxNum",String.valueOf("1"));
in.put("iNowPage",String.valueOf(nowPage));
该成
in.put("iMaxNum",new Integer(1));
in.put("iNowPage",new Integer(nowPage));
后就可以了!
---------------------------------------------------------------
控制台的错误信息中:
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2804)
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2905)
正是体现了上面的问题~!
偶的能力和语言表达能力有限~!解释的不好就……嘿嘿~!