Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/09/2011, 14:36
VivaElPirateo
 
Fecha de Ingreso: septiembre-2011
Mensajes: 40
Antigüedad: 12 años, 7 meses
Puntos: 0
Pregunta Excepciones por consola Java

Buenas tardes comunidad:

Estoy haciendo una aplicación por consola en el programa Eclipse (Java), y tengo problemas en el manejo de excepciones por medio de la consola.

Cuento corto: necesito que al ingresar el nombre, este debe tener como mínimo 2 caracteres y máximo 30.


Acá dejo la clase Menu:


package ProcedimientoAlmacenado;

import java.sql.*;
import java.util.*;
import java.io.*;

public class callableDemo extends Carga.Persona{
private Connection Conexion;
private CallableStatement cstmt = null ;


public callableDemo(String nombre, String apellido, String rut, Connection Con)
{
super(nombre, apellido, rut);
Conexion = Con;
}

public static void main(String args[]) throws Exception
{

Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://MARTE:1433;DatabaseName=Prueba", "sa", "gsiinformatica");
//Step-1

CallableStatement cstmt = con.prepareCall("{call ProcedAlmac_ExcepcionesFinal(?,?,?)}");
Scanner sc=new Scanner(System.in);


// Si fuese integer System.out.print("Enter the Employee No: ");
//int x=sc.nextInt();


// static void AtajaErrores(String nombre)

System.out.print("Ingrese el nombre: ");
// {
// if (nombre.trim().length()<2 || nombre.trim().length()>30)
// {
String nombre = sc.next().toUpperCase();
// }
// else
// {
// System.out.print("El nombre debe tener entre 2 y 30 letras...");
// }
// }
// catch (ExcepcionNombre e1)
// {
// System.out.println(e1);
// }
// }

//if (nombre.length()<2 && nombre.length()>30 );{
//System.out.println("El nombre debe tener entre 2 y 30 letras");
// }
System.out.print("Ingrese el apellido: ");

String apellido = sc.next();
//try{
//System.out.print("Ingrese el apellido: ");

//}catch(IOException e){System.out.println("El nombre debe tener entre 2 y 30 letras");}
//String apellido = sc.next();
//}



System.out.println("Ingrese el RUT: ");
String rut = sc.next();



//Step-2
cstmt.setString(1,nombre);
cstmt.setString(2,apellido);
cstmt.setString(3,rut);
//Step -3
cstmt.execute();
System.out.println("***Llamada a Procedimiento Almacenado****");
System.out.println("Registro Agregado con Exito");
con.close();
}
}


Y acá les dejo la clase Persona, de la cual pretendo heredar los métodos void para modificar:



package Carga;

public class Persona {

protected static String nombre;
protected static String apellido;
protected static String rut;

// METODO CONSTRUCTOR CON PARAMETROS //

public Persona (String nombre, String apellido, String rut)
{
setNombre(nombre);
setApellido(apellido);
setRut(rut);
}


// METODOS ACCESADORES DE NOMBRE, APELLIDO Y RUT//

protected static String getNombre ()
{
return nombre;
}

protected static String getApellido()
{
return apellido;
}
public String getRut()
{
return rut;
}

// METODOS MUTADORES DE NOMBRE, APELLIDO Y RUT//

public static void setNombre (String nombre)
{
if ((nombre.trim().length()<=2) || (nombre.trim().length()>=30))
{
nombre = nombre.trim();
}
else
{
System.out.print ("Debe ingresar un nombre válido");
}
}

public void setApellido (String apellido)
{
if ((apellido.trim().length()<=2)||(apellido.trim().l ength()>=20))
{
this.apellido = apellido.trim();
}
else
{
System.out.println ("Debe ingresar un apellido válido");
}
}

public void setRut (String rut)
{
if ((rut.trim().length()<10)|| (rut.trim().length()>12))
{
this.rut = rut.trim();
}
else
{
System.out.println ("Debe de ingresar un RUT con puntos y guion");
}
}

public void printMenu()
{
System.out.println ("El nombre de la persona es: "+ getNombre() );
System.out.println ("El apellido de la persona es: "+ getApellido() );
System.out.println ("El numero de la persona es: "+ getRut() );
}
}



Ayuda, por favor!!!!!!!!!


Lo otro: NO SÉ CÓMO VALIDAR EL RUT PARA QUE, POR EJEMPLO, AL INGRESARLO CON O SIN PUNTOS O GUIÓN, INGRESE A LA BASE DE DATOS CON LOS PUNTOS Y GUIÓN.

Ej: 161503337 ---> 16.150.333-0