Bintu Chaudhary
How to Open Picture From M.S. Access Database using Java Servlet ?
0 Answer(s)      4 years and 8 months ago
Posted in : JSP-Servlet

Hi all my Friends I have below code which insert a picture into M.S. Access Database But i m still not able to open this picture through Java using M.S. Access and i wants to open this Picture On Web Browser using Java Servlet anybody can help me....?

//Code for Insert Picture into M.S.Access using Java import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException;

public class InsertPicture { public static void main(String[] args) throws Exception, IOException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:MyDsn"; Connection conn=DriverManager.getConnection(url); String INSERT_PICTURE = "insert into Img(ID,Image) values (?, ?)";

            FileInputStream fis = null;
            PreparedStatement ps = null;
            try
            {
                    conn.setAutoCommit(false);
                    File file = new File("bintu.jpg");
                    fis = new FileInputStream(file);
                    ps = conn.prepareStatement(INSERT_PICTURE);
                    ps.setString(1, "001");
                    ps.setBinaryStream(2, fis, (int) file.length());
                    ps.executeUpdate();
                    conn.commit();
            }
            finally
            {
                    ps.close();
                    fis.close();
            }
    }

}

Advertisement
View Answers









Related Tutorials/Questions & Answers: