GVKun编程网logo

JDK6中的TimeZone.setDefault更改(jdk设置时区)

7

本文将分享JDK6中的TimeZone.setDefault更改的详细内容,并且还将对jdk设置时区进行详尽解释,此外,我们还将为大家带来关于0078Java与MySQL时间戳传递/存储/协调问题--

本文将分享JDK6中的TimeZone.setDefault更改的详细内容,并且还将对jdk设置时区进行详尽解释,此外,我们还将为大家带来关于0078 Java与MySQL时间戳传递/存储/协调问题--userLegacyDatetimeCode--userTimezone--serverTimezone、asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么、asp.net – 更改MVC帐户数据库中的DefaultConnection、C#中的TimeZone?的相关知识,希望对你有所帮助。

本文目录一览:

JDK6中的TimeZone.setDefault更改(jdk设置时区)

JDK6中的TimeZone.setDefault更改(jdk设置时区)

我只是注意到,与JDK5相比,JDK 6设置默认TimeZone的方法有所不同。

以前,新的默认值将存储在线程局部变量中。使用JDK6(我刚刚查看过1.6.0.18),实现已更改,因此,如果用户可以写入“
user.timezone”属性,或者如果未安装SecurityManager,则时区将在VM范围内更改!否则,将发生线程局部更改。

我错了吗?这似乎是一个巨大的变化,我在网上找不到任何有关它的信息。

这是JDK6代码:

 private static boolean hasPermission() {  boolean hasPermission = true;  SecurityManager sm = System.getSecurityManager();  if (sm != null) {   try {    sm.checkPermission(new PropertyPermission("user.timezone", "write"));   } catch (SecurityException e) {    hasPermission = false;   }  }  return hasPermission; } /**  * Sets the <code>TimeZone</code> that is  * returned by the <code>getDefault</code> method.  If <code>zone</code>  * is null, reset the default to the value it had originally when the  * VM first started.  * @param zone the new default time zone  * @see #getDefault  */ public static void setDefault(TimeZone zone) {  if (hasPermission()) {   synchronized (TimeZone.class) {    defaultTimeZone = zone;    defaultZoneTL.set(null);   }  } else {   defaultZoneTL.set(zone);  } }

而之前(在JDK5中)只是:

 /**  * Sets the <code>TimeZone</code> that is  * returned by the <code>getDefault</code> method.  If <code>zone</code>  * is null, reset the default to the value it had originally when the  * VM first started.  * @param zone the new default time zone  * @see #getDefault  */ public static synchronized void setDefault(TimeZone zone) {  defaultZoneTL.set(zone); }

答案1

小编典典

搜索错误数据库实际上是一个好主意:)

http://bugs.sun.com/view_bug.do?bug_id=6352812

并且(文档):

http://bugs.sun.com/view_bug.do?bug_id=6181786

简介:JDK 1.5是该规则的一个例外,对于JDK 1.6,一切恢复为“正常”,根据文档,这是时区更改在VM范围内。

0078 Java与MySQL时间戳传递/存储/协调问题--userLegacyDatetimeCode--userTimezone--serverTimezone

0078 Java与MySQL时间戳传递/存储/协调问题--userLegacyDatetimeCode--userTimezone--serverTimezone

00. 基本问题

0.0 版本: 驱动5.1.47和8.0.17 0.1 MySQL驱动5.1有userLegacyDatetimeCode和userTimezone两个参数, 8.0没有 0.2 Java与MySQL间传递时间戳的时候, 传递的是年月日时分秒, 没有时区 0.3 MySQL传递回来的是: MySQL读取到底层存储的时间戳, 按照当前连接(MySQL侧)的时区转为年月日时分秒
0.4 但是, 两个系统时区可能会不同, userLegacyDatetimeCode和userTimezone就是用来协调时区的

01. MySQL驱动5.1

1.1 数据库连接在建立时, 会创建一个Calendar对象保存在连接中, 其中保存了连接创建时的时区, 即下文的"连接时区". 见ConnectionImpl#705
1.2 如果配置了serverTimezone,则会将其保存到连接中, 即下文的"配置时区". 见ConnectionImpl#1978 1.3 userLegacyDatetimeCod=true&userTimezone=false, 这是默认情况 1.3.1 此时对应Java和MySQL时区相同
1.3.2 Java接收到MySQL传递来的年月日时分秒, 加上"连接时区"创建时间戳java.sql.Timestamp, 见ResultSetImpl#5877和TimeUtil#369 1.4 userLegacyDatetimeCod=true&userTimezone=true&serverTimezone=GMT%2B6 1.4.0 userTimezone=true, 必须在userLegacyDatetimeCod=true时才有效
1.4.1 此时对应二者时区不同 1.4.2 与3.2相同, 先将年月日时分秒+"连接时区", 创建时间戳
1.4.3 再进行时区调整, 调整为"配置时区". 见ResultSetImpl#5877和TimeUtil#160 1.5 userLegacyDatetimeCod=false&serverTimezone=GMT%2B6
1.5.1 此时对应二者时区不同 1.5.2 将年月日时分秒+"配置时区"创建时间戳. 见ResultSetImpl#5874
1.5.3 这也是8.0的处理方式

02. MySQL驱动8.0

