使用 excel sheet 作为数据库 java
Using excel sheet as a database with java
是否有可能比较 java
中用户的输入
在excelsheet中有几个属性值?
我正在尝试读取用户的 6 个输入(症状)并将其与
进行比较
我的疾病症状中的每个属性值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 |
------------------------------------------------------------------------
首先,应用程序会询问:
do you experience any of these symptoms, then it shows all symptoms_1
用户从中 select 的下拉列表中的值。然后它问
以同样的方式处理下一个症状。
ex: 如果我 select 从第一个下拉列表中发烧(所有值
symptoms_1), 在 java 我想将疾病 1 和疾病 2 增加 20% 并且
然后当我在第二个下拉列表中 select 干咳时(所有值
symptoms_2), 所以 disease_1 将是 40%.
我的问题是在 java 中使用 excel 作为数据库是否可行?
如果没有请给出解决这个问题的想法。
谢谢。
有可能。将 Excel 文件作为数据库,工作表作为 tables,工作表中的列作为 tables 的列。
1 - 您需要将 JDBC ODBC 驱动程序添加到您的项目中。
2 - 下面的代码可以帮助您获取下拉列表的来源(用户选择)。它假定您有一个 Excel 文件,其中 sheet1 是您的症状 table。 sheet1 有列 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();
}
}
希望对您有所帮助。
是否有可能比较 java
中用户的输入在excelsheet中有几个属性值?
我正在尝试读取用户的 6 个输入(症状)并将其与
进行比较我的疾病症状中的每个属性值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 |
------------------------------------------------------------------------
首先,应用程序会询问:
do you experience any of these symptoms, then it shows all symptoms_1
用户从中 select 的下拉列表中的值。然后它问 以同样的方式处理下一个症状。
ex: 如果我 select 从第一个下拉列表中发烧(所有值 symptoms_1), 在 java 我想将疾病 1 和疾病 2 增加 20% 并且
然后当我在第二个下拉列表中 select 干咳时(所有值 symptoms_2), 所以 disease_1 将是 40%.
我的问题是在 java 中使用 excel 作为数据库是否可行?
如果没有请给出解决这个问题的想法。
谢谢。
有可能。将 Excel 文件作为数据库,工作表作为 tables,工作表中的列作为 tables 的列。
1 - 您需要将 JDBC ODBC 驱动程序添加到您的项目中。
2 - 下面的代码可以帮助您获取下拉列表的来源(用户选择)。它假定您有一个 Excel 文件,其中 sheet1 是您的症状 table。 sheet1 有列 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();
}
}
希望对您有所帮助。