MySQL的datetime数据类型如何在Java中添加

简单,就转换为String就欧克了

@Test
	public void test1() throws Exception {
		Connection conn = DBUtil.getConnection();
		String sql = " insert into pp values(?,?,?)";
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setInt(1, 8); 
		pst.setObject(2, "小梨花");
		String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		pst.setString(3, dateStr);
		int res = pst.executeUpdate();
		System.out.println(res);
	}

 

你可能感兴趣的:(数据库,java修炼笔记)