SELECT absentdt,period FROM stu_attendancemaster
WHERE classid=70 AND absentdt BETWEEN '2013-06-01' AND '2013-06-19'
如何通过在函数中传递from date
和to date
来在java程序中使用此查询。
答案 0 :(得分:0)
试试此代码
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
}
答案 1 :(得分:0)
在这里
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);