2.1 8.0没有userLegacyDatetimeCode和userTimezone两个参数 2.2 一定要配置serverTimezone为MySQL运行的时区. 连接建立时会将这个时区存储到连接中. 见NativeProtocol#2147#2158 2.3 将年月日时分秒+"配置时区"构造时间戳. 见SqlTimestampValueFactory#100. 这里的cal就是在#68根据"配置时区"创建的

03. 代码跟踪中的一些关键点

版本5.1

连接初始化的过程

  1. ConnectionImpl#1978 "配置时区"
  2. ConnectionImpl#705 将当前时区保存到了数据库连接中

读取的过程

  1. MyBatis的各个TypeHandler
  2. ByteArrayRow#63 拿到字节数组
  3. ResultSetRow#705 将字节数组转为字符串
  4. ResultSetImpl#5729 将字符串分离为年月日时分秒
  5. ResultSetImpl#5873 对应上文01.5.2
  6. ResultSetImpl#5877 对应上文01.4.2和01.4.3
  7. ResultSetImpl#5317 如果Java要返回的是String, 则会在这里将时间戳转为jvm当前时区下的年月日时分秒

版本8.0

  1. NativeProtocol#2147#2158 保存"配置时区"
  2. ByteArrayRow#89 拿到数据库返回的字节, 大致相当于 01.5.1的ByteArrayRow#63
  3. MysqlTextValueDecoder#338 解析字节数组, 拿到年月日时分秒并封装为InternalTimestamp
  4. SqlTimestampValueFactory#100 也就是上文02.3
  5. StringValueFactory#94 如果Java要返回的是String, 就直接将InternalTimestamp转为字符串, 不考虑当前系统时区了, 与5.1的第7条有区别
  6. AbstractResultSetRow#78
  7. PropertyKey jdbc url的property的key枚举类, https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html

04. The server time zone value ''???DZ?׼ʱ?'' is unrecognized or represents more than one time zone 异常是怎么回事?

在三种情况下会抛出 上文01.4/01.5/02.2情况下未配置serverTimezone是都会抛出 因为, NativeProtocol#2130或者ConnectionImpl#1960拿到数据库的system_time_zone是乱码, 也就是select @@system_time_zone 的值 所以要配置serverTimezone为数据库运行的时区

05. 问题

时间戳传递为什么不是一个数字形式的秒/毫秒呢, 而是一个没有时区的年月日时分秒呢? 还得协调时区, 多复杂呢?

asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么

asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么

嗯…我真的无法理解这一点.

在web.config我有:

<connectionStrings>
   <clear /> <!--- need this to prevent using LocalsqlServer from machine.config or somewhere becouse it is not present when when publish to hosting -->
   <add name="DefaultConnection" providerName="System.Data.sqlClient" connectionString="Data Source=.\sqlEXPRESS;Initial Catalog=aspnet-Goaly-20120615111028;Integrated Security=sspI" />  
</connectionStrings>

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <!-- I think this line is telling asp.net that I want the membership working agains defaultconnection,and not LocalsqlServer connection????? -->
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider,System.Web.Providers,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minrequiredPasswordLength="6" minrequiredNonalphanumericCharacters="0" passwordAttemptwindow="10" applicationName="/" />
  </providers>
</membership>

但后来却在抱怨:

The connection name 'LocalsqlServer' was not found in the applications configuration or the connection string is empty.

当我在设置选项卡中使用VS2012 RC的发布时,我得到一个ModelContext和一个DefaultConnection,那么这应该如何工作呢?

我想要的只是在与modelcontext创建的表相同的数据库中获取成员资格表.

这应该是如此,但我必须过分复杂一些.

谢谢你的帮助.

问候

larsi

解决方法

在 forumsasp后面的帖子中提到了它
添加< / clear>在membership元素和rolemangaer元素(如果存在于web.config中)中的连接字符串之前的标记将解决该问题.

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
   <clear/> <!-- solves the issue -->    
   <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minrequiredPasswordLength="6" minrequiredNonalphanumericCharacters="0" passwordAttemptwindow="10" applicationName="/" />
  </providers>
</membership>

您也可以使用sqlMetal.exe将成员资格表添加到现有数据库.

asp.net – 更改MVC帐户数据库中的DefaultConnection

asp.net – 更改MVC帐户数据库中的DefaultConnection

我是Asp.Net MVC的新手.我的问题是如何更改web.config文件中的DefaultConnection以使用我的实体框架连接字符串.我的目标是整个应用程序中的一个数据库

我首先使用Asp.Net MVC 5和实体框架数据库.我在这里找到的其他帖子没有正确指出我的问题.

告诉我是否需要提供更多信息.谢谢.

解决方法

在IdentityModels中,您应该更改connectionString名称:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

将DefaultConnection更改为testEntities.

C#中的TimeZone?

C#中的TimeZone?

如何在下拉框中填充时区?

解决方法

Winforms示例:
myComboBox.displayMember = "displayName";
myComboBox.DataSource = TimeZoneInfo.GetSystemTimeZones();

我们今天的关于JDK6中的TimeZone.setDefault更改jdk设置时区的分享就到这里,谢谢您的阅读,如果想了解更多关于0078 Java与MySQL时间戳传递/存储/协调问题--userLegacyDatetimeCode--userTimezone--serverTimezone、asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么、asp.net – 更改MVC帐户数据库中的DefaultConnection、C#中的TimeZone?的相关信息,可以在本站进行搜索。

本文标签: