Entradas

Mostrando entradas de octubre, 2015

Conexion Java con SQL Server

package com.sql; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JOptionPane; public class Conexion {     //var     private Connection cone=null;     //constructor     public Conexion(){         try{             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");             String url="jdbc:sqlserver://localhost:1433;databaseName=BD_Supermercado;";             cone=DriverManager.getConnection(url, "sa", "xxxxx");         }catch(SQLException ex){             JOptionPane.showMessageDialog(null, "Error Servidor:"                     +ex.getMessage());         }catch(Exception e){             JOptionPane.showMessageDialog(null, "Error Driver:"                     +e.getMessage());         }     }     //metodo     public Connection getConnection(){         return cone;     } }

FUNCIONES EN ORACLE

--FUNCIONES EN ORACLE --esta funcion retorna el nombre del empleado a partir del codigo create or replace function f_nom_emple(v_cod in number)   return varchar2 is   v_nom varchar2(20); begin   select first_name into v_nom   from employees   where employee_id = v_cod;   return v_nom; end; --ejecutando la funcion select f_nom_emple(105) from dual; --funcion que muestra el sueldo mas alto de los empleados create or replace function f_sueldo_alto   return number is   v_salario number(8,2); begin   select max(salary) into v_salario   from employees;       return v_salario; end; --ejecutar select f_sueldo_alto as salario_alto from dual; --funcion que muestra el codigo de pais a partir del nombre de pais create or replace function f_codpais(v_nompais in varchar2)   return char is  v_codpais char(2); begin      select country_id into v_codpais      from countries      where country_name = v_nompais;          return v_codpais; end; --ejecutar select