将Office Open XML (OOXML) 文件作为blob插入到MySQL中

5

我有很多扩展名为XML的Office Open XML (OOXML)文件,并尝试将这些文件插入到MySQL数据库中。我可以正常连接,并且已经能够使用相同语法将字符串插入到不同的数据库中。但是,当我尝试将XML文件插入到数据库中的blob字段时,它告诉我语法有问题。因为这些文件的格式,我需要做些特殊的处理吗?

public Insertion(Connection conn) throws SQLException, FileNotFoundException{

    System.out.println("Trying to insert Data..");

    String filePath1 = "C:/Users/SAVAGD05/Documents/RMP/Section1.XML";
    InputStream inputStream1 = new FileInputStream(new File(filePath1));
    String filePath2 = "C:/Users/SAVAGD05/Documents/RMP/Section1.XML";
    InputStream inputStream2 = new FileInputStream(new File(filePath2));
    String filePath3 = "C:/Users/SAVAGD05/Documents/RMP/Section1.XML";
    InputStream inputStream3 = new FileInputStream(new File(filePath3));

    System.out.println("It did this part");

    String SQL = "INSERT INTO (1,2,3) values(?,?,?)";
    PreparedStatement statement = conn.prepareStatement(SQL);


    statement.setBlob(1, inputStream1);
    statement.setBlob(2, inputStream2);
    statement.setBlob(3, inputStream3);
    statement.executeUpdate();


    System.out.println("Data inserted.");
    conn.close();
    System.out.println("Connection Closed");
    System.out.println("Have a Nice Day and Goodbye.");
    }


}

这是错误信息:
“Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 您在SQL语法中有一个错误,请检查与您的MySQL服务器版本相对应的手册以了解正确的语法,位于第1行附近使用'(1,2,3)values(_binary'PK\0\0\0\0\0!\0?RH?\0\0?\0\0\0[Content_Types].'。"
在我的控制台上,一些0会被替换为一个带有问号的方框。

1
你的表长什么样子,你的目标是什么?你真的想把三个 blob 保存到一个记录中,还是想将每个 blob 保存到自己的记录中?在每种情况下,你的查询都缺少一个表名:INSERT INTO table_name (col_name1, col_name2) VALUES (...), (...); - rostbot
我的表格有列名为"Section1"、"Section2"和"Section3"。我刚刚更新了语法为:String SQL = "INSERT INTO (Section1, Section2, Section3) values(?,?,?)"; 但是这对于错误没有任何改变。 - Daniel Savage
2
你仍然没有指定表名:String SQL = "INSERT INTO your_table_name_here (Section1, Section2, Section3) values(?,?,?)"; - rostbot
我刚刚完成了。不过还是谢谢你的帮助。 - Daniel Savage
1个回答

3
好的,我意识到这只是一个小的语法错误。 这个:

String SQL = "INSERT INTO (1,2,3) values(?,?,?)";

需要的是:

 String SQL = "INSERT INTO sections(idSections,Section1,Section2,Section3) values(?,?,?,?)";

由于我需要指定表名并给id字段赋值,因此出现了这个问题。

原来在xml扩展中的ooxml数据没有问题,因为生成的查询可以在MS Word中打开(这正是我想要的)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接