image error in jsf: The system cannot find the file specified

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bernouli
    New Member
    • Oct 2012
    • 26

    #1

    image error in jsf: The system cannot find the file specified

    i tried to upload image but it prints error

    Photo0017.jpg (The system cannot find the file specified)


    Code:
    import org.apache.myfaces.custom.fileupload.UploadedFile;
    
    
    public class UploadBean {
    private UploadedFile uploadedFile;
    public UploadedFile getUploadedFile() {
    return uploadedFile;
    }
    public void setUploadedFile(UploadedFile uploadedFile) {
    this.uploadedFile = uploadedFile;
    }
    public String getFileName() {
    return fileName;
    }
    public void setFileName(String fileName) {
    this.fileName = fileName;
    }
    public Blob getDbImage() {
    return dbImage;
    }
    public void setDbImage(Blob dbImage) {
    this.dbImage = dbImage;
    }
    private String fileName;
    private Blob dbImage;
    
    public String upload()
    {
    
    int k = 0;
    
    PreparedStatement ps = null;
    Connection con = null;
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tet", "root", "");
    File imgfile = new File(uploadedFile.getName());
    
    
    //System.out.println(“Name: ” + imgfile.getName());
    FileInputStream fin = new FileInputStream(imgfile);
    
    String sql = "INSERT INTO upload_image (IMAGE,Image_name,image_length) VALUES(?,?,?)";
    ps= con.prepareStatement(sql);
    ps.setBinaryStream(1,fin,(int)imgfile.length());
    ps.setString(2, imgfile.getName());
    ps.setLong(3, uploadedFile.getSize());
    
    
    
    
    
    k = ps.executeUpdate();
    Code:
    <h:form id="welcomeForm" enctype="multipart/form-data">
        <h:outputText value="Here is a File upload example."/>
    
    <t:inputFileUpload value="#{UploadBean.uploadedFile}" size="20" />
    <h:commandButton value="Load the file" action="#{UploadBean.upload}" />
        
    
        
      </h:form>
Working...