使用jxl读取数据库,代码如下:
package test;
import java.io.*;
import jxl.*;
public class ReadExcel {
public void readExcel(String strPath) throws Exception{
System.out.println(strPath);
File file=new File(strPath);
Workbook workBook = Workbook.getWorkbook(file);
Sheet sheet=workBook.getSheet(0);
Cell[] row;
Cell cell;
for (int i = 0; i < sheet.getRows(); i++) {
row = sheet.getRow(i);
for (int j = 0; j < row.length; j++) {
cell = row[j];
System.out.print(cell.getContents()+" type:"+cell.getType() + "\t");
}
System.out.println("");
}
workBook.close();
}
public static void main(String[] args) {
try {
new ReadExcel().readExcel("E:\\text.xls");
} catch (Exception e) {
e.printStackTrace();
}
}
}
出现该异常,具体内容为:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at test.ReadExcel.readExcel(ReadExcel.java:11)
at test.ReadExcel.main(ReadExcel.java:29)
网上搜索原因说是因为JDK存在不同版本的问题,修改以后依旧报错,困扰,希望能得到大家的帮助。