您的位置:首页 > 其它

JDBC的增删改查,对Date类型的插入和查询问题!

2014-12-25 11:38 239 查看
在数据库中,我们的一个用户表中有姓名,生日等字段,生日为Date格式,其中生日在第4个字段,现在我们要对生日进行插入和查询操作:

插入的时候

pstmt.setDate(4, new java.sql.Date(customer.getBirthday().getTime()));

查询的时候

customer.setBirthday(rs.getDate(4));

.日期格式转换:String-->Date

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

customer.setBirthday(dateFormat.parse("1992-10-05"));

进行文件输出可能会遇到乱码:

解决:OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("mysql_query.txt"), "UTF-8");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: