文件无法从jTable打开

时间:2017-03-27 09:36:48

标签: java

我创建了一个简单的表单,其中包含一个JTable,我可以在其中 保存excel文件&每当选择行时打开excel文件。保存功能正常工作。但是,当我选择行时,excel文件不会打开。我使用以下代码:

public Log() {
    initComponents();
    conn=Javaconnect.ConnecrDb();
    Update_table();
}

private void Update_table(){
    try{
        String sql="select Code,Type,Date,Status,Path from Log";
        pst=conn.prepareStatement(sql);
        rs=pst.executeQuery();
        jTable1.setModel(DbUtils.resultSetToTableModel(rs));

    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }

}


private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    setVisible(false);
    Report ob=new Report();
    ob.setVisible(true);
}                                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    String sql="select * from Machine where Code=?";
    try{
        pst=conn.prepareStatement(sql);
        pst.setString(1, jTextField1.getText());
        rs=pst.executeQuery();
        if(rs.next()){
            String add1=rs.getString("Type");
            jTextField2.setText(add1);
            rs.close();
            pst.close();
        }
        else{
            JOptionPane.showMessageDialog(null, "Machine Not Found");
        }
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
}                                        

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    JFileChooser chooser=new JFileChooser();
    chooser.showOpenDialog(null);

    File f=chooser.getSelectedFile();
    String filepath=f.getAbsolutePath();
    jTextField3.setText(filepath);
}                                        

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    try{
        String sql ="Insert into Log (Code,Type,Date,Status,Path) values(?,?,?,?,?)";

        pst=conn.prepareStatement(sql);
        pst.setString(1, jTextField1.getText());
        pst.setString(2, jTextField2.getText());
        pst.setString(3,((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText());
        pst.setString(4, (String)jComboBox1.getSelectedItem());
        pst.setString(5, jTextField3.getText());            
        pst.execute();
        JOptionPane.showMessageDialog(null, "Saved");
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }

    jTextField1.setText("");
    jComboBox1.setSelectedItem("----------");
    jDateChooser1.setDateFormatString("");
    jTextField2.setText("");
    jTextField3.setText("");
    Update_table();
}                                        

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     
    // TODO add your handling code here:
    int row=jTable1.getSelectedRow();
    String value=(jTable1.getModel().getValueAt(row, 4).toString());
    try{
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler"+value);         
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
}                                    

我做错了什么?提前谢谢。

0 个答案:

没有答案