TYPE | Size (Approx.) |
---|---|
Tinyblob | 255 Bytes |
Blob | 65 KB |
Mediumblob | 16 MB |
Longblob | 4 GB |
import java.io.*; import java.sql.*; public class WriteImage { public static void main(String[] args) { Connection con = null; PreparedStatement pst = null; FileInputStream fin = null; String cs = "jdbc:mysql://localhost:3306/college"; String user = "root"; String password = "urMySqlPassword"; try { File img = new File("urPicName.jpg"); fin = new FileInputStream(img); con = DriverManager.getConnection(cs, user, password); pst = con.prepareStatement("INSERT INTO PICS VALUES(?)"); pst.setBinaryStream(1, fin, (int) img.length()); pst.executeUpdate(); pst.close(); fin.close(); con.close(); System.out.println("Pic Stored in Database Table..."); } catch (Exception ex) { ex.printStackTrace(); } } }