用jxl.jar包将excel文件导入oracle中出现了乱码问题,代码如下,求解决
packagexls;importjava.io.File;importjava.io.IOException;importjava.sql.CallableStatem...
package xls;
import java.io.File;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import dao.DataAccess;
public class loadEXCEL{
public static Connection con=null;
public static void build(Connection conn) throws BiffException, IOException{
File excelfile = new File("D://test.xls");
Workbook book = null;
CallableStatement st = null;
int rownum;
String name = null;
String sex = null;
try{
book = Workbook.getWorkbook(excelfile);
Sheet sheet = book.getSheet(0);//工作簿是从0开始的
for(rownum=1;rownum<sheet.getRows();rownum++){
name = sheet.getCell(0,rownum).getContents().trim();//参数顺序为(列,行)
sex = sheet.getCell(1,rownum).getContents().trim();//getContents().trim()是获取单元格内的值并去空格
try{
st = conn.prepareCall("insert into test_table values (?,?)");//这里是执行插入操作,可以换成别的如UPDATE
st.setString(1, name);
st.setString(2, sex);
st.execute();
st.close();
System.out.println("第"+rownum+"条记录!");
}catch (SQLException e) {
e.printStackTrace();
}
}
}finally{
}
}
public static void main(String [] arg) throws BiffException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
Connection co = DataAccess.getConnection();
co.setAutoCommit(true);
loadEXCEL.build(co);
co.close();
System.out.println("JUST OK!!!");
}
} 展开
import java.io.File;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import dao.DataAccess;
public class loadEXCEL{
public static Connection con=null;
public static void build(Connection conn) throws BiffException, IOException{
File excelfile = new File("D://test.xls");
Workbook book = null;
CallableStatement st = null;
int rownum;
String name = null;
String sex = null;
try{
book = Workbook.getWorkbook(excelfile);
Sheet sheet = book.getSheet(0);//工作簿是从0开始的
for(rownum=1;rownum<sheet.getRows();rownum++){
name = sheet.getCell(0,rownum).getContents().trim();//参数顺序为(列,行)
sex = sheet.getCell(1,rownum).getContents().trim();//getContents().trim()是获取单元格内的值并去空格
try{
st = conn.prepareCall("insert into test_table values (?,?)");//这里是执行插入操作,可以换成别的如UPDATE
st.setString(1, name);
st.setString(2, sex);
st.execute();
st.close();
System.out.println("第"+rownum+"条记录!");
}catch (SQLException e) {
e.printStackTrace();
}
}
}finally{
}
}
public static void main(String [] arg) throws BiffException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
Connection co = DataAccess.getConnection();
co.setAutoCommit(true);
loadEXCEL.build(co);
co.close();
System.out.println("JUST OK!!!");
}
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询