Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with max function (very urgent)

 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Sysbase is the backend used to execute this query
"SELECT col_name FROM table_name" where col_name is a datetime field . It is giving a ResultSet as expected.
Where as if i change the query to
"SELECT max(col_name) FROM table_name" an exception is thrown
"java.sql.SQLException: S0022: Invalid column name col_name"
Please let me know, where the problem is in my query.
Thanks in advance.
Regards
arun
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u paste the code here.
That may help me to analyze the problem better.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep Bhat
Thank you Bhat,
Here is the code for the above said problem
after getting a connection to database assume that "con" represents Connection object.
then
Statement st= con.createStatement();
ResultSet rs=st.executeQuery(strQuery);
where strQuery is a String for strQuery="select col_name from table_name"
will get the result set
but when strQuery="select max(col_name) from table_name"
then above mentioned Exception is thrown.
Regards
arun
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess that the error is occurring when you are trying to read the column from the resultset. If you use
rs.getTimestamp("col_name")
on the resultset using the max function, it will give you that exception. The actual column name you should use is
rs.getTimestamp("max(col_name)") or
rs.getTimestamp(1);
or change your query to use a column alias - "SELECT max(col_name) as col_name FROM table_name" then you can use rs.getTimestamp("col_name")
Hope this helps,
Jamie
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
This is a update for the forum member. As per Robertson suggestion i changed my query and it worked.
Thank you Robertson and Bhat for the help.
Regards
arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic