Advertisement
sergAccount

Untitled

Sep 27th, 2020
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.spec.service;
  7.  
  8. import com.spec.DBUtil;
  9. import java.sql.CallableStatement;
  10. import java.sql.Connection;
  11. import java.sql.SQLException;
  12. import java.sql.Types;
  13.  
  14. /**
  15.  *
  16.  * @author Admin
  17.  */
  18. public class TestProcService {
  19.    
  20.     //
  21.     public String testCall(final String value) throws Exception{
  22.        
  23.         String sql = "{? = call lower(?)}";
  24.         try(Connection c = DBUtil.getConn(); CallableStatement cs = c.prepareCall(sql); ){              
  25.             // установка типа возвращаемого значения для функции
  26.             cs.registerOutParameter(1, Types.VARCHAR);
  27.             cs.setString(2, value);            
  28.             // выполнение вывозва функции
  29.             cs.execute();                      
  30.             // получение рез-та в соответсвии с типом
  31.             String result = cs.getString(1);            
  32.             return result;
  33.         }catch(SQLException ex){
  34.             ex.printStackTrace();
  35.             throw new Exception("error while testCall", ex);
  36.         }                
  37.     }    
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement