Insert Office Open XML file (OOXML) in MySQL as blob

I have many Office Open XML files (OOXML) saved with the XML extension, and I'm trying to insert these files into a MySQL database. I can connect normally, and I was able to insert rows into different databases with the same syntax. But when I try to insert the XML file into the blob field in the database, it tells me that I have a problem with my syntax. Is there anything special I have to do due to the file format?

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."); } } 

This is mistake:

"Exception in thread" main "
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: you have an error in the SQL syntax; check the manual corresponding to the MySQL server version for the correct syntax for use next to the '(1,2,3) value (_binary'PK \ 0 \ 0 \ 0 \ 0 \ 0! \ 0? RH? \ 0 \ 0? \ 0 \ 0 \ 0 [Content_Types]. On line 1 ".

On my console, a few of 0 go out as a question mark in the box instead.

+5
source share
1 answer

Well, I realized that it was a small syntax error. It:

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

Must be:

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

since I need to specify the name of the table and also specify the id field.

There is no problem with the ooxml data in the xml extension, as it turns out, since the resulting query can be opened in MS Word (for which I aimed / wanted)

+3
source

All Articles