Solved

Getting error when writting to database

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Performance issue while iterating with streams 5 40
changePi Challenge 15 77
parentbit challenge 3 52
HashMap Vs TreeMap 12 49
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

11 Experts available now in Live!

Get 1:1 Help Now