SELECT absentdt,period FROM stu_attendancemaster
WHERE classid=70 AND absentdt BETWEEN '2013-06-01' AND '2013-06-19'
我如何通过在函数中传递from date
和在 java 程序中使用此查询。to date
试试这个代码
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/databasename","root","");
PreparedStatement stmt=con.prepareStatement("select absentdt, period from stu_attendancemaster where classid=70 AND absentdt BETWEEN '2013-06-01' AND '2013-06-19'");
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
//get data here
}
这里是
Method body
public void callDatabase(String date1, String date2){
PreparedStatement stmt=con.prepareStatement("select absentdt, period from stu_attendancemaster where classid=70 AND absentdt BETWEEN '"+date1+"' AND '"+date2+"' ");
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
//get data here
}
}
Method call
String d1,d2; //initialize
callDatabase(d1,d2);