I am using the following code to insert an image into a database. It will save two images because I used PreparedStatement
and Statement
.
When I run this code, I get two images in the database. But both images are different, and I do not understand why. Using PreparedStatement
, it inserts perfectly. I want to have the same image when I use Statement
. Why is it not working now and how can I make it work?
import java.io.*; import java.sql.*; public class Image { public static void main(String args[]) throws Exception { System.out.println("kshitij"); Class.forName("com.mysql.jdbc.Driver"); Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jsfdb","root","kshitij"); Statement st=cn.createStatement(); File f1=new File("c:\\k1.jpg"); FileInputStream fin=new FileInputStream(f1);
MySQL
CREATE DATABASE IF NOT EXISTS jsfdb; USE jsfdb;
source share