commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keates, Mark" <Mark.Kea...@dendrite.com>
Subject RE: [DBCP] Oracle NlsDateFormat
Date Fri, 19 Dec 2003 10:40:45 GMT
Thanks for the replies, a 'hook' into the connect creation would be the
thing 
I'd prefer, could this be done through extending 'Connection' somehow?

@Chris - the servlet works equally well against a Sybase (Adaptive Anywhere)
DB
and so I wanted to avoid the to_date/to_char approach.

@Henri - sounds like a good idea, I didn't know the JDBC driver did that.

Here's a example code snippet:

	ResultSet grid_r;
	Date odbc_dt1, odbc_dt2;
	java.util.Date x = cal.getTime();
	odbc_dt1 = new Date(x.getTime());
	cal.add(cal.MONTH, 1);
	cal.add(cal.DAY_OF_MONTH, -1);
	java.util.Date y = cal.getTime();
	odbc_dt2 = new Date(y.getTime());
	cal.add(cal.DAY_OF_MONTH, 1);

	String grid_q = "select event_type, count(*) n ";
	grid_q += "from event ";
	grid_q += "where employee_id="+id;
	grid_q += " and start_date_time >= '" + odbc_dt1.toString() + "
00:00:00'";
	grid_q += " and start_date_time <= '" + odbc_dt2.toString() + "
00:00:00'";
	grid_q += " group by event_type";
	grid_q += " order by event_type desc";
	grid_r = grid_s.executeQuery(grid_q);

Regards,

Mark

PS: Where do you get to see the message id to use in the request:
	commons-user-get.123_145@jakarta.apache.org
e.g. this thread has the mail archive url of:
	
http://www.mail-archive.com/commons-user@jakarta.apache.org/msg05316.html
If I request message 5316 then I get back:
	Re: [HiveMind]  Problems with manifestclasspath task
	5316 by: Howard M. Lewis Ship

> -----Original Message-----
> From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
> Sent: 18 December 2003 21:27
> To: Jakarta Commons Users List
> Subject: Re: [DBCP] Oracle NlsDateFormat
> 
> 
> The best way is to use java.sql.Date variables of course.
> If your java program expects the same date format from/to all 
> databases then you can set your default NLS_DATE_FORMAT as an 
> environment variable on unix or in the windows registry.
> 
> This alter session statement cannot be passed to the DBCP connection 
> engine right now. But it is an interesting feature for a future 
> version if it is generic enough. (executing a statement on 
> creation/activation of a connection).
> 
> -- Dirk
> 
> 
> Keates, Mark wrote:
> 
> > Hi,
> > 
> > When using a servlet engine to connect to different Oracle 
> databases,
> > which can have differing default date formats, is it the 
> responsibility of
> > the
> > servlet to execute an ALTER SESSION if I want to use a specific
> > date format in my queries? E.g.
> > 
> > 	Connection con = ds.getConnection();
> > 	Statement s = con.createStatement();
> > 	s.execute("alter session set NLS_DATE_FORMAT = 'YYYY-MM-DD
> > HH24:MI:SS'");
> > 	...
> > 	s.close();
> > 	con.close();
> > 
> > Or can this be passed to the DBCP connection engine somehow so that 
> > when a new connection is established the correct date 
> format is set? This 
> > problem has come about since the introduction of
> > 'timeBetweenEvictionRunsMillis'
> > into the DB ResourceParams section within server.xml.
> > 
> > I'd rather this was done than have to intersperce 'to_date' 
> calls everywhere
> > ;(
> > 
> > Thanks,
> > 
> > Mark
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: 
> commons-user-help@jakarta.apache.org
> > 
> > 
> > 
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message