-6
SELECT absentdt,period FROM stu_attendancemaster 
WHERE classid=70 AND absentdt BETWEEN '2013-06-01' AND '2013-06-19'

我如何通过在函数中传递from date和在 java 程序中使用此查询。to date

4

2 回答 2

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
        }
于 2013-06-18T07:13:52.083 回答
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);
于 2013-06-18T08:54:09.357 回答