aspose file tools*
The moose likes JDBC and the fly likes Receiving error while inserting a row into a MYSQL table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Receiving error while inserting a row into a MYSQL table" Watch "Receiving error while inserting a row into a MYSQL table" New topic
Author

Receiving error while inserting a row into a MYSQL table

Charles Sexton
Ranch Hand

Joined: Sep 26, 2013
Posts: 79
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

Joined: Jul 28, 2010
Posts: 153

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

Joined: Sep 26, 2013
Posts: 79
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

Joined: Sep 26, 2013
Posts: 79
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
 
subject: Receiving error while inserting a row into a MYSQL table
 
Similar Threads
SQL formatting question
How to create schema in MyEclipse Derby
Hypersonic DB question
Using PreparedStatement
mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;