I have inserted one image file in a table using a java program.I have written the program here. But when i do a select operation on the row i inserted it is displaying non-human readable contents. Instead i want some useful information(file name for example) to be displayed. I am using MySQL by the way. Any help much appreciated.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.FileInputStream;
public class BlobInsertClass {
static Connection con;
static PreparedStatement pst;
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
con = new ConnectionClass().getConnection();
File file = new File(
"/home/parasuraman/Pictures/lotr-eye-of-sauron-1.png");
InputStream is = new FileInputStream(file);
pst = con.prepareStatement("insert into Image values(?,?)");
pst.setInt(1, 1);
pst.setBinaryStream(2, is, 15000);
pst.executeUpdate();
pst.close();
con.close();
} catch (ClassNotFoundException cne) {
System.out.println("CNE " + cne);
} catch (SQLException se) {
System.out.println("SQl " + se);
} catch (FileNotFoundException fe) {
System.out.println("FE " + fe);
}
}
}