i’m using some code to getfilenames and store it on a DB and everything works fine, but i wanted to show what files it stored on a TextArea, how can i do it?
Here is the code used to store the file names. BTW i’m doing this in NetBeans.
private void ActualizerBDActionPerformed(java.awt.event.ActionEvent evt) {
Conectar();
File folder = null;
try {
String ppp = new File(".").getCanonicalPath();
folder = new File(ppp + "\\ImagensDB");
} catch (IOException iOException) {
}
File[] listOfFiles = folder.listFiles();
String query = "insert into dados (Num, Nome, Autor, Data, Preco, Categoria)" +"values(?,?,?,?,?,?)";
PreparedStatement prepStmt=null;
try {
prepStmt = con.prepareStatement(query);
} catch (SQLException ex) {
Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
for (int j = 0; j < listOfFiles.length; j++) {
if (listOfFiles[j].isFile()) {
try {
String text = listOfFiles[j].getName();
String txsp[] = text.split("-");
prepStmt.setString(1, txsp[0]);
prepStmt.setString(2, txsp[1]);
prepStmt.setString(3, txsp[2]);
prepStmt.setString(4, txsp[3]);
prepStmt.setString(5, txsp[4]);
prepStmt.setString(6, txsp[5]);
prepStmt.execute(); // executa o INSERT
} catch (SQLException ex) {
Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
JOptionPane.showMessageDialog(null, "Dados Introduzidos com Sucesso!");
try {
con.close();
} catch (SQLException ex) {
Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
}
Thanks in advance.
Somewhere here you could
Of course you need to have build the ui first! Check out this for more elp