使用excel表作为数据库与java [英] Using excel sheet as a database with java

查看:159
本文介绍了使用excel表作为数据库与java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能的方法来比较用户在java

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

中的输入与excel表中的几个属性值?

with several attribute value in excel sheet?

我尝试从用户(症状)中读取6个输入,并将其与

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_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:


您是否遇到以上症状,您可以在下拉列表中选择用于从中进行选择的symbols_1

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

值。

例如:如果我从第一个下拉列表中选择fever(所有值









$ b b symptoms_1),在java我想增加疾病1和疾病2 20%和

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

然后当我选择干咳嗽在第二个下拉列表(所有值
symptoms_2),所以disease_1将是40%。

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

我的问题是这种方式可能在java使用excel作为数据库?

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

如果没有请提出想法解决这个问题。

if not please give an idea to solve this problem.

谢谢。

推荐答案

这是可能的。将Excel文件作为数据库,将工作表作为表中的表和列作为表的列。

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

1 - 您需要将JDBC ODBC驱动程序添加到项目中。

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

2 - 下面的代码可能会帮助您获取下拉列表的来源(用户选择)。它假定您有一个Excel文件,其中sheet1是您的症状表。 sheet1有列symbols_1,symptoms_2,...

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();
  }
}

希望它有帮助。

这篇关于使用excel表作为数据库与java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