java通过桥访问excel_javajdbc-odbc桥读取excel指导.doc

javajdbc-odbc桥读取excel指导.doc

2660c5c4a0c40882f572c3e1e4f82a63.gif

还剩

7页未读,

继续阅读

下载文档到电脑,马上远离加班熬夜!

亲,喜欢就下载吧,价低环保!

内容要点:

专门操作 EXCEL 文件的 Java API。Jakarta POI 和 Java Excel API 就是其中的两个 Open Source项目。感兴趣的可以从网上搜索一下,应该会有很多关于的资料。 ExcelAccess ea = new ExcelAccess();HashMap res = null;if (!ea.openConnection()) {System.err.println("open connection err.");System.exit(1);}// get emp# 1000's informationSystem.out.println("Get Emp# 1000:");res = ea.getEmpInfo(1000);if (res != null) {Collection c = res.keySet();Iterator i = c.iterator();while (i.hasNext()) {Object key = i.next();Object value = res.get(key);System.out.println(key + "\t" + value);}// while ends}// insert a new record into the tableint ret = ea.insertEmpInfo(1005, "Yanjiang", 'M',"PM", "[email protected]");if (ret == 1) {System.out.println("emp# 1005 inserting success.");}// close the connectionea.closeConnection();}}运行结果:Get Emp# 1000:Email [email protected] MTitle PMName Jesse, G.ID 1000.0emp# 1005 inserting success.总结到此这篇文章就结束了,这个例子实现了 Java读写 Excel文件,类似,我们可以去读写 dBase、Access 文件等。还有就是这个简单的例子充 分说明了当初设计 JDBC,ODBC 等驱动的英明之处。值得一提的是,现在已有了比较成 熟的 return result;}public int insertEmpInfo(int id, String name, char gender, String title, String email) {int result = -1;if (stmnt == null)return result;// generate the query stringString query = "INSERT INTO [Sheet1$] VALUES(";query += id + ", ";query += "'" + name + "', ";query += "'" + gender + "', ";query += "'" + title + "', ";query += "'" + email + "'";query += " )";try {// execute the queryresult = stmnt.executeUpdate(query);} catch (SQLException e) {e.printStackTrace();}return result;}/*** close the connection*/public boolean closeConnection() {try {if (stmnt != null)stmnt.close();i

发表评论

暂无评论,赶快抢占沙发吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值