2011-03-17 40 views
-1

我已经编写了jsp,servlet的代码,用于在数据库中上传Doc文件。插入恢复(恢复)值(?)(文件名,目录名称或卷标语法不正确)。这里是我的代码,但我得到这样的错误== java.io.FileNotFoundException:插入恢复(继续)值(?)(文件名,目录名称或卷标语法不正确)。请帮助我如何删除此错误?java.io.FileNotFoundException?

  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(); 
     } 
+0

[Servlet将文本或文档文件发送到SQL Server 2008]的可能的重复(http://stackoverflow.com/questions/5336295/servlet-for-sending-the-text-or-document-file-到了-SQL服务器2008年) – BalusC 2011-03-17 13:12:47

回答

0

这是因为insert into resume(resume) values(?)可能不是磁盘上文件的名称。

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

您正在创建从一个""+ pstFile,这是被称为一个PreparedStatementtoString()结果。你有没有把""摆脱信息编译错误?

你可能在其他变量中有真实文件名。

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

请确保 “PST” 的值是一个有效的文件路径,显然值 “INSERT INTO简历(简历)值(?)” 不是一个有效的文件路径

0

java.io.File类有四个(4)构造

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

在你的情况,你试图传递给构造一个对象或键入java.sql.PreparedStatement你TR ying投入字符串。我没有看到(即使你将pst转换成字符串),pst会引用一个文件的路径。请返回阅读关于java.io的一些信息。