2

is there a possible way to compare an input from user in java

with several attribute value in excel sheet?

I am trying to read 6 input from the user (Symptoms) and compare it with

each attribute values in my disease symptoms excel sheet.

disease symptoms is something like this:

------------------------------------------------------------------------
disease_id | disease name | symptoms_1     | symptoms_2    | symptoms_3 |..

    1      |  flu         |  fever         |  dry cough    | headache  |
    2      |  diarrhea    |abdominal cramps| abdominal pain| fever     |

------------------------------------------------------------------------

first, the application will ask:

do you experience any of these symptoms, then it shows all symptoms_1

values in a drop-down list for user to select from it. then the it asks for the next symptoms same way.

ex: if I select fever from the first drop-down list(all values of symptoms_1), in java I want to increase disease 1 and disease 2 by 20% and

then when I select dry cough in the second drop-down list(all values of symptoms_2), so disease_1 will be 40%.

My question is this way is possible in java using excel as a database?

if not please give an idea to solve this problem.

Thanks.

8
  • 2
    There's a JDBC driver for Excel files, is that what you're looking for? Commented Sep 12, 2015 at 12:55
  • Or use Apache POI directly to read the file. Commented Sep 12, 2015 at 12:58
  • 2
    @Andreas the JDBC driver uses POI as its underpinnings, and POI is a fantastic piece of kit, but let's politely say it has a certain learning curve :) Commented Sep 12, 2015 at 12:59
  • why is a database not an option, you can use an embedded or in-memory db if you want to package as an application, I think it will be more efficient using a db Commented Sep 12, 2015 at 13:03
  • guys can you explain in more details. thanks Commented Sep 12, 2015 at 13:15

1 Answer 1

2

It's possible. Take the Excel file as the database, sheets as tables and columns in sheets as columns for your tables.

1 - You need to add the JDBC ODBC driver to your project.

2 - The code below may help you get the source of your drop-down list (user choices). It assumes that you have an Excel File with a sheet1 being your Symptoms table. sheet1 has columns symptoms_1, symptoms_2, ...

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {

    public static Connection getConnection() throws Exception {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:excelDB";
    String username = "yourName";
    String password = "yourPass";
    Class.forName(driver);
    return DriverManager.getConnection(url, username, password);
}

public static void main(String args[]) throws Exception {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    conn = getConnection();
    stmt = conn.createStatement();
    String excelQuery = "select symptoms_1 from [Sheet1$]";
    rs = stmt.executeQuery(excelQuery);

    while (rs.next()) {
      //Fill the data for your drop-down list
    }

    rs.close();
    stmt.close();
    conn.close();
  }
}

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

what data to be filled in this part ? while (rs.next()) { //Fill the data for your drop-down list }
Before the while loop, you created a collection or an array that will contain values to be displayed in the drop-down list. In the while loop you fill that collection with values from the ResultSet. Later when you create the drop-down list (ComboBox) you just set that collection as its source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.