Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 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 Integer callOracleStoredProcCURSORParameter(String ruc, String razSoc,String rubro,String direccion, String distrito, String provincia, String departamento)
  57. throws SQLException {
  58. Integer resultado;
  59. resultado = 0;
  60. Connection dbConnection = null;
  61. CallableStatement callableStatement = null;
  62. ResultSet rs = null;
  63.  
  64. String REGISTRAR_NUEVA_EMPRESA = "{call REGISTRAR_NUEVA_EMPRESA(?,?,?,?,?,?,?,?)}";
  65.  
  66. try {
  67. dbConnection = getDBConnection();
  68. callableStatement = dbConnection.prepareCall(REGISTRAR_NUEVA_EMPRESA);
  69.  
  70. callableStatement.setString(1, ruc);
  71. callableStatement.setString(2, razSoc);
  72. callableStatement.setString(3, rubro);
  73. callableStatement.setString(4, direccion);
  74. callableStatement.setString(5, distrito);
  75. callableStatement.setString(6, provincia);
  76. callableStatement.setString(7, departamento);
  77. callableStatement.setInt(8, resultado);
  78.  
  79.  
  80. callableStatement.executeUpdate();
  81. resultado = callableStatement.getInt(8);
  82.  
  83. } catch (SQLException e) {
  84.  
  85. System.out.println(e.getMessage());
  86.  
  87. } finally {
  88.  
  89. if (rs != null) {
  90. rs.close();
  91. }
  92.  
  93. if (callableStatement != null) {
  94. callableStatement.close();
  95. }
  96.  
  97. if (dbConnection != null) {
  98. dbConnection.close();
  99. }
  100.  
  101. }
  102. return resultado;
  103. }
  104.  
  105. private static Connection getDBConnection() {
  106.  
  107. Connection dbConnection = null;
  108.  
  109. try {
  110.  
  111. Class.forName(DB_DRIVER);
  112.  
  113. } catch (ClassNotFoundException e) {
  114.  
  115. System.out.println(e.getMessage());
  116.  
  117. }
  118.  
  119. try {
  120.  
  121. dbConnection = DriverManager.getConnection(
  122. DB_CONNECTION, DB_USER,DB_PASSWORD);
  123. return dbConnection;
  124.  
  125. } catch (SQLException e) {
  126.  
  127. System.out.println(e.getMessage());
  128.  
  129. }
  130.  
  131. return dbConnection;
  132.  
  133. }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement