Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

problem with max function (very urgent)

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic