我得到了相同的总数(这是不正确的)" Count"在下面的代码中。如果我使用" Statement",则总数是正确的。控制台上显示的错误结果是......
运行:
Connection Successful
Members 500
Payment 500
BUILD SUCCESSFUL (total time: 0 seconds)
package preparedstatement2;
import java.sql.*;
public class Main {
public static void main(String[] args) {
Connection conn = SqliteConn.connectDB();
try {
PreparedStatement pst = conn.prepareStatement("Select Count (?) From members");
pst.setString(1, "mem_id");
ResultSet rs = pst.executeQuery();
while (rs.next()) {
int mem_id = rs.getInt(1);
System.out.println("Members " + mem_id);
}
pst.setString(1, "payment");
rs = pst.executeQuery();
while (rs.next()) {
int payment = rs.getInt(1);
System.out.println("Payment " + payment);
}
} catch (SQLException ex) {
ex.getMessage();
}
}
}
编辑: 预期的输出应该是:
Connection Successful
Members 500
Payment 400
BUILD SUCCESSFUL (total time: 0 seconds)