This is my sample design
I have successfully stored a microsoft word document in my sql database (using longblob) using this code below:
Attach button code:
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);
}
Save button code:
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);
}
Now my problem is I don't know how to open that particular microsoft word document from my sql database by just double clicking the selected column on my jTable.