gpt4 book ai didi

mysql - 将 Office Open XML (OOXML) 文件作为 blob 插入 MySQL

转载 作者:可可西里 更新时间:2023-11-01 07:07:00 24 4
gpt4 key购买 nike

我保存了很多扩展名为 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: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1,2,3) values(_binary'PK\0\0\0\0\0!\0?RH?\0\0?\0\0\0[Content_Types].' at line 1".

在我的控制台上,一些 0 在方框中显示为问号。

最佳答案

好的,我发现这只是一个小的语法错误。这个:

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

需要:

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

因为我需要声明表名以及给 id 字段一个值。

事实证明,xml 扩展中的 ooxml 数据没有问题,因为结果查询可以在 MS Word 中打开(这是我的目标/想要的)

关于mysql - 将 Office Open XML (OOXML) 文件作为 blob 插入 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com