Spring JdbcTemplate calls the stored procedure and returns the List object

Source: Internet
Author: User

Note: This article is from the spring jdbctemplate call stored procedure, return list Object


Spring JdbcTemplate calls the stored procedure and returns the List object method:
/** * Call stored procedure * @param spname */@SuppressWarnings ("unchecked") PublicList//procedure = "{call Wcity2_statistic.sp_uservisit_stat (?)}";return(ListNewCallableStatementCallback () { PublicObject doincallablestatement (CallableStatement cs)throwssqlexception,dataaccessexception {listNewArraylist while(Rs.next ()) {hashmap<string, object> DataMap =NewHashmap<string, object> (); ResultSetMetaData rsmatadata = Rs.getmetadata (); for(inti = 1; I <= rsmatadata.getcolumncount (); i++) {datamap.put (Rsmatadata.getcolumnname (i), rs.getstring (Rsmatadata.getcolumnname (i))); List.add (DATAMAP);}returnlist;});}



Stored procedures:
Create or Replace package wcity2_statistic is--Author:administrator  --Created:2012/10/24 9:48:34  --Purpose:Type ref_cursor is Ref Cursor;--Procedure Sp_pager_stats;--access to informationProcedure Sp_uservisit_stat (C_uservisit out ref_cursor), end wcity2_statistic;create or replace package body wcity2_ Statistic is--page InfoProcedure Sp_pager_stats is begin--Cur_page as SELECT * from Oms_wireless. template_file_working;Null End Sp_pager_stats;--access to informationProcedure Sp_uservisit_stat (C_uservisit out ref_cursor) as--Defining cursors    / * Cursor C_uservisit is select T.city,t.username,t.username as Telphone, "as IP from interface_wireless. User_login_log t; * /Begin open C_uservisit for select T.city, T.username, t.username as Telphone, '' As IP from interface_wireless.  User_login_log T; End;end wcity2_statistic;
Call Method:
@SuppressWarnings ("rawtypes") public String Getuservisitstat () {//list Lst=jdbcservice.executesp ("  "); String procedure = "{call Wcity2_statistic.sp_uservisit_stat (?)}"; List Lst=spservice.executesp (procedure); if (lst!=null) {System.out.println (Lst.size ());} return SUCCESS;}




Code that you write yourself

Import Java.sql.callablestatement;import Java.sql.resultset;import Java.sql.resultsetmetadata;import Java.sql.sqlexception;import Java.util.arraylist;import Java.util.hashmap;import Java.util.List;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import org.springframework.beans.factory.annotation.Autowired; Import Org.springframework.dao.dataaccessexception;import Org.springframework.jdbc.core.callablestatementcallback;import org.springframework.jdbc.core.JdbcTemplate;    Import Com.tt.pwp.framework.data.dao.daofactory;import Oracle.jdbc.oracletypes;public class FuncReportTaskService {    Protected final Logger Logger = Loggerfactory.getlogger (This.getclass ()); @Autowired private Daofactory daofactory;/** * Call stored procedure * @param spname */@SuppressWarnings ("unchecked") public list{call Wcity2_statistic.sp_uservisit_stat (?)}"; Return (list

Spring JdbcTemplate calls a stored procedure and returns a list object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.