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

前端之家收集整理的这篇文章主要介绍了将Office Open XML(OOXML)文件作为blob插入MySQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有很多使用扩展 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,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,?)";

需要是:

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

因为我需要说明表名,并给id字段一个值.

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

猜你在找的XML相关文章