Pessoal, estou tentando adaptar o jfilechooser com o meu insert no bd, se puderem me ajudar com dicas de onde estou errando agradeço.
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import org.apache.poi.ss.usermodel.Row;
import jxl.Cell;
import jxl.DateCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import javax.swing.JFileChooser;
public class Insert_xlsJava2 {
private static Connection conn;
private static int i = 0;
private static String stringa1;
private static String stringa2;
private static String stringa3;
public static void main(String[] args )
throws IOException, BiffException,ClassNotFoundException, SQLException {
JFileChooser arquivo = new JFileChooser();
int retorno = arquivo.showOpenDialog(null);
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/bd_hh_fixa","root","");
String caminhoArquivo = "";
if(retorno == JFileChooser.APPROVE_OPTION){
caminhoArquivo = arquivo.getSelectedFile().getAbsolutePath();
Workbook workbook = Workbook.getWorkbook(new File("c:/arquivo.xls"));
Sheet sheet = workbook.getSheet(0);
int linhas = sheet.getRows();
for(i = 0; i < linhas; i++){
Cell a1 = sheet.getCell(0,i);
Cell a2 = sheet.getCell(1,i);
Cell a3 = sheet.getCell(2,i);
stringa1 = a1.getContents();
stringa2 = a2.getContents();
stringa3 = a3.getContents();
PreparedStatement ps = conn.prepareStatement("INSERT INTO teste(nome,prenome,sobrenome)" +
"VALUES('"+stringa1+"','"+stringa2+"','"+stringa3+"')");
ps.executeUpdate();
}
workbook.close();
}else{
}
}
}