File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Receiving error while inserting a row into a MYSQL table

 
Charles Sexton
Ranch Hand
Posts: 238
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need some help with this error that I receive, I have tried several solutions but changing the syntax to fit a preparedStatement(), if a preparedStatement() is needed can someone tell me why I should use it over createStatement().


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'First' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1842)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1764)
at server_sexton_it351.Threads.run(Threads.java:220)
at server_sexton_it351.Server_Sexton_IT351.main(Server_Sexton_IT351.java:30)


This is how I create the customers table through a script.



This is how I write the query in java

 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like cache of .class file, See the error
Unknown column 'First' in 'field list'
, which means your JVM sending column as 'First', MYSQL is not able to identify this column name, Make sure you clean, recompile and run.
 
Charles Sexton
Ranch Hand
Posts: 238
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malatesh Karabisti wrote:Seems like cache of .class file, See the error
Unknown column 'First' in 'field list'
, which means your JVM sending column as 'First', MYSQL is not able to identify this column name, Make sure you clean, recompile and run.


To be honest I always right click project, then select clean and build, every time I update my application and need to run the application. This is in netbeans of course, I don't know about eclipse. A few months ago I learned the hard way to clean and recompile my project anytime I updated it, that is why I made it a habit to clean and build. I appreciate your post and wasn't able to fix the error using a create statement.

First was the data that I was using to add to the firstName column. If I insert goo as the data for the column firstName it would say "Unknown column 'goo' in 'field list'".


 
Charles Sexton
Ranch Hand
Posts: 238
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For future reference this is the solution that I developed after testing several things. I have learned that the prepared statement is better to use than the createStatement method.



 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic