OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Re: Question for JDBC and Mysql

Alec.CawleyQuantel.Com
Date: Wed Nov 02 2005 - 03:23:24 CST


"Xiaobo Chen" <xiaobocs.dal.ca> wrote on 01/11/2005 20:28:38:

> Hi, all
>
> I have a question like this:
>
> There's a field in table_A, date_time, if I say this in Mysql:
>
> select min(date_time), max(date_time) from table_A;
>
> it returned something like this:
>
> +---------------------+---------------------+
> | min(date_time) | max(date_time) |
> +---------------------+---------------------+
> | 2003-05-06 11:59:00 | 2003-05-23 11:59:00 |
> +---------------------+---------------------+
>
> My question is that if I used JDBC like this:
>
> String sqlcmd = "select min(date_time), max(date_time) from table_A;
> Statement Stmt = conn.createStatement();
> ResultSet RS = Stmt.executeQuery(sqlcmd);
>
> How should I get the values, like this?
>
> start_time=RS.getString(1);
> end_time=RS.getString(2);
>
> or
>
> start_time=RS.getString(min(date_time));
> end_time=RS.getString(max(date_time));

You could do
String start_time = RS.getString (1) ;

but you would be much better advised, in my opinion, to do
java.sql.Date start_time = RS.getDate (1) ;
which then allows you to use all the Java library's excellent date
handling features.

        Alec

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql