使用jdbc访问excel作为数据库 [英] accessing excel as database with jdbc
问题描述
我必须设计一个应用程序来访问excel应用程序作为数据库。我的问题是我必须为每个事务创建多个连接,如果我错过任何关闭它,那么excel没有被更新。
I have to design an application for accessing excel application as database. My problem is I have to create multiple connection for each transaction and if I miss any of closing it, the excel is not being update.
我想设计模式,我可以访问excel。任何一个帮助我设计一个通常的模式,我不会有问题。我想要像这个这样的东西,但是我们无法使用它来访问excel。
I want to design pattern where i am able to access the excel. Any one help me in designing a common pattern through which i wont be having problem. I want something like this, but we are not able to use it to access excel.
提前感谢
我在实用程序类中有这个方法
i have this method in utility class
static ResultSet getExcelData(String filePath,String sqlQuery){
ResultSet rs=null;
try{
conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="+filePath+";READONLY=false");
stmt= conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery( sqlQuery );
}catch (Exception e) {
e.printStackTrace();
return null;
// TODO: handle exception
}finally{
}
return rs;
}
我正在以这种方式调用
ResultSet rs=JdbcUtil.getExcelData("D:\\AB_demo\\AB_demo\\test.xls", "Select max(int(ID)) from [MAIN$] where HEADER_IND is not Null AND int(ID)<"+excelId);
int databaseId = 0;
if(rs.next())
{
databaseId=rs.getInt(1);
}
ResultSet rs1=JdbcUtil.getExcelData("D:\\AB_demo\\AB_demo\\test.xls", "SELECT * from [MAIN$] where id= '"+databaseId+"'or id='"+excelId+"'");
我正在调用此方法两次,之后使用
i am calling this method twice after which im updating the excel file by using
stmt.executeUpdate(sql);
它返回整数1,但它没有反映在excel中。当我使用进程资源管理器文件仍然在使用中,我需要一个设计模式或来代码来克服他的那种问题。
its returning the integer 1 but its not reflecting in excel.when i use process explorer the file is still in use.i need a design pattern or come code to overcome his kind of problem.
推荐答案
我认为更正确的方式是生成数据库中的Excel文件。否则,您必须创建服务器端,以确保事务和连接控制。
您的任务的主要问题 - Excel是
I think more right way is generate Excel file from database. Otherwise you must create server side for ensure transactions and connections control. Main problem of your task - Excel is
- 不是数据库
- 不是网络数据库
其他单词您必须使用其他工具,您的任务的其他方法。
这篇关于使用jdbc访问excel作为数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!