I have a Mysql database which contain path of images stored in my local drive. I need to write a Java program which reads those images one-by-one.
I wrote the following code:
import java.sql.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ReadMultipleImages
{
public static void main(String[] args)
{
try
{
String myDriver = "com.mysql.cj.jdbc.Driver";
String myUrl = "jdbc:mysql://localhost/db?useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "user", "password");
String query = "SELECT * FROM test";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
String img = rs.getString("img");
BufferedImage in = ImageIO.read(new File(img));
System.out.println("Width of Image : " + in.getWidth());
}
st.close();
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
It doesn't workout with multiple image paths. However, when I passed the direct single image path:
BufferedImage in = ImageIO.read(new File('/tmp/frame_004.jpej'));
It gives me exact results that I want. My finding are it work only with single image path not more than that. How can I work on multiple images returned by the variable img ?