java读取表格里的日期读取到44235?

读取excel表格里的日期内容2月8日时读到的是44235

在这里插入图片描述
右键查看单元格格式发现
在这里插入图片描述
点击文本查看:
在这里插入图片描述
44235对应的是从1990年到当前日期一共有多少天。

解决方法一:通过代码转换

   public static String dayToDate(int day){

        Calendar calendar = new GregorianCalendar(1900,0,-1);
        Date d = calendar.getTime();

        Date date= DateUtils.addDays(d,day);

        return formatNormalDateString(date);
    }

解决方法二:处理excel表格
设置单元格格式改为日期,读到的数据就为:2021-02-08

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Java读取到的MySQL表格插入到另一个MySQL表格中,可以使用JDBC API和MySQL Connector/J驱动程序。以下是一个基本的示例代码,可以读取MySQL数据库中的表格并将其插入到另一个MySQL表格中: ```java import java.sql.*; public class InsertMySQLTable { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // Load the MySQL Connector/J driver Class.forName("com.mysql.jdbc.Driver"); // Connect to the database conn = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase", "username", "password"); // Create a statement stmt = conn.createStatement(); // Execute a query to select data from the source table rs = stmt.executeQuery("SELECT * FROM sourcetable"); // Insert the data into the destination table PreparedStatement ps = conn.prepareStatement("INSERT INTO destinationtable (id, name, age) VALUES (?, ?, ?)"); while (rs.next()) { ps.setInt(1, rs.getInt("id")); ps.setString(2, rs.getString("name")); ps.setInt(3, rs.getInt("age")); ps.executeUpdate(); } ps.close(); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { // Clean up resources try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { e.printStackTrace(); } } } } ``` 请注意,此示例假定您已经安装了MySQL数据库,并且已经创建了一个名为"mydatabase"的数据库、一个名为"sourcetable"的源表格和一个名为"destinationtable"的目标表格。同时,您需要将"username"和"password"替换为您的MySQL用户名和密码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值