I have a program in which the client uploads a file and the file is stored in a database. Prior to Java updating on my computer, my project was working fine. Now I am getting a FileNotFoundException
. Eclipse is telling me:
The JAR file C:\Program Files\Java\jre7\lib\rt.jar has no source attachment.
Anybody come across this problem?
My servlet code for uploading the file is standard:
if (!ServletFileUpload.isMultipartContent(request))
{return;}
try
{
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
courseID = items.get(0).getString();
homeworkID = items.get(1).getString();
File storeFile = new File(items.get(2).getName());
String fileName = storeFile.getName();
String mimeType = new MimetypesFileTypeMap().getContentType(storeFile); //for putting file into database
putFileIntoDB(uName, courseID, homeworkID, fileName, mimeType, storeFile);
}//try
catch (Exception ex)
{
request.setAttribute("msg", "There was an error: " + ex.getMessage());
request.getRequestDispatcher("/upload.jsp").forward(request, response);
}
There error is found in the putFileIntoDB method when the FileInputStream is created in the line fis=new FileInputStream(f):
void putFileIntoDB(String username, String courseID, String homeworkID, String fileName, String mime, File f) throws SQLException, IOException
{
FileInputStream fis = null;
java.sql.PreparedStatement pstmt = null;
java.sql.Connection conn = null;
try {
conn = ConnectionManager.getConnection();
conn.setAutoCommit(true);
fis = new FileInputStream(f);
pstmt = conn.prepareStatement("insert into files(username, courseID, assignmentID, fileName, mimeType, contents) values (?, ?, ?, ?, ?, ?)");
pstmt.setString(1, username);
pstmt.setString(2, courseID);
pstmt.setString(3, homeworkID);
pstmt.setString(4, fileName);
pstmt.setString(5, mime);
pstmt.setAsciiStream(6, fis, (int) f.length());
pstmt.executeUpdate();
conn.commit();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
finally
{
pstmt.close();
fis.close();
conn.close();
}
}
Anybody else come across this problem?