0
我试图上传图片到我的DB2 database.i已复制库需要 db2jcc.jar
在web-inf/lib
上传图像与servlet
<form action="Upload" method="post" enctype="multipart/form-data">
ID : <input type="text" name="id"/><br>
FILE : <input type="file" name="photo"/><br>
<input type="submit" value="upload"/>
</form>
我上传的servlet
try {
String id=request.getParameter("id");
Part photo = request.getPart("photo");
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:db2:SAMPLEDB");
System.out.println("Connection Successful");
PreparedStatement ps=con.prepareStatement("INSERT INTO SAMPLETABLE (ID,PHOTO) VALUES (?,?)");
ps.setString(1, id);
File fBlob = new File (request.getParameter("photo")); //exception thrown here
FileInputStream is = new FileInputStream (fBlob);
ps.setBinaryStream (2, is, (int) fBlob.length());
ps.execute();
}
catch(Exception e)
{
System.out.println("exception --> "+e);
}
}
finally
{
out.close();
}
}
的我得到的例外是
java.lang.NullPointerException
没份重量DRE在roseindia.net ... BT它不是wrking ......可以ANY1 TL我d解决方案????????? – user1506349 2013-03-17 21:31:21