开发者

java.io.FileNotFoundException?

开发者 https://www.devze.com 2023-02-17 14:34 出处:网络
i have written the code of jsp,servlet for uploading the Doc file in database. here is my code,but i am getting the error like this==java.io.FileNotFoundException: insert into resume(resume) values(?

i have written the code of jsp,servlet for uploading the Doc file in database.

here is my code,but i am getting the error like this==java.io.FileNotFoundException: insert into resume(resume) values(?) (The filename, directory name, or volume label syntax is incorrect) .please help me how to remove this error???

           try
    {   

    Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        con=DriverManager.getConnection("jdbc:jtds:sqlserver://W2K8SERVER:1433/career","sa","Alpha#123" );

        pst = con.prepareStatement("select * from data1 where email=? and password=?");   


        pst = con.prepareStatement
        ("insert into resume(resume) "+ "values(?)");

        File re = new File("" + pst);
        fis = new FileInputStream(re);
        pst.setBinaryStream(3, (InputStream)fis, (int)(re.length()));
        pst.setString (1,upload);


        //rs = pst.executeQuery();


        while (rs.next())
            cnt ++;

        int s = pst.executeUpdate();
        if(s>0) {
          System.out.println("Uploaded successfully !");
         }
        else {
        System.out.println("unsucessfull to upload image.");
          }
                开发者_开发百科    rs.close();
        pst.close();   
        con.close();
        }   


It is because insert into resume(resume) values(?) is probably not the name of a file on your disk.

  pst = con.prepareStatement ("insert into resume(resume) "+ "values(?)");
  File re = new File("" + pst);

You are creating a File from ""+ pst, which is the result of toString() being called on a PreparedStatement. Did you put in the "" to get rid of the informative compilation error?

You probably have the real filename in some other variable.

 File re = new File(theRealFileNameVariable);


File re = new File("" + pst);

please make sure the "pst" value is a valid file path, apparently the value "insert into resume(resume) values(?)" is not a valid file path


The java.io.File class has four (4) constructors

File(File parent, String child)
File(String pathname)
File(String parent, String child)
File(URI uri)

In your case you are trying to pass to the constructor an object or type java.sql.PreparedStatement that you trying to cast into a String. I don't see how (even if you arrived to convert pst into a string) pst will reference a path to a file. Please go back and read a little bit about java.io.

.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号