codice:
public void jButton11_ActionPerformed(java.awt.event.ActionEvent actionEvent)
{
String [] c=new String[]{".autore.nome_arte","",""};
String [] v=new String[]{"beatles","",""};
String sql=multiSelect(c,v);
int p;
//comtrollo se l'anno è inserito
pathfile="";
if((ivjAnno.isSelected()==true)&&(ivjAnT.getText().equals("")))
{//nn si puo' proseguire
Object[] options = {"OK"};
JOptionPane.showOptionDialog(null, "Impossibile esportare i dati.\nBisogna inserire un anno", "Errore di selezione",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
}
else
{
try
{
//controllo i campi selezionati e inizializzo il contatore
int n=3;
if (ivjAutore.isSelected()==false)
n--;
if(ivjAnno.isSelected()==false)
n--;
if(ivjGenere.isSelected()==false)
n--;
//se è stato inserito almeno un campo
if(n>0)
{
//imposto i parametri x la multiselect
String [] campi=new String[]{"","",""};
String [] valori=new String[]{"","",""};
if(ivjGenere.isSelected()==true)
{
n--;
campi[n]=".genere.genere";
valori[n]=(String)(ivjJComboBox11.getSelectedItem());
}
if(ivjAnno.isSelected()==true)
{
n--;
campi[n]=".album.anno";
valori[n]=ivjAnT.getText();
}
if(ivjAutore.isSelected()==true)
{
n--;
campi[n]=".autore.nome_arte";
valori[n]=(String)(ivjJComboBox1.getSelectedItem());
}
//ricavo la stringa SQL
String sqp=multiSelect(campi,valori);
//creo un file dialog
FileDialog d = new FileDialog(this, "Seleziona un file", FileDialog.SAVE);
d.setDirectory("c:\\Documents and Settings\\generale\\Desktop");
d.setVisible(true);
//se è stato inserito un file
if(d.getFile()!="")
{
File file = new File(d.getDirectory()+d.getFile());
//se il file nn esiste lo creo
if (!file.exists())
{
try
{
boolean creato = file.createNewFile();
if (creato)
{
pathfile=d.getDirectory()+d.getFile();
}// file creato
}catch (IOException ioex)
{ // file non creato }
}
}
else
{
pathfile=d.getDirectory()+d.getFile();
}
if(pathfile!="")
{
try
{
try
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (ClassNotFoundException e){}
}catch (InstantiationException f){}
}catch (IllegalAccessException g){}
try{
try{
try
{
java.sql.Connection conn;
conn=DriverManager.getConnection("jdbc:mysql://localhost/dbdischi");
java.sql.Statement stmt=conn.createStatement();
java.sql.ResultSet rs = stmt.executeQuery (sql);
java.sql.ResultSetMetaData stmd=rs.getMetaData();
int i=stmd.getColumnCount();
if(i>0)
{
rs.next();
//creo un foglio
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("DbDischi 1");
//salvo nel file
for(int j=0;j<i;j++)
{
// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short)j);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(j+1);
for (int k=1;k<i+1;k++)
{
p=k+1;
row.createCell((short)p).setCellValue(rs.getString(k));
}
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(pathfile);
wb.write(fileOut);
fileOut.close();
Object[] options = {"OK"};
JOptionPane.showOptionDialog(null, "Esportazione effettuata con successo.", "OK",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, options, options[0]);
ivjTTDB.dispose();
}else
{
Object[] options = {"OK"};
JOptionPane.showOptionDialog(null, "Esportazione non effettuata.\nDataBase vuoto", "DataBase vuoto",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
this.dispose();
}
}catch (SQLException e){}
}catch(java.io.FileNotFoundException fnf){}
}catch(java.io.IOException ioe){}
}
}
}
}
}catch(com.ibm.db.DataException de){}
return;
}
perchè mi dice che l'ultimo catch nn è raggiungibile???
Vi prego ci lavoro da un casino ma nn so cosa fare:master: