简体中文
会员名称: 登入密码: [Register] 注册 忘记密码 启用我的帐号
 
各位大侠,我出现了java.lang.reflect.InvocationTargetException这个错误,是怎么回事呢。代码内详  XML
论坛首页 »开源项目» JForum论坛
发表人 内容
moneymore


注册时间: 2007-11-04 22:28:04
文章: 2
离线

我想给论坛加一个在论坛列表添加图片的功能,所以在jforum_forums表中增加了forum_pic字段
现在图片可以以附件上传到制定文件了,但是,执行sql的时候却出错了:

/* 向jforum_jforum表中插入图片字段数据 */
String sql = new StringBuffer().append("update jforum_forums set forum_pic_address=? where forum_id=?")
.toString();
PreparedStatement pstmt = JForumExecutionContext.getConnection().prepareStatement(sql);
pstmt.setString(1, forumPicFinalFileName);
pstmt.setLong(2, forumId);
pstmt.executeUpdate();
}


详细代码如下~希望各位大侠帮忙!

// A new one
public void insertSave() throws SQLException {
Forum f = new Forum();
f.setDescription(this.request.getParameter("description"));
f.setIdCategories(this.request.getIntParameter("categories_id"));
f.setName(this.request.getParameter("forum_name"));
f.setModerated("1".equals(this.request.getParameter("moderate")));
int forumId = DataAccessDriver.getInstance().newForumDAO().addNew(f);
f.setId(forumId);
/* 增加版面显示的图片 */
if (request.getObjectParameter("forumPic") != null) {
String fileName = String.valueOf(forumId) + "forumPic";
FileItem item = (FileItem) JForumExecutionContext.getRequest().getObjectParameter("forumPic");//从file空间获得fileItem
UploadUtils uploadUtils = new UploadUtils(item);
// Gets file extension
String extension = uploadUtils.getExtension().toLowerCase();
int type = ImageUtils.IMAGE_UNKNOWN;
if (extension.equals("jpg") || extension.equals("jpeg")) {
type = ImageUtils.IMAGE_JPEG;
} else if (extension.equals("gif") || extension.equals("png")) {
type = ImageUtils.IMAGE_PNG;
}
if (type != ImageUtils.IMAGE_UNKNOWN) {
String forumPicTmpFileName = SystemGlobals.getApplicationPath() + "images" + File.separator
+ "forumPic" + File.separator + fileName + "_tmp." + extension;
// We cannot handle gifs
if (extension.toLowerCase().equals("gif")) {
extension = "png";
}
String forumPicFinalFileName = SystemGlobals.getApplicationPath() + "images" + File.separator
+ "forumPic" + File.separator + fileName + "." + extension;
uploadUtils.saveUploadedFile(forumPicTmpFileName);
// OK, time to check and process the avatar size
int maxWidth = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_WIDTH);
int maxHeight = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_HEIGHT);
BufferedImage image = ImageUtils.resizeImage(forumPicTmpFileName, type, maxWidth, maxHeight);
ImageUtils.saveImage(image, forumPicFinalFileName, type);
f.setForumPic(forumPicFinalFileName);//将文件路径放入forum的dt
// Delete the temporary file
new File(forumPicTmpFileName).delete();
/* 向jforum_jforum表中插入图片字段数据 */
String sql = new StringBuffer().append("update jforum_forums set forum_pic_address=? where forum_id=?")
.toString();
PreparedStatement pstmt = JForumExecutionContext.getConnection().prepareStatement(sql);
pstmt.setString(1, forumPicFinalFileName);
pstmt.setLong(2, forumId);
pstmt.executeUpdate();
}
}
ForumRepository.addForum(f);
GroupSecurityDAO gmodel = DataAccessDriver.getInstance().newGroupSecurityDAO();
PermissionControl pc = new PermissionControl();
pc.setSecurityModel(gmodel);
String[] allGroups = this.request.getParameterValues("groups");
// Access
String[] groups = this.request.getParameterValues("groupsAccess");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_FORUM, f.getId(), groups);
} else {
this.addRole(pc, SecurityConstants.PERM_FORUM, f.getId(), allGroups);
}
// Anonymous posts
groups = this.request.getParameterValues("groupsAnonymous");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_ANONYMOUS_POST, f.getId(), groups);
} else {
this.addRole(pc, SecurityConstants.PERM_ANONYMOUS_POST, f.getId(), allGroups);
}
// Read-only
groups = this.request.getParameterValues("groupsReadOnly");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_READ_ONLY_FORUMS, f.getId(), groups);
} else {
this.addRole(pc, SecurityConstants.PERM_READ_ONLY_FORUMS, f.getId(), allGroups);
}
// Reply-only
this.addRole(pc, SecurityConstants.PERM_REPLY_ONLY, f.getId(), allGroups);
// HTML
groups = this.request.getParameterValues("groupsHtml");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_HTML_DISABLED, f.getId(), groups);
} else {
this.addRole(pc, SecurityConstants.PERM_HTML_DISABLED, f.getId(), allGroups);
}
SecurityRepository.clean();
RolesRepository.clear();
//this.handleMailIntegration();
this.list();
}
private void addRole(PermissionControl pc, String roleName, int forumId, String[] groups) {
Role role = new Role();
role.setName(roleName);
for (int i = 0; i < groups.length; i++) {
int groupId = Integer.parseInt(groups[i]);
RoleValueCollection roleValues = new RoleValueCollection();
RoleValue rv = new RoleValue();
rv.setValue(Integer.toString(forumId));
roleValues.add(rv);
pc.addRoleValue(groupId, role, roleValues);
}
}

pinke

[Avatar]

注册时间: 2006-11-18 22:27:35
文章: 919
离线
性别: 男
出生:1982-06-18

你把你的代码 exception cache下来,再printStackTrace 出错的内容发上来看看

享我所想,乐你所乐
[MSN] Tencent QQ:44020567
 
论坛首页 »开源项目» JForum论坛
前往:   
Powered by JForum 2.1.8 © JForum Team Template: Trydone