java 用PreparedStatement来setDate,用问号的形式给日期问号赋值

阅读更多
给下边这个语句的问号赋值:

String sql="SELECT * FROM jizhang.bookuse_book WHERE datecreated between ? and ? group by DATECREATED  ";


String startYear = "";
String stopYear = "";
String str1 = "2005-01-01";
String str2 = "2005-01-31";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
Date date1 = new Date();
Date date2 = new Date();
try {
	date1 = sdf.parse(str1);
	date2 = sdf.parse(str2);
				
	startYear = sdf.format(date1);
	stopYear = sdf.format(date2);
					
} catch (ParseException e1) {
	// TODO Auto-generated catch block
	e1.printStackTrace();
}
pstmt.setDate(1, new java.sql.Date(date1.getTime()));
pstmt.setDate(2, new java.sql.Date(date2.getTime()));


黑色头发:http://heisetoufa.iteye.com/

你可能感兴趣的:(Java,SQL)