Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Receiving error while inserting a row into a MYSQL table

 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 153
Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 273
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic