例如连接如下数据库
数据库连接字符串:
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.220.4.156)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DATACENTER)
)
)
表名
/*获取指定时间段内更新的0231C、0235C编码集*/
datadba.unv_he_di_pkg.unv_get_prod_items(p_start_date in date,
p_end_date in date,
p_result out cur_data);--游标
第一步:配置数据库连接
# 配置 oracle
oracle:
url: jdbc:oracle:thin:@10.220.4.156:1521/DATACENTER
username: RD_HE
password: rdpehe*123987.
driver-class-name: oracle.jdbc.driver.OracleDriver
第二步:导入pom依赖
<!--oracle-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
第三步:实现
xml类
<!--获取指定时间段内更新的0231C、0235C编码集-->
<select id="selectCodeSetByTime" statementType="CALLABLE" parameterType="map" resultMap="指定映射类的id">
{call datadba.unv_he_di_pkg.unv_get_prod_items(
#{p_start_date,mode=IN,jdbcType=DATE},
#{p_end_date,mode=IN,jdbcType=DATE},
#{p_result,mode=OUT,jdbcType=CURSOR,javaType=ResultSet,resultMap = CodeSetByTimeMap}
)}
</select>
Mapper层
/**
* 获取指定时间段内更新的0231C、0235C编码集
* @param map
* @return
*/
ArrayList<CodeSet> selectCodeSetByTime(HashMap<String, Object> map);
service层
ArrayList<CodeSet> selectCodeSetByTime(HashMap<String, Object> map);
Impl层
@Override
@DS("oracle")
public ArrayList<CodeSet> selectCodeSetByTime(HashMap<String, Object> map) {
return storedProcedureMapper.selectCodeSetByTime(map);
}
HashMap<String, Object> map = new HashMap<>();
Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss").parse("2022-04-19 00:00:00.000");
Date date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss").parse("2022-04-22 00:00:00.000"); map.put("p_start_date", date1);
map.put("p_end_date", date2);
storedProcedureService.selectCodeSetByTime(map);
List<CodeSet> o = (List<CodeSet>) map.get("p_result");
后续根据对应的实体类就可以获得对用的数据
|