Solved

Getting error when writting to database

Posted on 2011-09-28
5
191 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
Java string replace 11 43
JavaFX TableView not displaying correctly 3 16
CSV file parsing thru Java 13 26
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now