这是我的样本设计
我已使用以下代码在我的sql数据库中成功存储了一个Microsoft Word文档(使用longblob):
附加按钮代码:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String filename = f.getAbsolutePath();
txt_path.setText(filename);
try {
File doc = new File(filename);
FileInputStream fis = new FileInputStream(doc);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum);
}
documents = bos.toByteArray();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
保存按钮代码:
try {
String sql = "insert into sample (comments, document) values (?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, txt_comments.getText());
pst.setBytes(2, documents);
pst.execute();
updateTable();
txt_comments.setText("");
txt_path.setText("");
JOptionPane.showMessageDialog(null, "Success");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
现在我的问题是我不知道如何通过双击我的jTable上的选定列从我的sql数据库中打开特定的Microsoft Word文档。