Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Syntax error while inserting a file into Mysql database.

 
Vazzdoin Rocko
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to insert an .exe file into mysql blob field in the database. I;ve tried to both ways i.e LOAD_FILE method and FileInputStream method at the local and remote Database server,
but it is consistently giving an error.The stacktrace of the error is : :
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 'binary) values('abc','19541a2746e08a6b8f5145bdbaa23e45','http:jadhjkhdf/dasdas',' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2398)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2316)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2301)
at temp1.copyFile.main(copyFile.java:45)



The code i'm using is given below :


Please help me in resolving this issue. I guess my code is all correct and there is some ado with the Mysql version.
The current mysql version shown by my RHEL machin is :
mysql Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (i686) using readline 5.0
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no experience with MySQL, but according to its documentation binary is a reserved word.

You should escape the column name (probably enclosing it in back quotes), though changing the column name to something which is not a reserved word would be much better in the long run.
 
Vazzdoin Rocko
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr. Martin.
My problem has been resolved. i already knew that Binary is a keyword but never thought that it would affect column names too.. i thought it's scope is upto Table names only. Well , it's not a problme any more as i've renamed the column and my code is working fine now. Thank you very much for the guidance
 
Rob Spoor
Sheriff
Pie
Posts: 20744
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to cast fis to InputStream, it already is one - FileInputStream extends InputStream.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic