Solved

Getting error when writting to database

Posted on 2011-09-28
5
194 Views
Last Modified: 2012-05-12
val = mStmt.executeUpdate("INSERT INTO airport VALUES("+airport  +")");

gives me


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'Test' in 'field list'
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Sour
0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36715742
I'm not convinced that the error message pairs correctly with the code, but the code is probably wrong in itself.

It will only work if

a. the table in question has one column
b. that column is a numeric type
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36715770
You probab ly meant to have a query like tahat:

"insert into airports(airport_id) values (" + airprt +")"

Where those  columns which should be inseterd  are enumerated in parenthese after the table name
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36716937
One thing I do is copy the query string into a string variable.  Then I print that string.  If the error is not obvious at this point, I start the database's manual update program (say with mysql, I type mysql at a command prompt).  Then I copy/paste the printed query into a test database and see if I get an error.  (I always get an error but the error message has valuable information.)
0
 
LVL 4

Accepted Solution

by:
stachenov earned 500 total points
ID: 36717825
I think you're missing quotes around string literal in the query. This should work:
 
val = mStmt.executeUpdate("INSERT INTO airport VALUES('"+airport  +"')");

Open in new window

0
 

Author Closing Comment

by:Mickeys
ID: 36719011
Yes I was afraid it was something like that. I tried to put it out in a system.out but I couldnt even see it then.

Thx. It really helped.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question