Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.InputStreamReader;
- import java.sql.DriverManager;
- import java.util.LinkedList;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.sql.Connection;
- public class Diagnostico {
- private final String DATAFILE = "data/disease_data.data";
- private Connection conn = null;
- private void showMenu() {
- int option = -1;
- do {
- System.out.println("Bienvenido a sistema de diagnóstico\n");
- System.out.println("Selecciona una opción:\n");
- System.out.println("\t1. Creación de base de datos y carga de datos.");
- System.out.println("\t2. Realizar diagnóstico.");
- System.out.println("\t3. Listar síntomas de una enfermedad.");
- System.out.println("\t4. Listar enfermedades y sus códigos asociados.");
- System.out.println("\t5. Listar síntomas existentes en la BD y su tipo semántico.");
- System.out.println("\t6. Mostrar estadísticas de la base de datos.");
- System.out.println("\t7. Salir.");
- try {
- option = readInt();
- switch (option) {
- case 1:
- crearBD();
- break;
- case 2:
- realizarDiagnostico();
- break;
- case 3:
- listarSintomasEnfermedad();
- break;
- case 4:
- listarEnfermedadesYCodigosAsociados();
- break;
- case 5:
- listarSintomasYTiposSemanticos();
- break;
- case 6:
- mostrarEstadisticasBD();
- break;
- case 7:
- exit();
- break;
- }
- } catch (Exception e) {
- System.err.println("Opción introducida no válida!");
- }
- } while (option != 7);
- exit();
- }
- private void exit() {
- if (conn != null){
- try{
- if(!conn.isClosed())
- conn.close();
- }
- catch (Exception e){
- System.out.println("No se pudo desconectar de la base de datos");
- }
- }
- System.out.println("Saliendo.. ¡hasta otra!");
- System.exit(0);
- }
- private void conectar() throws Exception {
- String drv ="com.mysql.jdbc.Driver";
- Class.forName(drv).newInstance();
- String serverAddress = "localhost:3306";
- String db = "diagnostico";
- String user = "bddx";
- String pwd = "bddx_pwd";
- String url = "jdbc:mysql://" + serverAddress + "/" + db;
- conn = DriverManager.getConnection(url, user, pwd);
- if (!conn.isClosed()){
- System.out.println("¡Conectado a la base de datos!");
- }
- }
- private void crearBD() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- private void realizarDiagnostico() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- private void listarSintomasEnfermedad() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- private void listarEnfermedadesYCodigosAsociados() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- private void listarSintomasYTiposSemanticos() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- private void mostrarEstadisticasBD() {
- try {
- if (conn == null || conn.isClosed())
- this.conectar();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- /* Lo que tenga que hacer */
- }
- /**
- * Método para leer números enteros de teclado.
- *
- * @return Devuelve el número leído.
- * @throws Exception
- * Puede lanzar excepción.
- */
- private int readInt() throws Exception {
- try {
- System.out.print("> ");
- return Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
- } catch (Exception e) {
- throw new Exception("Not number");
- }
- }
- /**
- * Método para leer cadenas de teclado.
- *
- * @return Devuelve la cadena leída.
- * @throws Exception
- * Puede lanzar excepción.
- */
- private String readString() throws Exception {
- try {
- System.out.print("> ");
- return new BufferedReader(new InputStreamReader(System.in)).readLine();
- } catch (Exception e) {
- throw new Exception("Error reading line");
- }
- }
- /**
- * Método para leer el fichero que contiene los datos.
- *
- * @return Devuelve una lista de String con el contenido.
- * @throws Exception
- * Puede lanzar excepción.
- */
- private LinkedList<String> readData() throws Exception {
- LinkedList<String> data = new LinkedList<String>();
- BufferedReader bL = new BufferedReader(new FileReader(DATAFILE));
- while (bL.ready()) {
- data.add(bL.readLine());
- }
- bL.close();
- return data;
- }
- public static void main(String args[]) throws Exception {
- new Diagnostico().showMenu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement