Mybatis插入失败,没有例外

时间:2012-02-04 20:21:03

标签: java mysql file struts2 mybatis

我正在尝试将java应用程序中的文件插入到mysql表中。

对映射器的调用完成没有任何异常,但最后我在表中找不到任何记录。

我将文件内容映射到blob字段的方式可能有问题吗?

这是豆子:

public class CustomFile {
private int id;
private String title;
private String fileName;
private String fileType;
private String fileSize;
private byte[] fileContent;
private String fileExtension;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getFileName() {
    return fileName;
}

public void setFileName(String fileName) {
    this.fileName = fileName;
}

public String getFileType() {
    return fileType;
}

public void setFileType(String fileType) {
    this.fileType = fileType;
}

public String getFileSize() {
    return fileSize;
}

public void setFileSize(String fileSize) {
    this.fileSize = fileSize;
}

public byte[] getFileContent() {
    return fileContent;
}

public void setFileContent(byte[] fileContent) {
    this.fileContent = fileContent;
}

public String getFileExtension() {
    return fileExtension;
}

public void setFileExtension(String fileExtension) {
    this.fileExtension = fileExtension;
}

 }

这是映射:

<insert id="saveFile" parameterType="CustomFile">

    INSERT INTO file SET
    Title = #{title},
    File_Name = #{fileName},
    File_Type = #{fileType},
    File_Size = #{fileSize},
    File_Content = #{fileContent,jdbcType=BLOB},
    File_Extension = #{fileExtension}

</insert>

这是log4j日志:

2012-02-04 20:14:20,656 DEBUG java.sql.Connection.debug:27 - ooo Connection Opened
2012-02-04 20:14:22,128 DEBUG java.sql.PreparedStatement.debug:27 - ==>  Executing: INSERT INTO file SET Title = ?, File_Name = ?, File_Type = ?, File_Size = ?, File_Content = ?, File_Extension = ? 
2012-02-04 20:14:22,135 DEBUG java.sql.PreparedStatement.debug:27 - ==> Parameters: Test(String), 294435318.jpg(String), image/jpeg(String), 10028(String), java.io.ByteArrayInputStream@13105f32(ByteArrayInputStream), image/jpeg(String)
2012-02-04 20:14:30,113 DEBUG java.sql.Connection.debug:27 - xxx Connection Closed

谢谢!

1 个答案:

答案 0 :(得分:6)

也许你没有commit你的插页?我们可以看到您创建SqlSession的代码吗?