Skip to main content

Posts

Showing posts with the label image insertion

Image Insertion into MySQL database Using java JDBC

 Image Insertion into MySQL database Using java JDBC  For explanation watch video: Code:: import java.io.FileInputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.util.Scanner; public class Test { private static final String query = "INSERT INTO IMG_TAB(CNAME,IMAGE) VALUES(?,?)"; public static void main(String[] args)throws Exception{ Scanner scn = new Scanner(System.in); System.out.println("Enter Customer name::"); String cname = scn.next(); System.out.println("Enter the image location: "); String loc = scn.next().replace("?", ""); InputStream is = new FileInputStream(loc); Connection con = DriverManager.getConnection("jdbc:mysql:///new","root","root"); PreparedStatement ps = con.prepareStatement(query); ps.setString(1, cname); ps.setBinaryStream(2, is); int count = ps.exe