在数据库中,我们的一个用户表中有姓名,生日等字段,生日为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");