当前位置: 技术问答>java相关
向数据库写blob类型的数据,出现找不到文件的错误
来源: 互联网 发布时间:2015-08-29
本文导语: String fileToReadBlob = "d:left_zh.gif"; File f = new File(fileToReadBlob); int lengthofFile = (int) f.length(); FileInputStream fileInputStream = new FileInputStream(f); PreparedStatement pstmt=conn.prepareStatement(sql); pstmt.setInt(1,3); pstmt.setBinaryStream(2, f...
String fileToReadBlob = "d:left_zh.gif";
File f = new File(fileToReadBlob);
int lengthofFile = (int) f.length();
FileInputStream fileInputStream = new FileInputStream(f);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,3);
pstmt.setBinaryStream(2, fileInputStream, lengthofFile);
pstmt.executeUpdate();
出现这样的错误:
[10/Sep/2002:11:41:09] failure (16112): Internal error: exception thrown from the servlet service function (uri=/jsp/student/forum/testClob.jsp): java.io.FileNotFoundException: d:/left_zh.gif (No such file or directory), Stack: java.io.FileNotFoundException: d:/left_zh.gif (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java, Compiled Code)
at java.io.FileInputStream.(FileInputStream.java, Compiled Code)
at _jsps._jsp._student._forum._testClob_jsp._jspService(_testClob_jsp.java, Compiled Code)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java, Compiled Code)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java, Compiled Code)
File f = new File(fileToReadBlob);
int lengthofFile = (int) f.length();
FileInputStream fileInputStream = new FileInputStream(f);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,3);
pstmt.setBinaryStream(2, fileInputStream, lengthofFile);
pstmt.executeUpdate();
出现这样的错误:
[10/Sep/2002:11:41:09] failure (16112): Internal error: exception thrown from the servlet service function (uri=/jsp/student/forum/testClob.jsp): java.io.FileNotFoundException: d:/left_zh.gif (No such file or directory), Stack: java.io.FileNotFoundException: d:/left_zh.gif (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java, Compiled Code)
at java.io.FileInputStream.(FileInputStream.java, Compiled Code)
at _jsps._jsp._student._forum._testClob_jsp._jspService(_testClob_jsp.java, Compiled Code)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java, Compiled Code)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java, Compiled Code)
|
try:
String fileToReadBlob = "d:\left_zh.gif";
java.io.File f = new java.io.File(fileToReadBlob);
if (f.exists()){
int lengthofFile = (int) f.length();
FileInputStream fileInputStream = new FileInputStream(f);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,3);
pstmt.setBinaryStream(2, fileInputStream, lengthofFile);
pstmt.executeUpdate();
}else{
out.println(fileToReadBlob+" is not exists!") ;
}
String fileToReadBlob = "d:\left_zh.gif";
java.io.File f = new java.io.File(fileToReadBlob);
if (f.exists()){
int lengthofFile = (int) f.length();
FileInputStream fileInputStream = new FileInputStream(f);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,3);
pstmt.setBinaryStream(2, fileInputStream, lengthofFile);
pstmt.executeUpdate();
}else{
out.println(fileToReadBlob+" is not exists!") ;
}