Solved

Getting error when writting to database

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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 …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

680 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