Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package m;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Gabriel
- */
- import java.sql.CallableStatement;
- import java.sql.Date;
- import java.sql.DriverManager;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import oracle.jdbc.OracleTypes;
- public class RegistrarEmpresa {
- private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
- private static final String DB_CONNECTION = "jdbc:oracle:thin:@dbinf.inf.pucp.edu.pe:1521:DBINF";
- private static final String DB_USER = "A20150862";
- private static final String DB_PASSWORD = "wj5l20w8";
- public static void main(String[] argv) {
- String ruc = null;
- String razSoc = null;
- String rubro = null;
- String direccion = null;
- String distrito = null;
- String provincia = null;
- String departamento= null;
- try {
- callOracleStoredProcCURSORParameter(ruc,razSoc,rubro,direccion,distrito,provincia,departamento);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- static String callOracleStoredProcCURSORParameter(String ruc, String razSoc,String rubro,String direccion, String distrito, String provincia, String departamento)
- throws SQLException {
- String resultado =null;
- Connection dbConnection = null;
- CallableStatement callableStatement = null;
- ResultSet rs = null;
- String REGISTRAR_NUEVA_EMPRESA = "{call REGISTRAR_NUEVA_EMPRESA(?,?,?,?,?,?,?,?)}";
- try {
- dbConnection = getDBConnection();
- callableStatement = dbConnection.prepareCall(REGISTRAR_NUEVA_EMPRESA);
- callableStatement.setString(1, ruc);
- callableStatement.setString(2, razSoc);
- callableStatement.setString(3, rubro);
- callableStatement.setString(4, direccion);
- callableStatement.setString(5, distrito);
- callableStatement.setString(6, provincia);
- callableStatement.setString(7, departamento);
- callableStatement.setString(8, resultado);
- callableStatement.executeUpdate();
- resultado = callableStatement.getString(8);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (rs != null) {
- rs.close();
- }
- if (callableStatement != null) {
- callableStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- return resultado;
- }
- private static Connection getDBConnection() {
- Connection dbConnection = null;
- try {
- Class.forName(DB_DRIVER);
- } catch (ClassNotFoundException e) {
- System.out.println(e.getMessage());
- }
- try {
- dbConnection = DriverManager.getConnection(
- DB_CONNECTION, DB_USER,DB_PASSWORD);
- return dbConnection;
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- return dbConnection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement