ssh整合错误 0 nanoseconds spent acquiring 0 JDBC connections;

SSH整合中解决JDBC连接获取错误问题
这篇博客主要讲述了在SSH整合过程中遇到的问题——0 nanoseconds spent acquiring 0 JDBC connections。通过调整web.xml文件中openSessionInViewFilter的配置,将url-pattern从'/*'更改为'*.action',成功解决了该错误,确保了JDBC连接的正常获取。
十一月 22, 2016 3:43:04 下午 org.hibernate.engine.internal.StatisticalLoggingSessionEventListener end
INFO: Session Metrics {
    0 nanoseconds spent acquiring 0 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    0 nanoseconds spent preparing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)

}

### 三级标题:Java 中将时间戳转换回 Timestamp 类型时去除 `.0` 的方法 在 Java 中,`java.sql.Timestamp` 类型的字符串表示默认包含纳秒(nanoseconds)部分,即使纳秒值为 0,也会显示为 `.0`。此行为是由于 `Timestamp` 的 `toString()` 方法会输出完整的 `yyyy-MM-dd HH:mm:ss.nnnnnnnnn` 格式,其中 `.nnnnnnnnn` 表示纳秒部分[^3]。 当时间戳被转换回 `Timestamp` 类型时,如果希望去除 `.0`,可以采用字符串处理方式。例如,使用 `substring()` 方法截取小数点前的部分,从而去除 `.0`: ```java Timestamp timestamp = new Timestamp(System.currentTimeMillis()); String timeStr = timestamp.toString().substring(0, timestamp.toString().indexOf(".")); System.out.println(timeStr); ``` 该方法通过字符串操作,直接移除小数点及之后的内容,输出格式为 `yyyy-MM-dd HH:mm:ss`,从而避免 `.0` 的出现[^3]。 另一种更灵活的方式是使用 `java.time` 包中的 `LocalDateTime` 或 `Instant`,并结合 `DateTimeFormatter` 来定义不包含纳秒部分的格式。例如: ```java import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedTime = now.format(formatter); System.out.println(formattedTime); ``` 这种方式可以避免 `.0` 的显示,并提供更可控的时间格式化能力[^2]。 此外,如果需要将 `LocalDateTime` 转换为 `Timestamp`,也可以通过以下方式实现: ```java Timestamp timestamp = Timestamp.valueOf(now); ``` 此方法保留了 `Timestamp` 的功能,同时避免了格式输出中 `.0` 的问题。 ### 三级标题:总结 通过字符串截取或使用 `java.time` 包中的类,可以有效去除 `Timestamp` 输出中的 `.0`,从而获得更简洁的时间格式。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值