帮助我坚持这个从结果集导出到excel的项目.此前的解决方案还没有回答我的问题,但是他们帮助了..到目前为止,我的代码只显示数据库中的一行.
我的守则
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class Plexada2 {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:Storeway","root", "");
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("Select * from Storeway.order");
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("lawix10");
Row row = sheet.createRow(0);
int x=0;
while (rs.next()){
String crate_id= rs.getString(2);
String content=rs.getString(3);
String Order_type= rs.getString(4);
java.sql.Date date= rs.getDate(5);
String datex= String.valueOf(date);
row.createCell(0).setCellValue(crate_id);
row.createCell(1).setCellValue(content);
row.createCell(2).setCellValue(Order_type);
row.createCell(3).setCellValue(datex);
}
x+=1;
String yemi = "C:\\Users\\lawix10\\Desktop\\testlno9.xls";
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream(yemi);
workbook.write(fileOut);
fileOut.close();
}