Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting error when writting to database

Posted on 2011-09-28
5
Medium Priority
?
199 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

618 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