File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLException:Invalid column name

 
Raghunath Madhvapathi
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need your code snippet and table description.
 
Raghunath Madhvapathi
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic