1

I am going to handle multiple time zone in my web application by resetting database session time zone every time getting DB connection.

The code looks like:

public Connection getConnection(GmDNSNamesEnum enDNSName) throws AppError
    {
         ...   
         DataSource ds = (DataSource) ic.lookup(enDNSName.getDNSName());
            conn = ds.getConnection();
            conn.setAutoCommit(false);
            setTimeZone(strTimeZone);
        ...
        return conn;
    }




private void setTimeZone(String strTimeZone){
     Statement stmt = null;
     if(conn != null) {
     try{
     stmt = conn.createStatement();
         stmt.execute("alter session set time_zone=\'" + strTimeZone+"\'");
     } catch (Exception e)
         {
         String strErrorMsg = GmCommonClass.getExceptionStackTrace(e);
             log.error("Exception e "+strErrorMsg);
         throw new AppError(e);
         }
     }
    }

Is there any alternate way to set database session time zone?

now, I am looking for configure datasource with different timezone in jboss/weblogic server and use appropriate datasource specific to user timezone instead of every time reset the session time zone by executing alter session script.

thanks in advance

Community
  • 1
  • 1
Gopi
  • 111
  • 1
  • 1
  • 6

1 Answers1

0

Wow ok.

Perhaps you could try persisting the dates and times into timezone-aware database columns instead of contorting the data source each time you connect? The convention is to store dates in UTC time, then do timezone conversion in the presentation layer (or at least post-retrieval).

Trent Bartlem
  • 2,213
  • 1
  • 13
  • 22
  • If Date column defined as TIMESTAMP WITH LOCAL TIME ZONE then Oracle will take care of conversion of date into current user session time zone,Manual conversion is not needed. So that I try to set user session time zone into database connection every time. – Gopi Nov 25 '15 at 05:29