Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes SQLException:Invalid column name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException:Invalid column name" Watch "SQLException:Invalid column name" New topic
Author

SQLException:Invalid column name

Raghunath Madhvapathi
Greenhorn

Joined: Aug 26, 2004
Posts: 6
Hi Folks,

I am using SQL Server 2000 database and using a Java DAO class executing an SQL query using preparedStatement.The issue is that intermittently i get the following exception: "SQLException:Invalid column name". I checked the filed name in the table and the filed name i gave in the resultset.getInt("field_name")and both are matching.The parameter values for the query are fetched from a JSP report and the surprsing issue is that this exception comes on & off. So iam unable to find the cause of this exception.Can anyone help me out?
Thanks
Raghu
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
need your code snippet and table description.
Raghunath Madhvapathi
Greenhorn

Joined: Aug 26, 2004
Posts: 6
Thanks for your response.
The table from which we query is USERS table and the column name which is giving the sqlexcetion is user_id. user_id field is a int data type.We are using the SQL server database.

The query is something like this:

SELECT usrs.user_id,uperm.value,uedis.attrib_value.......

FROM USERS usrs
LEFT OUTER JOIN extended_user_attributes uedis
ON (usrs.user_id = uedis.user_id AND usdis.attrib_id=?),
user_permission uperm
WHERE usrs.user_id = uperm.user_id
AND uperm.name=? AND some other conditions ...

and the code snippet is as follows:
Load the driver
create the connection...
make the preparedStatement and setting the parameters
ResultSet rs = preparedStatement.executeQuery();

while(rs.next())

UserID userid = new UserID();
userid.setUserID(rs.getInt("user_id"));
.....

The exception i.e coming is

(java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: user_id)
Raghunath Madhvapathi
Greenhorn

Joined: Aug 26, 2004
Posts: 6
Hi ,
What i would like to add here is the issue doesnt seem to be with either the SQL query or the code because we get these exception only sometimes.Otherwise the code works fine. I want to know whether there is some issue with the SQL server JDBC driver or something else.

regards
Raghu
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
no this is something you wrote it here, not the actual code. please paste the actual code. otherwise it would be difficult to figure out the issue.

may be driver issue, not sure about that??
[ October 15, 2004: Message edited by: adeel ansari ]
 
wood burning stoves
 
subject: SQLException:Invalid column name
 
Similar Threads
Dynamic SQL in hibernate
Unable to index a column values using Solr Apache
Spring ORM HibernateTemplate Mapping Exception
Problem with preapred Statement
JPA - need help with query