gpt4 book ai didi

java - 创建 JTextArea

转载 作者:行者123 更新时间:2023-12-01 15:15:55 26 4
gpt4 key购买 nike

我正在使用一些代码来获取文件名并将其存储在数据库中,一切正常,但我想显示它存储在 TextArea 上的文件,我该怎么做?

这是用于存储文件名的代码。顺便说一句,我正在 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);
}

}

提前致谢。

最佳答案

  • 从数据库读取文件名:

"Select fileName from YourTable"

  • 将名称添加到 for-each 中的文本区域

textArea.append(fileName + "\n");

关于java - 创建 JTextArea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11619183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com