Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1. package m;
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  *
  11.  * @author Gabriel
  12.  */
  13.  
  14. import java.sql.CallableStatement;
  15. import java.sql.Date;
  16. import java.sql.DriverManager;
  17. import java.sql.Connection;
  18. import java.sql.ResultSet;
  19. import java.sql.SQLException;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22.  
  23. import oracle.jdbc.OracleTypes;
  24.  
  25.  
  26. public class RegistrarEmpresa {
  27.    
  28.     private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
  29.     private static final String DB_CONNECTION = "jdbc:oracle:thin:@dbinf.inf.pucp.edu.pe:1521:DBINF";
  30.     private static final String DB_USER = "A20150862";
  31.     private static final String DB_PASSWORD = "wj5l20w8";
  32.  
  33.    
  34. public static void main(String[] argv) {
  35.          
  36.     String ruc = null;
  37.     String razSoc = null;
  38.     String rubro = null;
  39.     String direccion = null;
  40.     String distrito = null;
  41.     String provincia = null;
  42.     String departamento= null;
  43.    
  44.         try {
  45.  
  46.             callOracleStoredProcCURSORParameter(ruc,razSoc,rubro,direccion,distrito,provincia,departamento);
  47.  
  48.         } catch (SQLException e) {
  49.  
  50.             System.out.println(e.getMessage());
  51.  
  52.         }
  53.  
  54.     }
  55.  
  56. static String callOracleStoredProcCURSORParameter(String ruc, String razSoc,String rubro,String direccion, String distrito, String provincia, String departamento)
  57.             throws SQLException {
  58.                 String resultado =null;        
  59.         Connection dbConnection = null;
  60.         CallableStatement callableStatement = null;
  61.         ResultSet rs = null;
  62.  
  63.         String REGISTRAR_NUEVA_EMPRESA = "{call REGISTRAR_NUEVA_EMPRESA(?,?,?,?,?,?,?,?)}";
  64.              
  65.                 try {
  66.             dbConnection = getDBConnection();
  67.             callableStatement = dbConnection.prepareCall(REGISTRAR_NUEVA_EMPRESA);
  68.  
  69.             callableStatement.setString(1, ruc);
  70.             callableStatement.setString(2, razSoc);
  71.                         callableStatement.setString(3, rubro);
  72.                         callableStatement.setString(4, direccion);
  73.                         callableStatement.setString(5, distrito);
  74.                         callableStatement.setString(6, provincia);
  75.                         callableStatement.setString(7, departamento);
  76.                         callableStatement.setString(8, resultado);
  77.  
  78.                 callableStatement.executeUpdate();            
  79.         resultado = callableStatement.getString(8);
  80.  
  81.         } catch (SQLException e) {
  82.  
  83.             System.out.println(e.getMessage());
  84.  
  85.         } finally {
  86.  
  87.             if (rs != null) {
  88.                 rs.close();
  89.             }
  90.  
  91.             if (callableStatement != null) {
  92.                 callableStatement.close();
  93.             }
  94.  
  95.             if (dbConnection != null) {
  96.                
  97.                             dbConnection.close();
  98.             }
  99.  
  100.         }
  101.                 return resultado;
  102.     }
  103.  
  104.     private static Connection getDBConnection() {
  105.  
  106.         Connection dbConnection = null;
  107.  
  108.         try {
  109.  
  110.             Class.forName(DB_DRIVER);
  111.  
  112.         } catch (ClassNotFoundException e) {
  113.  
  114.             System.out.println(e.getMessage());
  115.  
  116.         }
  117.  
  118.         try {
  119.  
  120.             dbConnection = DriverManager.getConnection(
  121.                 DB_CONNECTION, DB_USER,DB_PASSWORD);
  122.             return dbConnection;
  123.  
  124.         } catch (SQLException e) {
  125.  
  126.             System.out.println(e.getMessage());
  127.  
  128.         }
  129.  
  130.         return dbConnection;
  131.  
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement