Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从数据库获取的jtable列表中双击一行打开文档_Java - Fatal编程技术网

Java 如何从数据库获取的jtable列表中双击一行打开文档

Java 如何从数据库获取的jtable列表中双击一行打开文档,java,Java,JFilechooser选择我要上传到数据库中的文档,选择的文件名将被上传到数据库和文件夹中的文件,我还可以通过gui在我的jtable中显示数据库表。现在我需要做的是双击我想要打开文档的任何表的行。我将如何做到这一点 //code to attach the document to a folder and its name to the database private void add_newActionPerformed(java.awt.event.ActionEvent e

JFilechooser选择我要上传到数据库中的文档,选择的文件名将被上传到数据库和文件夹中的文件,我还可以通过gui在我的jtable中显示数据库表。现在我需要做的是双击我想要打开文档的任何表的行。我将如何做到这一点

//code to attach the document to a folder and its name to the database

    private void add_newActionPerformed(java.awt.event.ActionEvent evt){                                          
try {
JFileChooser selectedFile = new JFileChooser();
int a = selectedFile.showOpenDialog(null);
File file = selectedFile.getSelectedFile();
Path dscPath = Paths.get(Paths.get("").toAbsolutePath()+ "\\store\\"+file.getName());
Path path = Files.copy(Paths.get(file.getAbsolutePath()), dscPath  ,StandardCopyOption.REPLACE_EXISTING);

SqlFunctions sql = new SqlFunctions();
sql.StoreFileName(file.getName());

System.out.println("File uploaded is "+file.getName());

    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
}      

//用于从数据库填充jtable数据的代码 私有void更新_表(){ 试一试{

}

//方法在数据库中存储文件名

 public void StoreFileName(String fileName){
    String sql = "INSERT INTO files VALUES ("+null+",'"+fileName+"')";
   // String sql = "insert into files(fileName) "+ "values(?)";
    System.out.println(sql);

    try {
        stmt.executeUpdate(sql);
    } catch (SQLException ex) {
        System.out.println("Exception: "+ex.getMessage() );
    }catch (Exception ex){
        System.out.println("Error");
    }
}
}
我还没有实现mouseclick事件的代码来直接打开文档

应用一些逻辑来双击

使用类似于标志的东西,第一次单击后为1,第二次单击后为2。仅当flag=2时才打开文档


您可以使用鼠标侦听器执行此操作。

我们可以看看您的代码吗?请不要要求我们做作业//从数据库私有void Update_table()填充jtable数据的代码{try{Class.forName(“com.mysql.jdbc.Driver”);conn=DriverManager.getConnection(“jdbc:mysql://localhost/uploader“,”根“,”;字符串sql=“从文件中选择”;pst=conn.prepareStatement(sql);rs=pst.executeQuery(sql);table_documentinfo.setModel(DbUtils.resultsetTableModel(rs))}catch(异常e){JOptionPane.showMessageDialog(null,e);}
 public void StoreFileName(String fileName){
    String sql = "INSERT INTO files VALUES ("+null+",'"+fileName+"')";
   // String sql = "insert into files(fileName) "+ "values(?)";
    System.out.println(sql);

    try {
        stmt.executeUpdate(sql);
    } catch (SQLException ex) {
        System.out.println("Exception: "+ex.getMessage() );
    }catch (Exception ex){
        System.out.println("Error");
    }
}